Please Forward: Ruby Quiz Submission

From: lagroue@free.fr
Date: June 16, 2007 11:15:34 AM CDT
To: submission@rubyquiz.com
Subject: Please Forward: Ruby Quiz Submission

Hello, I've just played with the Verbal Arithmetic game.

You'll find my solution in attachment. It is able to solve many problems, but slowly, since it relies on brute force.

The idea is to translate the input expression into a ruby expression, and to evaluate it with every digits permutations until one fits.

Words and '=' character only are modified : 'a + b = cd' is translated to the 'a + b == 10*(c)+d'. Then the program evaluates it with each digit permutation :
eval 'a=1;b=2;c=3;d=4;a + b == 10*(c)+d' => false
...
eval 'a=2;b=8;c=1;d=0;a + b == 10*(c)+d' => true

Thanks for the game !
Gwendal

Sample outputs :

$ ./verbal_arithmetics.rb 'forty+ten+ten=sixty'
f: 2
t: 8
s: 3
o: 9
r: 7
y: 6
e: 5
n: 0
i: 1
x: 4
29786+850+850=31486

$ ./verbal_arithmetics.rb 'oz**z=odd'
o: 1
z: 2
d: 4
12**2=144

verbal_arithmetics.rb (2.49 KB)

ยทยทยท

Begin forwarded message: