From: Raf Coremans Date: 2007-06-17T23:03:24+09:00 Subject: Re: [QUIZ] Verbal Arithmetic (#128) ------=_Part_80050_4473820.1182089005690 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline Hi, Here's my solution: http://pastie.caboo.se/71188 It's of the dumb-brute-force-slow-as-hell variety: $ time ./rq128_verbalarithmetic_rafc.rb 'send + more = money' {"m"=>1, "y"=>2, "n"=>6, "o"=>0, "d"=>7, "e"=>5, "r"=>8, "s"=>9} real 2m51.197s user 2m39.722s sys 0m11.397s $ time ./rq128_verbalarithmetic_rafc.rb 'forty + ten + ten = sixty' {"x"=>4, "n"=>0, "y"=>6, "o"=>9, "e"=>5, "f"=>2, "r"=>7, "s"=>3, "i"=>1, "t"=>8} real 7m28.151s user 6m55.114s sys 0m32.938s But on the other hand, it can handle any operator as well as bases other than 10. Did you know for instance that in base 9, ruby is worth up to 4 perls with some extra fun thrown in? $ ./rq128_verbalarithmetic_rafc.rb 'n * perl + fun = ruby' 9 {"l"=>8, "b"=>7, "y"=>0, "n"=>1, "e"=>5, "p"=>3, "f"=>6, "r"=>4, "u"=>2} {"l"=>8, "b"=>7, "y"=>0, "n"=>1, "e"=>6, "p"=>3, "f"=>5, "r"=>4, "u"=>2} {"l"=>1, "b"=>7, "y"=>4, "n"=>2, "e"=>6, "p"=>3, "f"=>5, "r"=>8, "u"=>0} {"l"=>2, "b"=>5, "y"=>0, "n"=>3, "e"=>7, "p"=>1, "f"=>8, "r"=>6, "u"=>4} {"l"=>4, "b"=>5, "y"=>6, "n"=>3, "e"=>0, "p"=>2, "f"=>8, "r"=>7, "u"=>1} {"l"=>4, "b"=>0, "y"=>6, "n"=>3, "e"=>1, "p"=>2, "f"=>8, "r"=>7, "u"=>5} {"l"=>4, "b"=>7, "y"=>6, "n"=>3, "e"=>5, "p"=>2, "f"=>1, "r"=>8, "u"=>0} {"l"=>2, "b"=>6, "y"=>3, "n"=>4, "e"=>7, "p"=>1, "f"=>5, "r"=>8, "u"=>0} Regards, Raf ------=_Part_80050_4473820.1182089005690--