It felt like I cheated...
September 13, 2007 11:27 AM
Subscribe
How do I solve
this puzzle mathematically, rather than programmatically?
I condensed it the problem down to the following equation:
x1 + y1 = z1
x2 - y2 = z2
x3 * y3 = z3
z1 / z2 = y3
And then a ruby
permute snippet to solve it:
[1,2,3,4,5,6,7,8,9].permute do |x|
x1 = x[0]
y1 = x[1]
z1 = x[2]
x2 = x[3]
y2 = x[4]
z2 = x[5]
x3 = x[6]
y3 = x[7]
z3 = x[8]
if (x1 + y1 == z1) &&
(x2 - y2 == z2) &&
(x3 * y3 == z3) &&
(z1 / z2 == y3)
then
puts 'x1 = '+x1.to_s
puts 'y1 = '+y1.to_s
puts 'z1 = '+z1.to_s
puts 'x2 = '+x2.to_s
puts 'y2 = '+y2.to_s
puts 'z2 = '+z2.to_s
puts 'x3 = '+x3.to_s
puts 'y3 = '+y3.to_s
puts 'z3 = '+z3.to_s
break;
end
end
I got the correct result,
x1 = 1
y1 = 7
z1 = 8
x2 = 9
y2 = 5
z2 = 4
x3 = 3
y3 = 2
z3 = 6
My question is, how can I solve this using pure math, without guessing? Or can I?
posted by anomie to education (12 comments total)
you can also work at it from ordering the variables - i.e. x1+y1=z1 indicates that z1 > x1 and y1 and so forth. then put them on a number line.
posted by noloveforned at 11:32 AM on September 13, 2007