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

Neanderthal Boggle

by gaspodethewonderdog (Monk)
on Feb 23, 2001 at 21:48 UTC ( [id://60511]=CUFP: print w/replies, xml ) Need Help??

Alright... you guys are using big words like renooberate and such. So here is something I've squished together. I tried to make the fy shuffle a one liner, but I couldn't quite rap my brain around it.

Really the only reason I'm even doing this is because my friend wanted to make a boggle program in c and I figured I'd show him up and do everything he's implemented in under 500 lines of code if I could hehe.

If any of you have any suggestions let me know. I didn't want to post the part that contains the word list and matching because it doesn't work yet and the word list is contained in the perl script. No sense in posting a 200k or so program when only 500 characters of it works so far hehe.

For those of you who like boggle here it is. Given enough time this may actually turn into something a little more interesting with an interface and such.

@dice = qw(foxrib moqabj furilw setupl camped acitao slcrae romash nodesw hefiye onudtk tevign anedvz pinesh abilyt gkyleu); $board = join "", &make_board(fy_shuffle(@dice)); $board =~ s/([^\n]{4})/$1\n/g; print $board; sub make_board { my @board, $i; $board[$i++] = substr $_, int rand length, 1 foreach @_; return @board; } # make_board sub fy_shuffle { for (my $i = @array; -- $i;) { my $r = int rand (1 + $i); @_ [$i, $r] = @_ [$r, $i] unless $r == $i; } return @_; } # fy_shuffle

UPDATE:

Apparently I wasn't being as clever as I though (as Chipmunk pointed out) so I put the perl code back to what I had originally done for the fy_shuffle.

Replies are listed 'Best First'.
Re: Neanderthal Boggle
by japhy (Canon) on Feb 23, 2001 at 23:35 UTC
Re: Neanderthal Boggle
by chipmunk (Parson) on Feb 23, 2001 at 22:16 UTC
    Your fy_shuffle routine merely swaps the last Boggle cube with any one of the cubes (possibly itself). Don't you want to actually shuffle the entire array?

    The code in the FAQ uses a C-style for loop to iterate through the entire array. Your code uses a foreach loop with a single element list and only makes one swap in the array.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: CUFP [id://60511]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2024-04-19 07:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found