Perl-Sensitive Sunglasses PerlMonks

### RE: RE: Cryptogram Generator

by Elihu (Novice)
 on Feb 08, 2000 at 07:39 UTC ( #3030=note: print w/replies, xml ) Need Help??

in reply to RE: Cryptogram Generator

Wow. Thanks for the new ideas. I've been playing with the different algorithms a bit. I've seen somewhere how you do benchmarking, I'll try my own just to see for myself how it's done and if I get comparable numbers.

I was pretty sure there was a better way to do that. :)

Replies are listed 'Best First'.
Re^3: Cryptogram Generator
by duggles (Acolyte) on Dec 11, 2007 at 00:20 UTC

I've been working on a cryptogram solver and discovered this post and found the code useful - I snagged the code for the fisher_yates_shuffle to grab one of my solved cryptograms to recreate one to work on solving and I found that in some instances one or two of the letters in \$substit remained the same as it was originally. The line that checks for \$i == \$j does a next BUT \$i keeps on counting down and effectively leaves the unchanged letter alone. I fixed it by incrementing \$i before doing the next.

I realize in some cases the shuffle results are okay if this happens, but in a cryptogram, it won't fly... ;-) Just thought I'd throw this info back out there just in case you or anyone else may have a need for the fix.

Here's the modified sub:

## Taken from perlfaq4 (thanks btrott) sub fisher_yates_shuffle { my \$array = shift; for (my \$i = @\$array; --\$i; ) { my \$j = int rand (\$i+1); # next if \$i == \$j; # original if (\$i == \$j) { # this means the letter will be the same as it wa +s before \$i++; # put \$i back where it was and get another one next; } @\$array[\$i, \$j] = @\$array[\$j, \$i]; } return join '', @\$array; }

thanks for the original post! I'm learning a little here and there about using perl to solve cryptos... it's gonna take a while, but it's fun!!!

Life is short, but it's wide -- Chuck Pyle

Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://3030]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (3)
As of 2023-12-10 17:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
What's your preferred 'use VERSION' for new CPAN modules in 2023?

Results (40 votes). Check out past polls.

Notices?