I have attempted a solution to a beginners programming question which produces what I think is unexpected output. I need a way to validate it and was hoping to do that mathematically.
Problem description: Take a stack of coins all heads up. Upturn/flip the topmost coin and then proceed: take the top 2 coins and upturn as a single stack (tail, head becomes when upturned and placed back on the stack tail, head (the two coins are flipped as if glued together)). Now in the same way flip the top 3 coins and place back on the stack (you get: tail, tail, head (and if there were 4 coins that would be tail, tail, tail, head). When you upturn the whole stack begin again with the first coin. Continue until you return to a stack with all heads up.
Beginning with 2 coins and increasing the stack by 1 each time the output is:- 3, 9, 11, 24, 35, 28, 31, 80, 60, 121... not quite what I expected.
Any pointers on how best to model this?