Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Pentominos Solver

by stefp (Vicar)
on Sep 09, 2002 at 15:27 UTC ( #196303=note: print w/replies, xml ) Need Help??


in reply to Pentominos Solver

Square polyominos were obfuscated a long time ago using regexps. The program won as most creative of the OPC3 : the sources. If you remove the printing code that shows the progression of the search, it is relatively fast too. The trick used is to fold the board to make the problem unidimensional. I used it as a obfuscation trick to use regexp but it can be used as well as a performance boost.

BTW: there are 12 pentominoes, not eleven. Finding all of them is already quite a challenge.

You should check a Knuth paper that talks about dancing links to solve polyominoes problems and the N-Queens problem. The best book about about polyominos was written by Samuel Golomb and aptly titled polyominoes.

-- stefp -- check out TeXmacs wiki

Replies are listed 'Best First'.
Re: Re: Pentominos Solver
by Lexicon (Chaplain) on Sep 13, 2002 at 17:15 UTC
    The board is already kinda unidirectional, albeit in a hacked way. I figure the problem is already either optimally solved or runnable a couple orders of magnatude faster than my code, but researching it would take longer than writing my code, and it just wasn't that important of a project (although I am a math major, and would easily be distracted into researching that as it's own project :). Anyway, here are the three heuristics I used:
    # If piece is efficiently placed, try the next pentomino # (tend to cluster them towards origin) if (!exceeds_hole_count($index)) { solve ($index+1); }
    There are 9 holes in pentominos (I assume that's the mythical 12'th pentomino that you refer to). Clearly we better leave holes sparingly. The exact forumula relates the indexth of the pentomino to the indexth diagonal, namely that there are less than or equal to index holes up to and including the indexth diag.
    ($x, $y) = next_position_accross ( $x, $y ); # if the pentomino has run off the board, backup # and try again. (n_p_a returns (-1,-1) in this case if ($x < 0) { return } $SOLVE_COUNT++; # Start the piece well out onto the board if (($x+$y) < $index) { next };
    A pentomino need never be in a diagonal less than it's index. Pentomino 1 starts in diagonal 2, for instance.
    # Optimization by which piece never starts too far out on board. if (($x+$y) > (2*$index)) { print 'b'; next }; if ($y > $index) { print 'y'; return }; last;
    And we keep them close to home in two ways. First, they need to stay within a radius of twice their index, and second they need never exceed the indexth row. This somewhat prevents reflection across the x-y plane. And now that I've thought about it some more, I have a glimmering of a far more elegant way to capture all that. But that's allright, I have other projects to work on. Back to your post, Regexps would have been super elegant. I'm off to check it out presently. Thanks!

      A math major should know how to search the litterature. especially when the references are spelled out.
      12 pentominoes and a solved 3x20. Straight out from my obfuscation.
      xxxxx x xxx x xx x xx XX XXX x xxx x x xxxx xx xx x xxx x x x xxx x xx xxx xxxx x x x xxx _________________________________________________________ | __| |____________| |__ |___ ___| |________ | | | |__ ___| | _____| |__ | | ______| __|__| | |_____|__|_______|__|_________|__|__|__|________|________|

      -- stefp -- check out TeXmacs wiki

        Sometimes it's just more fun to solve things yourself. It's not rocket science or network security.

        I mean, hell, do ya think I wrote the Poker Probability Processor because I thought that was an effecient way to solve things? Ha! :)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://196303]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (4)
As of 2021-03-01 17:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favorite kind of desktop background is:











    Results (15 votes). Check out past polls.

    Notices?