Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Looking for pointers or optimizations.

by hbm (Hermit)
on Aug 21, 2012 at 20:26 UTC ( #988849=note: print w/ replies, xml ) Need Help??


in reply to Looking for pointers or optimizations.

Looking at your 3:11 PM version, I'd make a few more changes:

  1. You split(//,$word) twice, perhaps every time through the while loop. Move them up, prior to looping.
  2. You have @words, $words, $word, and %word. Below, I ditch the temporary $words, and introduce @chars and %chars.
... #my $words = @words; # just use (scalar @words) chomp(my $word = lc($words[int(rand(scalar @words))])); my @chars = split//,$word; my %chars = map { $_ => 1 } @chars; ... while ($turns > 0) { ... foreach my $char (@chars) { # split not needed ... else { #my %word = map{$_=>1}split(//,$word); # not needed if (exists($chars{$guess})) { # changed %word to %chars ...

Minor update - tweaked my 'foreach' comment

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (2)
As of 2016-07-30 02:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What is your favorite alternate name for a (specific) keyboard key?


















    Results (264 votes). Check out past polls.