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

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?

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2016-10-25 00:30 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (313 votes). Check out past polls.