Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

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

Comment on Re: Looking for pointers or optimizations.
Select or Download Code

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 meditating upon the Monastery: (5)
As of 2016-05-29 09:37 GMT
Find Nodes?
    Voting Booth?