Four fours
-
Did that route in a hired car in 2003. My VP of Engineering (a Sri Lankan Tamil) wanted to visit Chamundi's temple, so we made a day trip of it and also visited the Mysore Palace. Both impressive.
Robust Services Core | Software Techniques for Lemmings | Articles
The fox knows many things, but the hedgehog knows one big thing.Kind of unusual to hear a Canadian has done that trip, and that too by road! :-D I've never done it by road but I've taken the train, just once.
Cheers, Vikram.
-
imho, there is nothing of educational value in this puzzle. By the way, i've been on that train (1976); scenery's too nice to miss.
«The mind is not a vessel to be filled but a fire to be kindled» Plutarch
More of recreational value, something like a mathematical excursion.
-
Kind of unusual to hear a Canadian has done that trip, and that too by road! :-D I've never done it by road but I've taken the train, just once.
Cheers, Vikram.
-
I teach high school maths to a child, and yesterday, there was some spare time as it was raining outside, and he could not head back home. So, I opened my old book of math puzzles and gave him some puzzles. One puzzle is quite interesting, and is said to have occupied an acquaintance over a two-and-a-half hour train journey from Mysore to Bangalore, two cities in Southern part of India separated by about 150 km. The puzzle goes like this: Four Fours Express any number between 1 and 100 in terms of four 4s, and mathematical symbols, + - x / . .4-dot ! sqrt, etc. For example, 1 = (4 + 4)/(4 + 4) 4 = 4 / sqrt(4) + 4 / sqrt(4) 12 = (4!/4) + (4!/4) 36 = (4!/4) x (4!/4) 45 = 44 + 4/4 100 = (4/.4) x (4/.4) Can you attempt to fill in the other numbers from 1 to 100. Some numbers have non-unique solutions. One challenge here is to find HTML symbols to express the numbers. For example, .444444... is expressed as .4-dot (with the dot on top) - so this fraction 4/9 is expressed as .4-dot, with only one 4 being used. Also, expressing square root needs a unicode symbol in HTML.
-
Last one - cannot use the number 0 in the expression.
-
Last one - cannot use the number 0 in the expression.
-
I teach high school maths to a child, and yesterday, there was some spare time as it was raining outside, and he could not head back home. So, I opened my old book of math puzzles and gave him some puzzles. One puzzle is quite interesting, and is said to have occupied an acquaintance over a two-and-a-half hour train journey from Mysore to Bangalore, two cities in Southern part of India separated by about 150 km. The puzzle goes like this: Four Fours Express any number between 1 and 100 in terms of four 4s, and mathematical symbols, + - x / . .4-dot ! sqrt, etc. For example, 1 = (4 + 4)/(4 + 4) 4 = 4 / sqrt(4) + 4 / sqrt(4) 12 = (4!/4) + (4!/4) 36 = (4!/4) x (4!/4) 45 = 44 + 4/4 100 = (4/.4) x (4/.4) Can you attempt to fill in the other numbers from 1 to 100. Some numbers have non-unique solutions. One challenge here is to find HTML symbols to express the numbers. For example, .444444... is expressed as .4-dot (with the dot on top) - so this fraction 4/9 is expressed as .4-dot, with only one 4 being used. Also, expressing square root needs a unicode symbol in HTML.
Since this is "codeproject" my train trip was short. Took about 15 minutes to get the 1st order solution in C. Yes...I know it's simplistic....but a good exercise nonetheless. Obviously could be improved for all the special cases....could obviously compute squares, square roots, factorials, etc and start from the largest of those to reduce the value. I'll leave that exercise for others. In this code just change the modulus value to whatever you want and you'll get all the 1st order solutions. #include int modulus = 5; void do4(int n) { int mod = n % modulus; int i, j; printf("%d=", n); for (i = modulus; i <= n; i += modulus) { if (i > modulus) { printf("+"); } printf("%d", modulus); } for (j = 0; j < mod; ++j) { if (i != modulus) { printf("+"); } printf("(%d/%d)", modulus, modulus); } printf("\n"); } void main(void) { int i; for (i = 1; i <= 100; ++i) { do4(i); } }
-
Since this is "codeproject" my train trip was short. Took about 15 minutes to get the 1st order solution in C. Yes...I know it's simplistic....but a good exercise nonetheless. Obviously could be improved for all the special cases....could obviously compute squares, square roots, factorials, etc and start from the largest of those to reduce the value. I'll leave that exercise for others. In this code just change the modulus value to whatever you want and you'll get all the 1st order solutions. #include int modulus = 5; void do4(int n) { int mod = n % modulus; int i, j; printf("%d=", n); for (i = modulus; i <= n; i += modulus) { if (i > modulus) { printf("+"); } printf("%d", modulus); } for (j = 0; j < mod; ++j) { if (i != modulus) { printf("+"); } printf("(%d/%d)", modulus, modulus); } printf("\n"); } void main(void) { int i; for (i = 1; i <= 100; ++i) { do4(i); } }
Great!
-
imho, there is nothing of educational value in this puzzle. By the way, i've been on that train (1976); scenery's too nice to miss.
«The mind is not a vessel to be filled but a fire to be kindled» Plutarch
A variant using the four digits, 1 9 7 and 2, in order, was educational to me. Took a few minutes to write a BASIC program to generate and evaluate random Polish notation expressions. The program took days to generate almost all of 1..100 on a time-shared mini-computer. When one of my kids had a similar assignment in school, I wrote the program again in C for modern hardware. Ran instantaneously. That program taught me that computers can solve problems without human super-skills being needed.
-
Since this is "codeproject" my train trip was short. Took about 15 minutes to get the 1st order solution in C. Yes...I know it's simplistic....but a good exercise nonetheless. Obviously could be improved for all the special cases....could obviously compute squares, square roots, factorials, etc and start from the largest of those to reduce the value. I'll leave that exercise for others. In this code just change the modulus value to whatever you want and you'll get all the 1st order solutions. #include int modulus = 5; void do4(int n) { int mod = n % modulus; int i, j; printf("%d=", n); for (i = modulus; i <= n; i += modulus) { if (i > modulus) { printf("+"); } printf("%d", modulus); } for (j = 0; j < mod; ++j) { if (i != modulus) { printf("+"); } printf("(%d/%d)", modulus, modulus); } printf("\n"); } void main(void) { int i; for (i = 1; i <= 100; ++i) { do4(i); } }
-
It works for four fours. But this is "Code Project" and writing a routine to do just that one example is no fun.
The output, after repairing a small bug - condition in 2nd loop is i != modulus || j > 0:
1=(5/5)
2=(5/5)+(5/5)
3=(5/5)+(5/5)+(5/5)
4=(5/5)+(5/5)+(5/5)+(5/5)
5=5
6=5+(5/5)etc. None of these lines has five fives, so this does not solve the problem. Running it with modulus 4, one gets:
1=(4/4)
2=(4/4)+(4/4)
3=(4/4)+(4/4)+(4/4)
4=4
5=4+(4/4)etc Here, only the solution for 2 has four fours, all others are not solutions (two fours, six fours, one four, three fours, ...). So how does this "work for four fours"?
-
The output, after repairing a small bug - condition in 2nd loop is i != modulus || j > 0:
1=(5/5)
2=(5/5)+(5/5)
3=(5/5)+(5/5)+(5/5)
4=(5/5)+(5/5)+(5/5)+(5/5)
5=5
6=5+(5/5)etc. None of these lines has five fives, so this does not solve the problem. Running it with modulus 4, one gets:
1=(4/4)
2=(4/4)+(4/4)
3=(4/4)+(4/4)+(4/4)
4=4
5=4+(4/4)etc Here, only the solution for 2 has four fours, all others are not solutions (two fours, six fours, one four, three fours, ...). So how does this "work for four fours"?
I didn't program the entire solution...left that for others to do. One could make the necessary change to solve the X/Y problem of trying to get 5 5's or 3 5's or such an arbitrary combination. I was just demonstrating the "let's use 4's" to solve the values. That's why I said there needed to be more work to do the special cases of "only 4" or "only X" values. You eight need to increase or decrease the # of terms so is a bit more challenging.
-
I didn't program the entire solution...left that for others to do. One could make the necessary change to solve the X/Y problem of trying to get 5 5's or 3 5's or such an arbitrary combination. I was just demonstrating the "let's use 4's" to solve the values. That's why I said there needed to be more work to do the special cases of "only 4" or "only X" values. You eight need to increase or decrease the # of terms so is a bit more challenging.
Ok - fine :-) In other words, what you did does not take any useful step in any sensible direction for solving the problem :-D For this, one would need to create all possible expression trees fulfilling the stated properties (e.g., exactly four leaves with constant 4, only the given operator node types) and collecting the trees and their expression results. A suitable pruning condition could prevent creation of trees definitely not yielding results in {1...100} (although I don't see what a simple pruning condition would look like; maybe two stacked exponentations can always be excluded* or thereabouts). * Not true: 4^(4^(4-4)) is a valid solution for value 4, and (4^4)^(4-4) is a valid solution for value 1.