My first post. I've been using Perl for a couple months and thought maybe this was irrelevant enough to post (sorry if it's too silly).
#!/usr/bin/perl -w + # Attempts to randomly ("randomly") generate the phrase # 'tobeornottobe'. Odds are 1 in ~2.481152873E18 (?). # And it's pretty slow. Wouldn't know how to fix that. # Good luck! # rcon + $count = 0; @a = (0 .. 25); @b = (a .. z); $alnum{$_} = shift(@b) foreach (@a); + sub random_int { ($lower,$upper)=(@_); return $lower + int rand(1 + $upper - $lower); } + while (1) { $s=""; @s=(); foreach $c (0 .. 12) { $s[$c] = random_int(0,25); #print "$alnum{$s[$c]}"; } #print "\n"; $s .= $_ foreach (@s); print "$s\n"; print "count: ",++$count,"\n"; die "Who's a good monkey?\n" if ($s eq "1914141417131419191414 +"); }
If you feel like having a zen moment you can uncomment the two print statements and watch their "progress". Ok, so you won't be killing SETI any time soon :P.

Replies are listed 'Best First'.
Re: Lone Monkey
by rcon (Novice) on Sep 11, 2003 at 22:14 UTC
    I made it about 120 times faster (really, I'm not sure how), but it is probably more suitable for the obfuscated code section now :P. Maybe you guys need an obfuscated poetry section? J/k!
    #!/usr/bin/perl -w $c=0;@a=(0..25);@b=(a..z);$a{$_}=shift(@b)foreach(@a);sub r{($l,$h)=( @_);return$l+int rand(1+$h-$l);}while(1){$s="";@s=();foreach(0..12){$s [$_]=r(0,25);print$a{$s[$_]};}$s.=$_ foreach(@s);++$c;print" $c\n";die "Who's a good monkey?\n"if($s eq"1914141417131419191414");}
Re: Lone Monkey
by mojotoad (Monsignor) on Sep 11, 2003 at 20:42 UTC
    Perhaps you could combine it with Parallel::ForkManager and call it the "Lone Monks" ala the "Lone Gunmen".

    :) ++

    Matt