Sean has a faulty calculator such that:
The only keys that do anything on his calculator, with the function they actually perform, are:
- Subtact 1 from the display.
+ Add 2 to the display.
x Cube the display value.
M+ Add the display value to the memory.
M- Subtract the display value from the memory.
MC Clear the memory (but not the display).
MR Recall the memory, replacing the display value.
The display and memory are both zero before you start.
Determine the minimum number of key presses that Sean needs to perform on his calculator to obtain the number 2004.
The sequence posted by Larry is the only one for 8 or fewer key presses, as verified by the following program:
clearvars,clc
global ops display memory seq had had2 reached fid
ops=["+","-","x","m+","m-","mc","mr"];
display=0;
memory=0;
seq=[]; had=[]; had2=[]; reached=[]
fid=fopen('c:\VB5 Projects\flooble\faulty calculator reached.txt','w');
addon();
fclose(fid);
function addon()
global ops display memory seq had had2 reached fid
for i=1:length(ops)
op=ops(i);
dont=false;
memsave=memory; dispsave=display;
switch op
case "-"
display=display-1;
case "+"
display=display+2;
case "x"
display=display^3;
case "m+"
if display==0, dont=true;
else
memory=memory+display;
end
case "m-"
if display==0, dont=true;
else
memory=memory-display;
end
case "mc"
if memory==0, dont=true;
else
memory=0;
end
case "mr"
if memory==display, dont=true;
else
display=memory;
end
end
if dont==true
continue
end
seq=[seq op];
ix1=find(had==display);
ix2=find(had2==memory);
if ~isempty(intersect(ix1,ix2)) && display~=2004
seq=seq(1:end-1);
display=dispsave;
memory=memsave;
continue
end
had=[had display];
had2=[had2 memory];
if isempty(find(reached==display))
reached=[reached display];
if display>0 && display<=9999
fprintf(fid,'%6d ',display);
fprintf(fid,'%3s',seq);
fprintf(fid,'\n');
end
end
if display==2004
disp([display seq])
else
if length(seq)<8 && display < 100000
addon()
end
end
display=dispsave;
memory=memsave;
seq=seq(1:end-1);
had=had(1:end-1);
had2=had2(1:end-1);
end
end
finds for 2004 only one:
value sequence ------------------------------
2004 + x + x + m+ m+ mr
Along the way, it found other numbers. Below are the positive numbers of four or fewer digits and one way of forming each in 8 or fewer key presses. Some are not the shortest way, but only the first one found.
1 + + + + + mr - +
2 +
3 + + + + mr - + +
4 + +
5 + + + + - m+ - -
6 + + +
7 + + + + -
8 + + + +
9 + + + + + -
10 + + + + +
11 + + + + + + -
12 + + + + + +
13 + + + + + + + -
14 + + + + + + +
15 + + + + m+ - m+ mr
16 + + + + + + + +
17 + + + m+ m+ - m+ mr
18 + + + + m+ + m+ mr
19 + + m- m- - x m+ mr
20 + + + + + m+ m+ mr
21 + + - m- m- x m+ mr
22 + + + m+ + m+ m+ mr
23 + + - x - - - -
24 + + + + m+ m+ m+ mr
25 + + - x - -
26 + + - x -
27 + + + - m+ - - x
28 + + - x + -
29 + + - x +
30 + + - x + + -
31 + + - x + +
32 + + - x + + + -
33 + + - x + + +
34 + + m+ - m+ x m+ mr
35 + + - x + + + +
36 + x + + m+ m+ m+ mr
38 + x m+ + m+ m+ m+ mr
40 + x + m+ m+ m+ m+ mr
48 + x m+ m+ m+ mr m+ mr
50 + + m- - x m+ m+ mr
51 + + - m- x m+ m+ mr
52 + + - x - m+ m+ mr
53 + + - x m+ - m+ mr
54 + + - x m+ m+ + mr
55 + + m- m- x - m+ mr
56 + + - x m+ + m+ mr
57 + + - m+ x m+ m+ mr
58 + + - x + m+ m+ mr
59 + + x - - - - -
60 + + x - - - -
61 + + x - - -
62 + + x - -
63 + + + - m+ - x -
64 + + + - m+ - x
65 + + x + -
66 + + + - m+ - x +
67 + + x + + -
68 + + x + +
69 + + x + + + -
70 + + x + + +
71 + + x + + + + -
72 + + x + + + +
74 + + x + + + + +
76 + + m+ m+ m+ x m+ mr
81 + + - x m+ m+ m+ mr
119 + + + m- - x m+ mr
120 + + + - m- x m+ mr
121 + + m- + - x m+ mr
122 + + + - x - - -
123 + + + - x - -
124 + + + - x -
125 + + + - x
126 + + + - x + -
127 + + + - x +
128 + + + - x + + -
129 + + + - x + +
130 + + + - m+ x m+ mr
131 + + + - x + + +
132 + + x + m+ m+ + mr
134 + + x + m+ + m+ mr
136 + + x + + m+ m+ mr
188 + + m- x m+ m+ m+ mr
189 + + x - m+ m+ m+ mr
190 + + x m+ - m+ m+ mr
191 + + x m+ m+ - m+ mr
192 + + x m+ m+ m+ + mr
194 + + x m+ m+ + m+ mr
196 + + x m+ + m+ m+ mr
198 + + x + m+ m+ m+ mr
204 + + + m- m- x m+ mr
206 + + m- + m- x m+ mr
208 + + m- m- + x m+ mr
209 + + + m- x - m+ mr
210 + + + m- x m+ + mr
211 + + m- + x - m+ mr
212 + + + x - - - -
213 + + + x - - -
214 + + + x - -
215 + + + x -
216 + + + + - m+ - x
217 + + + x + -
218 + + + x +
219 + + + x + + -
220 + + + x + +
221 + + + x + + + -
222 + + + x + + +
223 + x - m+ - x m+ mr
224 + + + x + + + +
226 + + m+ + m+ x m+ mr
228 + + + m+ m+ x m+ mr
250 + + + - x m+ m+ mr
256 + + x m+ m+ m+ m+ mr
327 + x m- m- - x m+ mr
328 + x m- - m- x m+ mr
329 + x - m- m- x m+ mr
333 + m- x m- - x m+ mr
334 + x m- - x - m+ mr
335 + x - m- x - m+ mr
336 + x - m- x m+ + mr
337 + x m- - x + m+ mr
338 + x - m- x + m+ mr
339 + x - x - - - -
340 + x - x - - -
341 + + + + - x - -
342 + + + + - x -
343 + + + + - x
344 + + + + - x + -
345 + + + + - x +
346 + x - x + + -
347 + + + + - x + +
348 + x - x + + + -
349 + x - x + + +
350 + x - m+ x m+ + mr
351 + x - x + + + +
352 + x - m+ x + m+ mr
353 + x m+ - x + m+ mr
357 + x - m+ m+ x m+ mr
358 + x m+ - m+ x m+ mr
359 + x m+ m+ - x m+ mr
426 + + + m- x m+ m+ mr
428 + + m- + x m+ m+ mr
430 + + + x - m+ m+ mr
431 + + + x m+ - m+ mr
432 + + + x m+ m+ + mr
434 + + + x m+ + m+ mr
436 + + + x + m+ m+ mr
438 + + + m+ x m+ m+ mr
488 + x m- m- m- x m+ mr
494 + m- x m- m- x m+ mr
495 + x m- m- x - m+ mr
496 + x m- m- x m+ + mr
498 + x m- m- x + m+ mr
500 + m- m- x m- x m+ mr
501 + m- x m- x - m+ mr
502 + x m- x - - m+ mr
503 + x m- x - m+ + mr
504 + + + + m- x m+ mr
505 + x m- x + - m+ mr
506 + + + m- + x m+ mr
507 + x x - - - - -
508 + + m- + + x m+ mr
509 + + + + x - - -
510 + + + + x - -
511 + + + + x -
512 + + + + x
513 + + + + x + -
514 + + + + x +
515 + + + + x + + -
516 + + + + x + +
517 + x x + + + -
518 + + + + x + + +
519 + x x + + + + -
520 + + + + m+ x m+ mr
521 + x m+ x + - m+ mr
522 + x x + + + + +
524 + x m+ x + + m+ mr
526 + m- x m+ m+ x m+ mr
527 + x m+ m+ x - m+ mr
528 + x m+ m+ x m+ + mr
530 + x m+ m+ x + m+ mr
536 + x m+ m+ m+ x m+ mr
648 + + + x m+ m+ m+ mr
678 + x m- - x m+ m+ mr
679 + x - m- x m+ m+ mr
684 + x - x - m+ m+ mr
685 + x - x m+ - m+ mr
686 + x - x m+ m+ + mr
688 + x - x m+ + m+ mr
690 + x - x + m+ m+ mr
693 + x - m+ x m+ m+ mr
694 + x m+ - x m+ m+ mr
719 + x + m- - x m+ mr
720 + x + - m- x m+ mr
721 + x m- + - x m+ mr
722 + x - m- + x m+ mr
726 + x + - x - - -
727 + x + - x - -
728 + + + + + - x -
729 + + + + + - x
730 + x + - x + -
731 + + + + + - x +
732 + x + - x + + -
733 + x + - x + +
735 + x + - x + + +
736 + x - m+ + x m+ mr
737 + x m+ + - x m+ mr
738 + x + - m+ x m+ mr
739 + x + m+ - x m+ mr
980 + x + m- m- x m+ mr
982 + x m- + m- x m+ mr
984 + x m- m- + x m+ mr
988 + m- x + m- x m+ mr
989 + x + m- x - m+ mr
990 + x + m- x m+ + mr
991 + x m- + x - m+ mr
992 + x + m- x + m+ mr
994 + x m- + x + m+ mr
996 + x + x - - - -
997 + x + x - - -
998 + + + + + x - -
999 + + + + + x -
1000 + + + + + x
1001 + + + + + x + -
1002 + + + + + x +
1003 + x + x + + -
1004 + + + + + x + +
1005 + x + x + + + -
1006 + x + x + + +
1007 + x m+ + x - m+ mr
1008 + x + x + + + +
1009 + x + m+ x - m+ mr
1010 + x + m+ x m+ + mr
1012 + x + m+ x + m+ mr
1014 + x m- x - m+ m+ mr
1015 + x m- x m+ - m+ mr
1016 + x m+ m+ + x m+ mr
1018 + x m+ + m+ x m+ mr
1020 + x + m+ m+ x m+ mr
1021 + x x - m+ - m+ mr
1022 + x x - m+ m+ + mr
1023 + x x m+ - m+ + mr
1024 + + + + x m+ m+ mr
1025 + x x m+ + - m+ mr
1026 + x x + - m+ m+ mr
1027 + x x + m+ - m+ mr
1028 + x x + m+ m+ + mr
1029 + x - x m+ m+ m+ mr
1030 + x x + m+ + m+ mr
1031 + x m+ x m+ - m+ mr
1032 + x x + + m+ m+ mr
1034 + x m+ x m+ + m+ mr
1036 + x m+ x + m+ m+ mr
1040 + x m+ x m+ mr m+ mr
1329 + x + + - x - -
1330 + x + + - x -
1331 + + + + + + - x
1332 + x + + - x + -
1333 + x + + - x +
1335 + x + + - x + +
1458 + x + - x m+ m+ mr
1528 + x m- x m+ m+ m+ mr
1533 + x x - m+ m+ m+ mr
1534 + x x m+ - m+ m+ mr
1535 + x x m+ m+ - m+ mr
1536 + x x m+ m+ m+ + mr
1538 + x x m+ m+ + m+ mr
1540 + x x m+ + m+ m+ mr
1542 + x x + m+ m+ m+ mr
1544 + x m+ x m+ m+ m+ mr
1716 + x + + m- x m+ mr
1718 + x + m- + x m+ mr
1720 + x m- + + x m+ mr
1725 + x + + x - - -
1726 + x + + x - -
1727 + + + + + + x -
1728 + + + + + + x
1729 + x + + x + -
1730 + + + + + + x +
1731 + x + + x + + -
1732 + x + + x + +
1734 + x + + x + + +
1736 + x m+ + + x m+ mr
1738 + x + m+ + x m+ mr
1740 + x + + m+ x m+ mr
1990 + x + m- x m+ m+ mr
1992 + x m- + x m+ m+ mr
1998 + x + x - m+ m+ mr
1999 + x + x m+ - m+ mr
2000 + x + x m+ m+ + mr
2002 + x + x m+ + m+ mr
2004 + x + x + m+ m+ mr
2008 + x m+ + x m+ m+ mr
2010 + x + m+ x m+ m+ mr
2048 + x x m+ m+ m+ m+ mr
2196 + x + + + - x -
2197 + x + + + - x
2199 + x + + + - x +
2742 + x + + + x - -
2743 + x + + + x -
2744 + + + + + + + x
2745 + x + + + x + -
2746 + x + + + x +
2748 + x + + + x + +
3000 + x + x m+ m+ m+ mr
3374 + x m+ - m+ mr x -
3375 + x + + + + - x
3377 + x m+ - m+ mr x +
3456 + x + + x m+ m+ mr
4080 + x m- m- mr x m- mr
4094 + x m+ m+ mr x - -
4095 + x + + + + x -
4096 + + + + m+ m+ mr x
4097 + x m+ m+ mr x + -
4098 + x + + + + x +
4100 + x m+ m+ mr x + +
4112 + x m+ m+ mr x m+ mr
4913 + x m+ + - m+ mr x
5831 + x m+ + m+ mr x -
5832 + + + m+ m+ m+ mr x
5834 + x m+ + m+ mr x +
6859 + x + m+ - m+ mr x
7999 + x + m+ m+ mr x -
8000 + x + m+ m+ + mr x
8002 + x + m+ m+ mr x +
9261 + x - m+ m+ m+ mr x
|
Posted by Charlie
on 2023-03-31 09:47:52 |