On Thu, Mar 29, 2001 at 01:19:19PM +0300, Ilmari Karonen wrote: > However, there are some nice ways in which ASCII characters behave in > XOR operations. In particular, XORing a letter with a space flips the > case of that letter, so ("foo" ^ " ") eq "Foo". I'm wondering if this can be done substantially faster and wether it will find anything in my /usr/dict/words. Right now it checks 10 in ~6 seconds on a p2-400 on a dict file with 45402 words. Also interesting: Converting the large array to a hash is very slow with map and fast with foreach: ===================8<=========================8<===================== #!/usr/bin/perl use integer; chop(@words = <>); print "read\n"; @words = map { lc } @words; print "lc\n"; @Words = map { uc } @words; print "uc\n"; keys %words = 45402; #%Words = map { $_ => 1 } @Words; # takes ages?! foreach (@Words) { $Words{$_} = 1 } # fast print "hash\n"; print "Go!\n"; $|=1; for($i=0; $i < @words; $i++) { $w1 = $words[$i]; $W1 = $Words[$i]; print "$w1 \r"; for($j=$i; $j < @words; $j++) { $w2 = $words[$j]; $W2 = $Words[$j]; print "\n$w1 ^ $w2" . ($w1^$w2)."\n" if exists $Words{uc($w1^$w2)}; print "\n$W1 ^ $w2" . ($W1^$w2)."\n" if exists $Words{uc($W1^$w2)}; print "\n$w1 ^ $W2" . ($w1^$W2)."\n" if exists $Words{uc($w1^$W2)}; print "\n$W1 ^ $W2" . ($W1^$W2)."\n" if exists $Words{uc($W1^$W2)}; } } ===================8<=========================8<===================== -Sven -- Be cheerful while you are alive. -- Phathotep, 24th Century B.C. ==== Want to unsubscribe from Fun With Perl? Well, if you insist... ==== Send email to <fwp-request@technofile.org> with message _body_ ==== unsubscribe