in reply to Challenge: Mystery Word Puzzle
Update: The puzzle changed; this solution has not. If a general solution is desired, then more work would need to be done here.use strict; use warnings; my $word = "aaaaa"; my @words; { push @words, $word if $word =~ tr/bumps// == 2 and $word =~ tr/seam// == 2 and $word =~ tr/domes// == 3 and $word =~ tr/shake// == 3 and $word =~ tr/pokes// == 3 and $word =~ tr/dukes// == 3; last if $word eq "zzzzz"; $word = inc_letter($word, 4); redo; } print "$_\n" for @words; sub inc_letter { my ($word, $i) = @_; if (substr($word, $i, 1) eq "z") { $word = inc_letter($word, $i-1, 1); substr($word, $i, 1) = substr($word, $i-1, 1); } else { substr($word, $i, 1)++; } $word; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Challenge: Mystery Word Puzzle
by dragonchild (Archbishop) on Jan 12, 2005 at 20:55 UTC |