But you have Perl handy so you could:

use strict; use warnings; my @puzzle = ( [3, 1, 2], [1, 1, 3], [1, 5, 2], [2, 3, -2], [2, 4, 2], [2, 6, - +2], [4, 6, -3], [4, 1, 2], [6, 1, 3], [5, 2, 2], [5, 4, -2], [4, 5, - +2], [4, 3, 2], ); while (<DATA>) { next if !/(\d+)\.\ (\w) -> (\w+)/; my ($step, $block, $move) = ($1, $2, $3); my $blockIndex = ord($block) - ord('A'); print "Before step $step $block $move:\n"; dumpPuzzle(@puzzle); my $piece = $puzzle[$blockIndex]; if ($move eq 'up') { --$piece->[0]; } elsif ($move eq 'down') { ++$piece->[0]; } elsif ($move eq 'left') { --$piece->[1]; } else { ++$piece->[1]; } } print "Final state:\n"; dumpPuzzle(@puzzle); sub dumpPuzzle { my (@puzzle) = @_; my @rows = map {'.' x 6} 1 .. 6; for my $pieceIdx (0 .. $#puzzle) { my ($y, $x, $len) = @{$puzzle[$pieceIdx]}; if ($len < 0) { $len = -$len; substr $rows[$_ - 1], $x - 1, 1, chr($pieceIdx + ord('A')) for $y .. $y + $len - 1; } else { substr $rows[$y - 1], $x - 1, $len, chr($pieceIdx + ord('A')) x $len; } } print join "\n", @rows, ''; } __END__ 1. C -> left 2. F -> up 3. G -> up 4. L -> up 5. M -> left 6. K -> up 7. I -> right 8. H -> down 9. I -> right 10. I -> right 11. K -> up 12. J -> right 13. J -> right 14. M -> left 15. D -> down 16. D -> down 17. A -> right 18. D -> down 19. M -> right 20. H -> up 21. H -> up 22. H -> up 23. M -> left 24. D -> up 25. I -> left 26. G -> down 27. F -> down 28. C -> right 29. B -> right 30. H -> up 31. A -> left 32. D -> up 33. J -> left 34. J -> left 35. J -> left 36. D -> down 37. A -> right 38. H -> down 39. B -> left 40. C -> left 41. F -> up 42. K -> down 43. A -> right 44. L -> down 45. A -> right 46. A -> right 47. A -> right

Prints (in part):

Before step 1 C left: BBB.CC ..DEEF AAD..F HHMMLG .JJKLG IIIK.G Before step 2 F up: BBBCC. ..DEEF AAD..F HHMMLG .JJKLG IIIK.G Before step 3 G up: BBBCCF ..DEEF AAD... HHMMLG .JJKLG IIIK.G . . . Before step 47 A right: BBBCCF HH.EEF ....AA MMDKLG JJDKLG ..IIIG Final state: BBBCCF HH.EEF .....AA MMDKLG JJDKLG ..IIIG

Note that I've changed the puzzle coding to use a top left corner and size/orientation array for each piece and the board size is hard wired at 8.

True laziness is hard work

In reply to Re^2: Puzzle solver (rush hour) by GrandFather
in thread Puzzle solver (rush hour) by Ratazong

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.