Skip to content

made a puzzle that creates a bunch of random files with one of the co…#9

Open
jacobmccaughrin wants to merge 15 commits intogigamonkey:mainfrom
jacobmccaughrin:main
Open

made a puzzle that creates a bunch of random files with one of the co…#9
jacobmccaughrin wants to merge 15 commits intogigamonkey:mainfrom
jacobmccaughrin:main

Conversation

@jacobmccaughrin
Copy link
Copy Markdown

…lors of the rainbow.

Copy link
Copy Markdown
Owner

@gigamonkey gigamonkey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Close but not quite right. To test this you can run first ./build/build.sh after you've added your script to STEPS. Then you can run ./progress like you were playing the game but you may want to use the ./copy-solutions.sh script to copy the existing solutions into the main directory so you don't have to solve the whole puzzle every time.

Comment thread README
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops. This shouldn't have been committed. I thought I had an entry in .gitignore to ignore it but maybe I don't. Anyway, can you git rm this file and then commit that change so it doesn't get added when I merge this PR.

Comment thread build/sortDir.sh Outdated
Comment on lines +33 to +35
echo $PUZZLE/$FOLDER is a directory with some number of files. Each file has in its name one of the colors of the rainbow: red, orange, yellow, green, blue, indigo, and violet

echo "The secret is found by joining the names of the first file found for each color in the rainbow."
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this is not quite right. These scripts need to take a secret to hide as their single argument (so it will be $1) and then hide it somehow. You could hide it by splitting it into seven pieces and then putting each piece in the first file of each color so that catting those files together would retrieve the secret. (The way the puzzle is built is your script is given the secret/clue generated by the next puzzle in the sequence so you hide it and your clue tells how to find it.) If you want to go that way you should look at the split command which can split input into chunks. But it writes them out to files which you would then have to move to the appropriate files that you generated. And then, ideally, you'd also put fake secrets into all the other files so the user can't just cat all the files.

Copy link
Copy Markdown
Owner

@gigamonkey gigamonkey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please address the comments and get this script into a runnable state.

Comment thread README
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops. This file was generated by building the puzzle and shouldn't be checked in. You can git rm it and then commit and push to get rid of it.

Comment thread build/sort-dir.sh Outdated

total_files=$(((RANDOM % 100 + 1) * 7 )) #picks a random amount of files

files_per_color=$((TOTAL_FILES / 7 )) #how many files per each color
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure why shellcheck doesn't notice this but TOTAL_FILES is not defined. I assume you meant total_files.

Comment thread build/sort-dir.sh
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file needs to be chmod +x'd to be runnable by the ./build/build.sh script. But beyond that there are syntax errors that prevent this from running. You need to fix those to get this script to an actually runnable state.

Comment thread build/sort-dir.sh Outdated
for color in "${rainbow_colors[@]}"; do #for every color
first_file_created=false
for ((i= 0; i<files_per_color; i++)); do #for every file per color
if [[ $first_file_created == false]]; then
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you need a space before the ]] for bash to understand the syntax.

Copy link
Copy Markdown
Owner

@gigamonkey gigamonkey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commented on a couple bash gotchas you ran into that are preventing your script from running to completion.

Comment thread build/sort-dir.sh Outdated
((count++))
else

rand_str=$(tr -dc 'a-z0-9' </dev/urandom | head -c 5) #generate random string
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a bit of a gotcha here. The head command shuts down it's input once it gets enough stuff. But that causes the next write by the tr command to it's output to fail which because of the set -o pipefail causes this pipeline to fail which causes this line to fail which causes your whole script to fail. One simple fix is to change this line to this:

Suggested change
rand_str=$(tr -dc 'a-z0-9' </dev/urandom | head -c 5) #generate random string
rand_str=$(tr -dc 'a-z0-9' </dev/urandom | head -c 5) || true #generate random string

The || true causes the first command's failure to be in a context where failure is okay and true always succeeds so the line as a whole will succeed.

Comment thread build/sort-dir.sh Outdated
FILENAME="${color}_${parts[$count]}.txt"
touch "$FOLDER/$FILENAME"
first_file_created=true
((count++))
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is a gotcha. For various reasons, the success or failure of arithmetic expansions is determined by their arithmetic value with anything except 0 counting as success and 0 counting as failure. In a context like this where count starts at zero ((count++)) evaluates to 0 which is considered failure which causes your script to exit due to the set -e. One simple way to fix this is to use ((count += 1)) instead since it evaluates to the new value rather than the old value. Other possibilities include ((++count)) or ((count++)) || true

…in directory. Am i doing something wrong or do i need to make some files to get the ./progress to work?
Copy link
Copy Markdown
Owner

@gigamonkey gigamonkey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your script as checked in still doesn't run because you're missing the || true on the other place you use tr and head in a pipeline.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants