[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [FWP] Love & Hate shenanigans




On Thu, 29 Mar 2001, Sven Neuhaus wrote:
> 
> I'm wondering if this can be done substantially faster and wether it 
> will find anything in my /usr/dict/words.
 [snip]
>         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)};

I'd expect it not to find anything, and you've since confirmed this.
The reason becomes apparent when one looks at the ASCII character table:

  000  ................................
  001   !"#$%&'()*+,-./0123456789:;<=>?
  010  @ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_
  011  `abcdefghijklmnopqrstuvwxyz{|}~.

On each line above there are 32 characters in ascending order.  On the
left side of each line are the three high bits common to each character
on that line.  The periods on the first line and in the lower right
corner stand for control characters.

What you can see from that chart is that all the letters have the second
highest bit set.  When you XOR two letters, the resulting character will
*not* have that bit set, and will therefore not be a letter.  So XORing
two words will never produce a word, regardless of case.

(XORing two letters _could_ produce a number, but that shouldn't make a
difference in this case.)

-- 
Ilmari Karonen - http://www.sci.fi/~iltzu/
"Certainly Pluto itself couldn't care less whether it's called a planet
 or not."                    -- Erik Max Francis in rec.arts.sf.science



==== Want to unsubscribe from Fun With Perl?  Well, if you insist...
==== Send email to <fwp-request@technofile.org> with message _body_
====   unsubscribe