From: gotoken@... (GOTO Kentaro) Date: 2000-12-30T04:30:16+09:00 Subject: [ruby-talk:8292] Re: speedup of anagram finder In message "[ruby-talk:8287] Re: speedup of anagram finder" on 00/12/30, "SHULTZ,BARRY (HP-Israel,ex1)" writes: >The idea is this: use the math theorem that upto order of the prime factors, >'every positive integer can be written uniquely as a product of primes'. To >create an integer key for each word, I first setup a hash which maps ascii >codes for a-z and A-Z to the first 26 primes. Then as I each_byte the word, >the key is built of the product of the >primes associated with each letter in the word. Neat! It is a kind of Goedel number. I've never seen any practical application of this numbering scheme. >bm do |x| > GC.start > x.report("primes"){barry(wordlist)} > GC.start > x.report("joe"){joe(wordlist) } > GC.start > x.report("devel"){devel(wordlist) } >end > > user system total real >primes 1.923000 0.000000 1.923000 ( 1.923000) >joe 2.533000 0.010000 2.543000 ( 2.543000) >devel 2.404000 0.010000 2.414000 ( 2.413000) You can justify output lines by "bm(10) do |x| ...". -- Gotoken