Trying to program Dan Finkel Puzzles

Hey Everyone,
I am a complete novice trying to piece together how to program one of Dan Finkel's puzzles from his TED talks.
Namely:https://www.ted.com/talks/dan_finkel_can_you_solve_the_giant_cat_army_riddle?language=en

It should be simple:
3 analog inputs (buttons), simple calculations, cross check against the rules, print to LCD display, and once the puzzle is solved, send a signal (to play a sound or power a lock relay).

So I started with the buttons - I can easily get one button to add +5 to a variable on each press. I figured the next obvious step was to repeat this for the other two buttons, add some "OR" statements and nested while loops to handle the fact that they are independent, yet only one operation can be done at a time. This completely crapped out.
Any suggestions or tutorials that you can link me to would be great. Once I get this sorted, I hope that the LCD output will be more straightforward!
Thanks

Hi SAGERahn,

Could you describe the logic in more detail? (Without everyone watching the video, it will be hard for us to understand what you are trying to do.)

Also, if your buttons are “press” buttons rather than “adjustable” controls, you are describing a digital input, not an analog one.

Pat

Sure!
There are 3 press buttons. Button 1, Button 2, and Button 3.
There is a variable to carry a value which is modified by pressing any of the buttons; call it "Total".
If Button 1 is pressed, the variable value is adjusted such that: Total = Total+5
If Button 2 is pressed, the variable value is adjusted such that: Total = Total+7
If Button 3 is pressed, the variable value is adjusted such that: Total = sqrt(Total)
THe way I managed to deal with registering a single button push was to pause the loop using "while" so that a press and release only accounts for a single loop - if you do not do this, a single button press could end up adding to the Total variable # of times depending on how long you held the button down (e.g. one button depression, regardless of length, results in only one registering of an event and one operation on Total).

The running value will then be printed to an LCD.
For example, if you pressed Button 1 five times, Button 3 once, and Button 2 once, the display would read:
0 5 10 15 20 25 5 12

There are other logical operators that I can add later, once the buttons are sorted - included below for completeness:
If a number repeats, reset Total to zero and clear the display
If a number >60 is reached, reset Total to zero and clear the display
If a non-perfect square is taken (e.g. non-integer result), reset Total to zero and clear the display
If the running number sequence contains the numbers 2, 10, and 14 in that order but not necessarily adjacent, then mark the puzzle as solved.

SAGERahn:
THe way I managed to deal with registering a single button push was to pause the loop using "while" so that a press and release only accounts for a single loop - if you do not do this, a single button press could end up adding to the Total variable # of times depending on how long you held the button down (e.g. one button depression, regardless of length, results in only one registering of an event and one operation on Total).

File->Examples->Digital->Debounce
File->Examples->Digital->StateChangeDetection

SAGERahn:
If a number repeats, reset Total to zero and clear the display

You could consider keeping a 60/61 length array of booleans to store and check which numbers have been used already to prevent duplicates. Space wasteful, but easy to do.

SAGERahn:
If a non-perfect square is taken (e.g. non-integer result), reset Total to zero and clear the display

Since there are so few possibilities for numbers to square root, you could just forgo the non-integer stuff and check for each of 4, 9, 16, 25, 36, 49. If the pre-root total isn't one of those numbers then failure.

SAGERahn:
If the running number sequence contains the numbers 2, 10, and 14 in that order but not necessarily adjacent, then mark the puzzle as solved.

You'd be already checking for duplicates, now just make sure that when 10 or 14 arrive, you already have had 2. Likewise, when 14 arrives, check that you have had 10.

Cute puzzle by the way.

Thanks for these suggestions!

Unfortunately, my CEO (aka Wife) just gave me a few new priorities - which means I probably cannot get back to this for a month or two. I will make a point to get back and post the outcome!

Out of curiosity, what would someone charge to do a small project like this one?