Path: utzoo!mnetor!tmsoft!torsqnt!lethe!yunexus!ists!helios.physics.utoronto.ca!news-server.csri.toronto.edu!cs.utexas.edu!uunet!rbj From: rbj@uunet.UU.NET (Root Boy Jim) Newsgroups: comp.lang.perl Subject: Even Parity Table Generation Message-ID: <121817@uunet.UU.NET> Date: 9 Feb 91 03:08:56 GMT Organization: UUNET Communications Services, Falls Church, VA Lines: 32 I needed an even parity table, so I decided to generate it recursively. I thought people might be interested in my solution, and or commenting on how it might be done better. And while I'm at it, I hereby request another function: chr(), the opposite of ord(). Either that, or get rid of ord. Anyway, here it is: print time,"\n"; &mkEven(7); print time,"\n"; &prtEven; print time,"\n"; exit(0); sub mkEven # global %even (level) { local($_,$k) = @_; $_ || return $even{"\0"} = "\0"; # bottom out &mkEven(--$_); # lower half $_ = 1 << $_; # next bit for $k (keys %even) { # key loop $even{pack('c',$_^ord($k))} = # new key pack('c',128^$_^ord($even{$k})); # new value } } sub prtEven { for (sort keys(%even)) { printf("%x %x\n",ord($_),ord($even{$_})); } } -- Root Boy Jim Cottrell I got a head full of ideas They're driving me insane