Org-mode solution to this riddle.
More to learn about org-mode than to solve the riddle…
- The product of the 3 numbers is 36.
- The sum is the hallway number, which Zara knows.
- The largest number is unique.
- Zara needed the third clue.
Work out all the factors that produce 36:
product = 36
factors = []
(1..product).each {|x|
(x..product).each {|y|
(y..product).each {|z|
factors << [x, y, z] if x * y * z == product
}
}
}
factors
1 | 1 | 36 |
1 | 2 | 18 |
1 | 3 | 12 |
1 | 4 | 9 |
1 | 6 | 6 |
2 | 2 | 9 |
2 | 3 | 6 |
3 | 3 | 4 |
There are only 8 possible results, and these are the sums:
sums = factors.map { |f|
f + ["="] << f.reduce(:+)
}
1 | 1 | 36 | = | 38 |
1 | 2 | 18 | = | 21 |
1 | 3 | 12 | = | 16 |
1 | 4 | 9 | = | 14 |
1 | 6 | 6 | = | 13 |
2 | 2 | 9 | = | 13 |
2 | 3 | 6 | = | 11 |
3 | 3 | 4 | = | 10 |
Since she needed the last clue, and only 1*6*6 and 2*2*9 produce the same result, she must have gone through hallway 13 with the code 229.