Pathologically Eclectic Rubbish Lister | |
PerlMonks |
Re^4: Tk - Discipulus 15 puzzleby Discipulus (Canon) |
on Jun 13, 2017 at 20:21 UTC ( [id://1192731]=note: print w/replies, xml ) | Need Help?? |
> being impressed Discipulus' code actively can figure out things like the minimum number of moves remaining or even that a solution was impossible based on the random shuffle. Oh do not overstimate me, nor my code: I have no idea about the minimum number of moves nor how to solve the puzzle programatically. The possible/impossible solution is another matter and is a simple one: see the link to the mathworld site in the reference or run with the --verbose switch to see how to compute it. Infact it is calculated counting, for every tile, how many are lesser of the current one, as if they lay on a single row and adding all these number: if the result is odd the game is impossible. You can read on wikipedia: > .. offering a $1,000 prize for anyone who could provide a solution for achieving a particular combination specified by Loyd, namely reversing the 14 and 15. This was impossible, as had been shown over a decade earlier by Johnson & Story (1879), as it required a transformation from an even to an odd combination. Infact I simply do: $perm += grep {$_ < $appear[$num]} @appear[$num+1..$#appear]; and later on if ($permutation % 2){ print "Impossible game with odd permutations!" Running with --verbose shows it clearly:
Being 105 the highest value for permutations I just assign solved, easy, medium and hard difficulty level for permutations with values of 0, 1-35, 36-70 and 71-105 The real fun is running the program with --perl switch... ;=)
L*
There are no rules, there are no thumbs.. Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.
In Section
Cool Uses for Perl
|
|