Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

Re: Word Search Builder

by Fendaria (Beadle)
on Feb 21, 2005 at 23:11 UTC ( #433187=note: print w/ replies, xml ) Need Help??

in reply to Word Search Builder

Wonderful little program.

I couldn't help myself from noticing though you can combine your two loops in addWord if you randomize the order you brute force search. As long as your brute force search hits all possibilities, you can search in whatever order you want.

sub randomizeArray(@) { my @array = @_; for my $i ( 1 .. $#array ) { my $j = int rand( $i + 1 ); ( $array[$i], $array[$j] ) = ( $array[$j], $array[$i] ); } return @array; } ## end sub randomizeArray(@) sub addWord { my ( $grid, $word ) = @_; for my $dir ( randomizeArray( 0 .. 7 ) ) { for my $y ( randomizeArray( 0 .. $height - 1 ) ) { for my $x ( randomizeArray( 0 .. $width - 1 ) ) { if ( wordFits( $grid, $word, $x, $y, $dir ) ) { insertWord( $grid, $word, $x, $y, $dir ); return 1; } } } ## end for my $y ( randomizeArray... } ## end for my $dir ( randomizeArray... return 0; } ## end sub addWord

It would also be neat if you allowed for 'turns' when adding a word. ex. in a 2,2 grid allow the word 'perl' as


I think the game 'boggle' allows for word grids in this style.


Replies are listed 'Best First'.
Re^2: Word Search Builder
by aufflick (Deacon) on Feb 22, 2005 at 00:43 UTC
    You're insane! Just as nuts as my girlfriend's flatmate who loves borderless jigsaws that come with extra pieces!
Re^2: Word Search Builder
by pbeckingham (Parson) on Mar 08, 2005 at 16:03 UTC

    Thanks! You're right about the ordering. As for the Boggle thing, I don't know how I might go about that.

    pbeckingham - typist, perishable vertebrate.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (9)
As of 2016-08-27 21:10 GMT
Find Nodes?
    Voting Booth?
    The best thing I ever won in a lottery was:

    Results (389 votes). Check out past polls.