1 Attachment(s)
Here is my latest program:
|
First noticed this thread late Monday; this is great fun!
I wrote my logic in C, a bit over 300 lines w/ comments, about 11k Linux binary. I get 49 results for 2019. My matrix: Code:
and 95 for 1972! (as Sinatra would say, "When I was 21, it was a very good year") Algebraic formulae and code upon request. I will keep trying to improve on that 49 as well. What would you say to applying other operations as well? I remember back in the 1970s a similar calculator puzzle entitled '4x4' in which you were allowed to press only the '4' key exactly four times to get results from 0 to 100. Almost the same as this, but in '4x4', you could also use the square, square root, factorial, and reciprocate keys, with parentheses as needed. It took me a good while, but i was eventually able to generate all 101 values (not with a program). |
I played the 4x4 game in the 70s too. I didn't make it to 100 though.
I did it on paper, which unlike a calculator allowed me to write .4 with a bar over it. That represents a repeating digit to make .4444444444..., which is 4/9, and the square root of that is 2/3. I got some mileage out of that. Yeah, good times! |
This is my although not a program itself. Idea is to use RPN (or PRN): reverse polish notation. Notation which allows to avoid completely use of parentheses, say:
Code:
2*3 Code:
2 3 * Code:
d1 d2 op1 d3 op2 d4 op3 Code:
0 1 | 2 * 9 + Code:
Code:
1 0 | 2 * 9 - Code:
10*2-9 = 11 Code:
1 0 | 2 | 9 | - Code:
102 -9 = 93 |
Yeah, my first programmable calculator, an HP11, used RPN. Much more intuitive than parentheses, once you get used to the concept. Also, a co-worker in the 90s wrote a compiler, using RPN to evaluate algebraic expressions.
|
Quote:
Code:
4 * (4! + 1/4) - 4 Code:
4 ! 4 1/x + 4 * 4 - |
Quote:
|
Just correction, it is also necessary to take sequences of the form
Code:
d d o d d o o Code:
90 -12 Code:
9 0 | 1 2 | - |
My HP48GX has seen much use exploring potential expressions for this exercise!*
*It sees much use every day |
Side Topic and Tutorial
2 Attachment(s)
I have been investigating the perils of floating point division. To explain: Computers can add, subtract, and multiply whole numbers exactly, provided they don't exceed the number of available bits. Division is different. No matter how many bits are available, division often use every last bit, and still the result is inexact.
For example, on many calculators, 1/3 evaluates to something like 0.33333333. We all know that 3*(1/3) should be 1, but the calculator yields 0.99999999. Call it roundoff error, or truncation error. For most purposes, the difference is negligible, but in the New Year Puzzle, it is a huge problem because we need to know whether the result is or is not a whole number. When I try that calculation in python, at first it doesn't look so bad: Code:
>>> 1/3 Let's try introducing another step: Code:
>>> (1/3)*3*7 Code:
>>> (1/3)*7*3 Here is some good news: If I do those same two calculations in C, I get perfect answers regardless of the order of operations. I don't know why. There must be a small difference in the implementation. Code:
(1/3)*3*7 = 7.0000000000000000 Code:
((7/6)*6)*9 = 63.0000000000000071 Let me share two programs with you, one in python3 and the other in C, which do the same thing, except C has the option of long double. In the C program, feel free to change the long double declaration and cast to double, or even float, and see what happens. Attachment 29446 Attachment 29447 |
^ Very interesting. It shows how things can get more complicated from an apparent simple assignment ;)
|
Unless I missed the point:
Code:
#!/usr/bin/env python3 Code:
0 |
^ I don't know Python but you processed only all the possible concatenations based on [2,0,1,9] digits whose results range from 0 to 100, didn't you?
|
Yes.
Generate all integers from 0 to 100. Filter out the ones that have the same digit more than once. Filter out the ones that have digits that aren't 2, 0, 1, or 9. Print what's left. |
Interesting. I didn't know such things can be done with python's set() function. Someday I should learn how, and when, to use set().
There is more to the New Year Puzzle. It requires each digit of the year to be used once and only once, and certain arithmetic operations are allowed. Sorry if the original post didn't make that clear. |
All times are GMT -5. The time now is 03:08 AM. |