No such thing as a small change  
PerlMonks 
Re: Re: Solver for Sunday Times teaser 2021by Brovnik (Hermit) 
on Jun 22, 2001 at 12:59 UTC ( #90653=note: print w/ replies, xml )  Need Help?? 
Hmmm..., looking at it again, I can see that it might be a bit confusing.
If you uncomment the print line in HisTry and MyTry, you get more verbose reporting about the results of each possibility.
This is where we start the game, with both players @ 0. In later rounds, the round could start with several possibilities (e.g. Roll 7 => [14, 15]), and each is explored in turn. we try all 6 possibilities for the die in HisTry But, $new = move($start,$die) will adjust the output if it is a prime or a square before returning the value, and validHim($new) knocks out any of these that won't be valid final values. So for the first roll : Scores of 1,4 move down to the next square, and 2,3,5 move up to the next prime. Since we have to end up with His score twice mine, his end number must be even, so this only leaves 6 from the first roll. Do the same for Me, but matching possibilities are only those where his roll ends up as twice mine. And carry forward to the next round the sequence of final values for Me. In this case, I end up at the end of Roll 1 with a 3 as the only possible value that is valid under the contstraints. The last line means that it found exactly one final set of rolls that would meet the constraints, and Me end up with 15, and Him on 30. Note that several of the rolls carry forward multiple possible routes to the next round where they then get eliminated, and in Roll 5,6, we can get from 10=>12=>15 or 10=>13=>15 via 2 different routes but, since the answer is the same we don't care.
Hope that helps explain it.
In Section
Craft

