reach
A program to express each the numbers between 0 and 199 inclusive as a mathematical expression using each of 1, 2, 3, 4, 5 exactly once.
When I was a kid, a friend of mine was in REACH which is a program for
gifted and talented elementary school students. One of his activities from
this program was writing each of the numbers from 1 to 100 as a mathematical
expression using each of 1, 2, 3, 4, and 5 exactly once.
This is a program that does just that except this program does it for the
numbers from 0 to 199. 178 is the first number for which this program cannot
find a solution.
This program uses postfix notation rather than infix notation as it is easier
to form postfix mathematical expressions rather than infix ones.
For example:
- 1 2 + => 1 + 2
- 3 4 + 2 * => (3 + 4) * 2
- 3 4 2 + * => 3 * (4 + 2)
All the numbers from 0 up to 100 inclusive can be written in this way. 178
is the smallest number for which there is no known way to write it using
The output of the program is at the bottom:
From the output you can see that
- 0 == 1 5 + 4 2 + - 3 * => ((1 + 5) - (4 + 2)) * 3
- 1 == 1 5 + 2 + 4 3 + - => 1 + 5 + 2 - (4 + 3)
Notice that all these expressions use the numbers 1 through 5 exactly once.
As you can see 178 is the first number with no such expression.
0 [1 4 + 2 3 + - 5 *]
1 [1 2 + 5 + 3 4 + -]
2 [1 2 + 3 + 4 + 5 /]
3 [1 3 + 5 + 2 4 + -]
4 [1 2 + 4 + 5 + 3 /]
5 [1 2 + 3 + 4 + 5 -]
6 [1 2 + 4 + 5 - 3 *]
7 [1 2 + 3 + 5 + 4 -]
8 [2 4 + 5 + 3 - 1 *]
9 [1 2 + 4 + 5 + 3 -]
10 [1 2 + 3 + 4 - 5 *]
11 [1 3 + 4 + 5 + 2 -]
12 [1 2 + 5 + 4 - 3 *]
13 [2 3 + 4 + 5 + 1 -]
14 [2 3 + 4 + 5 + 1 *]
15 [1 2 + 3 + 4 + 5 +]
16 [1 4 + 5 + 2 3 * +]
17 [1 3 + 5 + 2 4 * +]
18 [1 3 + 5 + 4 2 - *]
19 [3 4 + 1 5 + 2 * +]
20 [1 2 + 4 + 3 - 5 *]
21 [1 3 + 4 + 2 * 5 +]
22 [3 4 + 5 + 1 - 2 *]
23 [1 4 + 5 + 2 * 3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