Hi Ed, I'm addicted to obfuscated perl solutions to your problems. It's often more fun for me to write and minimize a perl program than to solve the problem itself :) For the 2003=>2004 puzzle, I couldn't come up with one-liner, but the solution is still short enough: ### sub p{for(@s=([$_[0]]);$m=shift@s;){$l=length($n=$$m[0])-1;$n=~ s/(\d)(?!$)/$1-/g;for$c(1..2**$l-1){$_=sprintf"$n \%0${l}b",$c;while (s/-(.* )0/$1/|s/-(.* )1/\+$1/){}s/0*(\d+)/$1*$1/g;push@r,$_}for$p (@r){$e=[$q=eval$p,$p,$m];next if$h{$q}++or$q>9e9;while($q==$_[1]){ $a="$$e[1]= $$e[0]\n$a";if(!($e=$$e[2])){print$a;exit}}push@s,$e}}}p 2003 => 2004 ### Note: the last line, 2003 => 2004, is a part of the program. You can change 2003 and 2004 to other numbers. Well, to make the program compact, I deleted some code that optimized speed of execution. So, I don't guarantee a fast solution for arbitrary numbers :) Also, only the first shortest solution is printed out. On my machine, calculations for 2003 => 2004 take about 40 seconds and this is the actual printout: = 2003 200*200+3*3 = 40009 4000*4000+9*9 = 16000081 16000*16000+81*81 = 256006561 2*2+5*5+60065*60065+6*6+1*1 = 3607804291 3*3+6*6+7*7+8*8+42*42+9*9+1*1 = 2004 Regards, Igor Krivokon ------------------------------------------------------------- Ed, "Find positive integers A, B, C, D, and E all less than 100 so that A^2 + B^2 + C^2 = D^2 + E^2 and A^3 + B^3 + C^3 = D^3 + E^3" Answer: For integers from 1-99, there is one unique solution set not counting swapping A, B, C around, or swapping D and E: For A,B,C, the numbers are 21, 26, 64. For D and E, the numbers are 37 and 62. Counting all combinations of these due to addition reordering, there are 12 solution combinations. Further analysis: Counting all possible combinations, there are 647913 solutions to A^2 + B^2 + C^2 = D^2 + E^2, and 11550 solutions to A^3 + B^3 + C^3 = D^3 + E^3. If we change the range from 1-99 to 1-199, there are three solution sets (or 36 total solution combinations counting addition reordering): 1. (A,B,C)=42,52,128; (C,D)=74,124 2. (A,B,C)=63,78,192; (C,D)=111,186 3. (A,B,C)=21,26,64; (C,D)=37,62 Thanks for the diversion on a slow work day! Happy Holidays, J.B. Gill ----------------------------------------------------------- Ed, There are many 6-step variants. These are two of 5-step solutions: 200:3 -> 400:0:9 -> 1600:8:1 -> 2:560065 -> 3:1:36:7:2:8:0:4:22:9 -> 2004 200:3 -> 4000:9 -> 16000:0:81 -> 2:5:60065:6:1 -> 3:6:0:7:8:0:42:9:1 -> 2004 Do we necessarily need to chop numbers on each step? If not, there's at least one 4-step solution: 200:3 -> 40009 -> 1:600:7:2008:1 -> 4:39:21:1:5 -> 2004 Thanks, Igor Krivokon ---------------------------------------------------------------------- From your site: > Erich Friedman: Start with 2003. Chop it up any way you like: 20,0,3. Square the pieces and add them together to get a new number 400+0+9=409. Repeat until you get 2004. It's easy to find a path that takes 7 steps: 20:0:3 --> 40:9 --> 1:6:81 --> 6:59:8 --> 35:8:1 --> 12:90 -> 8:2:44 --> 2004. Find a 6 step path from 2003 to 2004. might make a good new yearspuzzle. this took 7 steps. Do it in six steps. Just a quick summary of my findings: It is indeed possible in six steps: 20,0,3 -> 409 -> 1,672,81 -> 45,814,6 -> 66,4,6,5,7 -> 44,8,2 -> 2004 Or even better, in five steps: 2003 -> 401,20,0,9 -> 1612,82 -> 2,6,0,52,6,8 -> 2,8,44 -> 2004 -- Greetings, Dave Langers. _______________ --------------------------------------------------------------------- --- One of the puzzles on mathpuzzle.com assked to get from 2003 to 2004 by chopping up the number, squaring the pieces and adding the squares in six steps. Will a sequence of four steps do as well? 2003 -> 200, 3 -> 40000 + 9 -> 40009 -> 40009 -> 1600720081 -> 1600720081 -> 1, 600, 7, 2008, 1 -> 1 + 360000 + 49 + 4032064 + 1 -> 4392115 -> 4, 39, 21, 1, 5 -> 16 + 1521 + 441 + 1 + 25 -> 2004 Abigail ---------------------------------------------------------------------- Ed, I found three solutions: 20:03 --> 409 --> 1:672:81 --> 45:814:6 --> 66:4:6:5:7 --> 44:8:2 --> 2004 20:03 --> 409 --> 1:672:81 --> 458:1:4:6 --> 209:8:1:7 --> 43:7:9:5 --> 2004 200:3 --> 400:09 --> 1:600:81 --> 3:665:6:2 --> 442:2:74 --> 2:008:44 --> 2004 Al Zimmermann ----------------------------------------------------------------- Hello, I think these are all solutions (Excluding dupes): 6 Steps: 20 0 3 >409 >1 672 81 >45 814 6 >66 4 6 5 7 >44 8 2 20 0 3 >409 >1 672 81 >458 1 4 6 >209 8 1 7 >43 7 9 5 20 0 3 >409 >167 281 >1068 5 0 >1 140 649 >44 0 8 0 2 20 0 3 >409 >1672 8 1 >2795 649 >8 233 2 2 6 >5 43 9 7 200 3 >400 0 9 >1 600 81 >3 665 6 2 >442 2 74 >2 0 0 8 44 if its allowed not to split ... 5 Steps: 2003 >40 1200 9 >1 4 4 1 6 81 >663 1 >43 9 5 7 0 2003 >40 1200 9 >1 4 416 8 1 >1 731 3 8 >5 3 44 3 5 6 Steps: 2003 >4 0 1 200 9 >40 0 98 >112 0 4 >12 560 >3 1 3 7 44 2003 >4 0 1 2009 >4 0 360 9 8 >1297 61 >1 6 8 59 30 >44 8 2 2003 >4 0 1 2009 >40 3 60 98 >148 13 >2 2073 >4 29 7 3 33 2003 >4 0 1 2009 >40 3 60 98 >1481 3 >2 193 370 >17 41 5 3 2003 >4 0 1 2009 >40 360 9 8 >1313 45 >1 725 99 4 >5 3 5 44 3 2003 >40 1 2 0 0 9 >1 686 >470 59 7 >2 2 44 30 >2 8 44 2003 >40 1 2 0 0 9 >1686 >2 842 5 96 >7 1 8 209 >43 7 9 5 2003 >40 1 200 9 >4 1 682 >465 1 41 >2 17 90 7 >8 44 2 2003 >40 1 200 9 >4 1682 >2829 1 40 >80 0 4 8 42 >8 2 44 2003 >40 1 2009 >4 0 376 8 2 >1414 60 >200 2 9 9 6 >40 20 2 2003 >40 1 2009 >403 7 6 8 2 >1 625 6 2 >3 9 0 6 66 >44 8 2 2003 >40 1 2009 >403 7 682 >627 582 >7 31 85 3 >8 2 44 2003 >40 1 2009 >403 76 8 2 >1682 5 3 >2 8 2 91 5 8 >8 44 2 2003 >40 1200 9 >1 441 6 8 1 >1 9 458 3 >209 8 5 5 >43 7 9 5 2003 >40 1200 9 >1 441 681 >6 5 82 43 >8 634 >40 2 0 20 2003 >40 1200 9 >14 4 1 681 >463 9 74 >219 926 >9 0 5 43 7 2003 >40 1200 9 >14 4 1681 >2 825 9 73 >6 860 39 >7 41 15 7 2003 >40 1200 9 >14 4 1681 >2825 9 7 3 >7 980 764 >1 5 44 1 4 5 2003 >40 1200 9 >1441 6 8 1 >2 0 765 8 2 >585 29 7 >3 43 11 5 2003 >40 1200 9 >1441 681 >2540 2 4 2 >6 45 1 624 >3 9 1 43 8 2003 >401 20 0 9 >16 1282 >1643 78 0 >270 55 3 3 >7 5 9 43 2003 >401 20 0 9 >1612 82 >2 6 0 52 6 8 >2 8 44 2003 >401 200 9 >2008 82 >403 878 8 >9 3 33 57 >44 2 8 2003 >401 2009 >4 196 8 82 >4 5 220 >484 41 >23 5 9 37 2003 >401 2009 >4 1968 8 2 >38 731 0 8 >5 3 586 9 >3 43 5 11 2003 >401 2009 >41 9 68 82 >1311 0 >1 7 1872 1 >3 5 0 44 3 5 cu Yves -- Yves Hetzer ----------------------------------------------------------------- There's a solution in *four* steps: 200:3 -> 40009 -> 1:600:7:2008:1 -> 4:39:21:1:5 -> 2004 -- Keith F. Lynch ----------------------------------------------------------------- Hi Ed! (remember me?) I'm glad that whenever I find the time to visit your page, I'm always challenged and entertained by your puzzles! I wrote a program to solve this puzzle and came up with this 5-step solution: 200:3 -> 4000:9 -> 16000:0:81 -> 2:5:60065:6:1 -> 3:6:0:7:8:0:42:9:1 -> 2004 Regards, Yogy Namara ----------------------------------------------------------------- Dear Ed, some weeks ago I had sent the solution for power-of-2-approximations and two small programs which you have published since. Now I enjoyed your (Erich's) new year's problem with chopping and squaring. My solution is: 20.03 > 409 > 1.672.81 > 458.1.4.6 > 209.8.1.7 > 43.7.9.5 > 2004 A usual I have written a small DOS-program doing the computations: TeileQua If you start the program with "TeileQua beg end" it tries to find a path from 'beg' to 'end' and writes the solution into the file 'TeileQua.dat'. The program has in the first step a highest number (1.000.000) till which it searches. If it has no success it multiplies the highnumber by 10 and searches again, and so on. If you start the program with 'TeileQua beg end/highnumber' then the highest searched number is 'highnumber'. If it finds an solution then it the shortest within the range of the high-number. Rarely, it does not find a solution which means that the internal tables of 33.000 entries are not enough. Try 'TeileQua 2003 2004' and you will get the above solution. Try 'TeileQua 2003 2004/1000' and you will get your old solution (the program has expanded once the high-number to 10.000). There is one more request with 'TeileQua v=beg b=end' which will give you a table for all the possibilities of the numbers from 'beg' to 'end' and writes this into a file named 'TeileQua.all'. I hope you and the readers enjoy my findings. Sincerely yours - Bodo Zinser PS: I think that it is always possible to find a path from any starting-number (except powers of 10) to any positive end-number. Even more there will be an number infinite of solutions which are more and more longer. Who finds a solid proof for this? 'TeileQua.bas '------------ $compile exe Sta???=2003:Zie???=2004 goto Haupt Def FNQ1???(X%) 'Je nach Index ZQ1x??? bergeben shared TQ1A???(),TQ1B???() if X%<=16380 then X???=TQ1A???(X%) elseif X%<=2*16380 then X???=TQ1B???(X%) end if FNQ1???=X??? end def Def FNQ2???(X%) 'Je nach Index ZQ2x??? bergeben shared TQ2A???(),TQ2B???() if X%<=16380 then X???=TQ2A???(X%) elseif X%<=2*16380 then X???=TQ2B???(X%) end if FNQ2???=X??? end def Def FNZ$(X???)=ltrim$(rtrim$(str$(X???))) 'Zahl normiert ohne Nullen Sub SucheZahl(Z???,E%) 'Suche in TQ, ob Zahl schon da shared Anz% E%=0 for i%=1 to Anz% if FNQ1???(i%)=Z??? then E%=i%:exit sub next i% end sub Sub Tast 'Tastendruck abwarten und bestimmen shared E$ while not instat:wend E$=inkey$ end sub Sub TeileQuad(Z$,E$) 'Teile und quadriere L%=len(Z$) if L%=1 then E$="1" end if if L%=2 then E$="11/2" end if if L%=3 then E$="111/12/21/3" end if if L%=4 then E$="1111/112/121/211/22/13/31/4" end if if L%=5 then E$="11111/1112/1121/1211/2111/122/212/221/113/131/311/23/32/14/41/5" end if if L%=6 then E$="111111/11112/11121/11211/12111/21111/1122/1212/1221/2112/2121/2211"_ +"/222/1113/1131/1311/3111/123/132/213/231/312/321/33/114/141/411"_ +"/24/42/15/51/6" end if if L%=7 then E$="1111111/111112/111121/111211/112111/121111/211111"_ +"/11122/11212/11221/12112/12121/12211/21112/21121/21211/22111"_ +"/1222/2122/2212/2221/11113/11131/11311/13111/31111"_ +"/1123/1213/2113/1132/1231/2131/1312/1321/2311/3112/3121/3211"_ +"/223/232/322/133/313/331/1114/1141/1411/4111"_ +"/124/142/214/241/412/421/34/43/115/151/511/25/52/16/61/7" end if if L%>7 then E$=string$(L%,"1") end if E$=E$+"/" end sub Sub Weg(Z???,W$) 'Weg der gesuchten Zahl shared Anz%,Sta??? W$="" SW: call SucheZahl(Z???,E%) TQ???=FNQ1???(E%) W$=FNZ$(TQ???)+" > "+W$ if len(W$)>5 then if TQ???=Sta??? then W$=left$(W$,len(W$)-3):exit sub end if Z???=FNQ2???(E%) goto SW end sub Sub WertQ1(X%,X???) 'Wert TQ1x??? bergeben je nach Index shared TQ1A???(),TQ1B???() if X%<=16380 then TQ1A???(X%)=X??? elseif X%<=2*16380 then TQ1B???(X%)=X??? end if end sub Sub WertQ2(X%,X???) 'Wert TQ2x??? bergeben je nach Index shared TQ2A???(),TQ2B???() if X%<=16380 then TQ2A???(X%)=X??? elseif X%<=2*16380 then TQ2B???(X%)=X??? end if end sub Haupt: 'Hauptprogramm ZR???=1000000 Par$=rtrim$(lcase$(command$)) if Par$>"" then if left$(Par$,2)="v=" then Sta%=val(mid$(Par$,3)) Zie%=Sta% y%=instr(Par$,"b=") if y%>0 then Zie%=val(mid$(Par$,y%+2)) goto Alle end if y%=instr(Par$,"/") if y%>0 then ZR???=val(mid$(Par$,y%+1)):Par$=left$(Par$,y%-1) y%=instr(Par$," ") if y%=0 then print "Falsche Parameter":end Sta???=val(Par$):Zie???=val(mid$(Par$,y%+1)) end if cls print "Teile und quadriere" print "-------------------" print "nach einer Idee von Erich Friedmann in www.MathPuzzle.com vom 1.Jan. 2004:" print "Nimm eine Zahl als String und teile sie in beliebige Stcke auf." print "Diese Stcke quadriere und addiere und verfahre mit der neuen Zahl" print "ebenso bis du an deinem Ziel angelangt bist." print "Bsp.: 20/0/3 > 40/9 > 1/6/81 > 6/59/8 > 35/8/1 > 12/90 > 8/2/44 > 2004" print print "Start="Sta???"Ziel="Zie??? delay 3 dim TQ1A???(1:16380),TQ1B???(16381:32760) 'Von dim TQ2A???(1:16380),TQ2B???(16381:32760) 'Nach Beginn: 'Beginn des Programms Anz%=1:Akt%=0 call WertQ1(1,Sta???) NaechsteZahl: 'Die kleinste Akt%=Akt%+1 if Akt%>Anz% then print "Keine L”sung im Zahlenraum bis"ZR??? delay 3 ZR???=10*ZR??? goto Beginn end if TQ???=FNQ1???(Akt%) TQ$=FNZ$(TQ???) call TeileQuad(TQ$,Erg$):L%=len(TQ$) NeueZahlen: 'Neue Zahlen daraus ausgeben y%=instr(Erg$,"/") if y%=0 then NaechsteZahl Z$=left$(Erg$,y%-1):Erg$=mid$(Erg$,y%+1) y1%=1:NZ???=0 for i%=1 to len(Z$) y2%=val(mid$(Z$,i%,1)) y3???=val(mid$(TQ$,y1%,y2%)) NZ???=NZ???+y3???*y3??? y1%=y1%+y2% next i% if y1%<>L%+1 then print"Fehler in Aufteilung":end if NZ???>=ZR??? then NeueZahlen call SucheZahl(NZ???,Erg%) if Erg%=0 then 'noch nicht vorhanden Anz%=Anz%+1:if Anz%>2*16380 then Anz%=2*16380 Erg%=Anz% call WertQ1(Erg%,NZ???) call WertQ2(Erg%,TQ???) else if FNQ2???(Erg%)=0 then call WertQ2(Erg%,TQ???) end if print Akt%;FNQ2???(Erg%)">"FNQ1???(Erg%) ':call Tast if NZ???<>Zie??? then NeueZahlen Anz%=Anz%+1:if Anz%>16380 then Anz%=16380 call WertQ1(Anz%,NZ???):call WertQ2(Anz%,TQ???) call Weg(NZ???,W$) print print "Ziel erreicht:" print "Maximal untersuchte Zahl:"ZR??? print W$ open "TEILEQUA.DAT" for output as #1 print #1,"Ziel erreicht:" print #1,"Maximal untersuchte Zahl:"ZR??? print #1,W$ close end Alle: 'Alle Zahlen bis ... untersuchen open "TeileQua.all" for output as #1 for i%=1 to Zie% TQ$=FNZ$(i%) print TQ$" >"; print #1,TQ$" >"; call TeileQuad(TQ$,Erg$):L%=len(TQ$) AlleZahlen: 'Alle Zahlen: Ergebnisse y%=instr(Erg$,"/") if y%>0 then Z$=left$(Erg$,y%-1):Erg$=mid$(Erg$,y%+1) y1%=1:NZ???=0 for j%=1 to len(Z$) y2%=val(mid$(Z$,j%,1)) y3???=val(mid$(TQ$,y1%,y2%)) NZ???=NZ???+y3???*y3??? y1%=y1%+y2% next j% if y1%<>L%+1 then print"Fehler in Aufteilung":end print " "FNZ$(NZ???); print #1," "FNZ$(NZ???); goto AlleZahlen end if print print #1,"" next i% close end