Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
This golf challenge is tricky, because the design is opposite from how one would usually approach Boggle. Not that this is a bad thing; it makes the challenge more interesting!

Usually, when playing Boggle, you start with a list of words, and search the grid for all the words in the list. (In real life, the word list is your vocabulary. In a program, it might be /usr/dict or some other word list.) In this golf challenge, you start with the grid, and then you get one word at a time that you try to find, and you can stop searching as soon as you find the word.

Here's my solution. I went for the bonus points using $n as the board size. It's 195 characters; surely a shorter solution is possible!

sub test_boggle_word { # 1 2 3 4 5 #2345678901234567890123456789012345678901234567890 my$t;for$y(@n=0..$n-1){$t|=t($y,$_,@_)for@n}sub t{ my($y,$x,$w,$n,@g,$t)=@_;if($y>=0&$y<$n&$x>=0&$x<$ n&chop$w eq splice@g,$y*$n+$x,1,0){for$Y(-1..1){$t |=t($y+$Y,$x+$_,$w,$n,@g)|!$w for-1..1}}$t}$t } # testing code: @bogglelist = qw/ R E W E M T A S K L E T N V F O /; $n = 4; $dict = [ qw/ WATER SETTER VETO WASTE WASTES / ]; print "$_\n" for find_boggle_words(); sub find_boggle_words { # $storage = prepare_boggle_search( $n, @bogglelist ); @matched = grep { test_boggle_word( $_, $n, @bogglelist ) } @$dict; return @matched; }
In my testing code, WATER, VETO and WASTE can be found in the grid. The original node doesn't specify, but in the rules of Boggle a single cube cannot be used twice in the same word. So, WASTES can't be found because the S would be used twice.

In reply to Re: (Golf) The Perl Boggles by chipmunk
in thread (Golf) The Perl Boggles by Masem

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

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (5)
As of 2021-11-27 18:32 GMT
Find Nodes?
    Voting Booth?

    No recent polls found