Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

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 all is quiet...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2018-06-22 04:47 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (121 votes). Check out past polls.