Boggle's a very simple game, in which 16 dice containing random letter sets are rattled and set into a 4x4 grid. Then players have a limited amount of time to located words in the grid by starting at any letter then moving to an adjacent cube (all 8 directions, no 'warping' on sides, however) to form out a word. For example, with the random grid:
REWE MTAS KLET NVFO
You can form the word 'WATER', but you can't form the word 'SETTER' as you can't stay on a letter to make a double letter. At the end of a specified amount of time, the players would reveal their lists and the one with the highest number of valid words wins.

Now, Boggle has been approached before on PM: chipmunk has a basic boggle word finder that locates words in a boggle grid. And gaspodethewonderdog has a node that generates a boggle board.

The golf now is to try to 'simplify' these. Your code should fit into the following blocks:

sub find_boggle_words { $storage = prepare_boggle_search( @bogglelist ); @matched = grep { test_boggle_word( $_, $storage ) } @$dict; return @matched; } sub prepare_boggle_search { # YOUR CODE HERE } sub test_boggle_word { # YOUR CODE HERE }
$dict is a list of valid dictionary words. @bogglelist is an array of the current randomly-selected boggle characters; if the above example was used, then @bogglelist would look like: qw( R E W E M T A S K L E T N V F O ).

The first function, prepare_boggle_search, can be any method to make searching for words easier. If you choose not to use it, treat this function as zero strokes towards your golf total; additionally, you can pass @bogglelist instead of $storage to test_boggle_word (eg test_boggle_word( $_, @bogglelist ). If you do use this function, you should pass back your data structure as this will be passed on to test_boggle_word.

The second function test_boggle_word should return true of the word passed can be found on the boggle board as defined by either @bogglelist or by your $storage variable.

No extra modules are allowed, and strictness need not apply. Golf will only count characters in the subroutines, not in the code provided, and the character count should be done as if the entire code was on one single line. Assume that all inputs are valid (that is, the @bogglelist will always have 16 elements, for example).

For bonus points, generalize the situation when you have a NxN boggle board. In this case, the wrapping code will look like:

sub find_boggle_words { $storage = prepare_boggle_search( $n, @bogglelist ); @matched = grep { test_boggle_word( $_, $n, $storage ) } @$dict; return @matched; }
where $n is the board size N (>1). Again, if you don't use prepare_boggle_search, you can replace $storage with @bogglelist.

Update - You may assume that no word that can be found will be longer than 12 characters, if you need to use this information.

-----------------------------------------------------
Dr. Michael K. Neylon - mneylon-pm@masemware.com || "You've left the lens cap of your mind on again, Pinky" - The Brain
"I can see my house from here!"
It's not what you know, but knowing how to find it if you don't know that's important


In reply to (Golf) The Perl Boggles by Masem

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.