Home » Archimedes archive » Acorn User » AU 1998-07.adf » Regulars » StarInfo/Brobecker/Hanoi
StarInfo/Brobecker/Hanoi
This website contains an archive of files for the Acorn Electron, BBC Micro, Acorn Archimedes, Commodore 16 and Commodore 64 computers, which Dominic Ford has rescued from his private collection of floppy disks and cassettes.
Some of these files were originally commercial releases in the 1980s and 1990s, but they are now widely available online. I assume that copyright over them is no longer being asserted. If you own the copyright and would like files to be removed, please contact me.
Tape/disk: | Home » Archimedes archive » Acorn User » AU 1998-07.adf » Regulars |
Filename: | StarInfo/Brobecker/Hanoi |
Read OK: | ✔ |
File size: | 03F8 bytes |
Load address: | 0000 |
Exec address: | 0000 |
File contents
10REM>>> Hanoi towers 20REM Alain BROBECKER (baah/Arm's Tech) on ??-Jan-1998 30 40REMAlgorithm is based upon the following fact... 50REMMoving the pile of N elements from stick I to stick J is equivalent to 60REM 1) moving the N-1 elts' pile from I to K 70REM 2) moving the last elt from I to J 80REM 3) moving the N-1 elts' pile from K to J 90MODE9:OFF:FORc%=1TO15:COLOURc%,c%*17,5*17,0:NEXT 100nb%=12 :REMnb of rings 110s%=32 :REMsize of ring 120max%=(nb%+1)*s% :REMsize of biggest ring 130DIMsize%(2):size%()=max%,0,0 :REMsizes of bottom rings 140FORc%=1TOnb%:PROCbox(c%,0,(nb%+1-c%)*s%,c%*s%/2):NEXT :REMdraw initial position 150IFGET 160PROCHanoi(nb%,0,1,2) 170END 180 190DEFPROCHanoi(nb%,from%,to%,temp%) 200 IFNOTnb%THEN 210 PROCHanoi(nb%-1,from%,temp%,to%) 220 WAIT 230 PROCbox(0,from%,size%(from%),nb%*s%/2) 240 size%(from%)-=s% 250 size%(to%)+=s% 260 PROCbox(nb%,to%,size%(to%),nb%*s%/2) 270 PROCHanoi(nb%-1,temp%,to%,from%) 280 ENDIF 290ENDPROC 300 310DEFPROCbox(col%,x%,y%,size%) 320 GCOLcol% 330 RECTANGLEFILLx%*400+200-size%,y%,2*size%,s%/2 340ENDPROC
�>>> Hanoi towers 9� Alain BROBECKER (baah/Arm's Tech) on ??-Jan-1998 (2�Algorithm is based upon the following fact... 2K�Moving the pile of N elements from stick I to stick J is equivalent to </� 1) moving the N-1 elts' pile from I to K F)� 2) moving the last elt from I to J P/� 3) moving the N-1 elts' pile from K to J Z$�9:�:�c%=1�15:�c%,c%*17,5*17,0:� d)nb%=12 :�nb of rings n*s%=32 :�size of ring x2max%=(nb%+1)*s% :�size of biggest ring �6�size%(2):size%()=max%,0,0 :�sizes of bottom rings �H�c%=1�nb%:�box(c%,0,(nb%+1-c%)*s%,c%*s%/2):� :�draw initial position �� ��Hanoi(nb%,0,1,2) �� � � ��Hanoi(nb%,from%,to%,temp%) � �nb%� �# �Hanoi(nb%-1,from%,temp%,to%) � Ȗ �) �box(0,from%,size%(from%),nb%*s%/2) � size%(from%)-=s% � size%(to%)+=s% ' �box(nb%,to%,size%(to%),nb%*s%/2) # �Hanoi(nb%-1,temp%,to%,from%) � "� , 6��box(col%,x%,y%,size%) @ �col% J) ȓȐx%*400+200-size%,y%,2*size%,s%/2 T� �
00000000 0d 00 0a 15 f4 3e 3e 3e 20 48 61 6e 6f 69 20 74 |.....>>> Hanoi t| 00000010 6f 77 65 72 73 0d 00 14 39 f4 20 20 20 20 41 6c |owers...9. Al| 00000020 61 69 6e 20 42 52 4f 42 45 43 4b 45 52 20 28 62 |ain BROBECKER (b| 00000030 61 61 68 2f 41 72 6d 27 73 20 54 65 63 68 29 20 |aah/Arm's Tech) | 00000040 6f 6e 20 3f 3f 2d 4a 61 6e 2d 31 39 39 38 0d 00 |on ??-Jan-1998..| 00000050 1e 04 0d 00 28 32 f4 41 6c 67 6f 72 69 74 68 6d |....(2.Algorithm| 00000060 20 69 73 20 62 61 73 65 64 20 75 70 6f 6e 20 74 | is based upon t| 00000070 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 66 61 63 |he following fac| 00000080 74 2e 2e 2e 0d 00 32 4b f4 4d 6f 76 69 6e 67 20 |t.....2K.Moving | 00000090 74 68 65 20 70 69 6c 65 20 6f 66 20 4e 20 65 6c |the pile of N el| 000000a0 65 6d 65 6e 74 73 20 66 72 6f 6d 20 73 74 69 63 |ements from stic| 000000b0 6b 20 49 20 74 6f 20 73 74 69 63 6b 20 4a 20 69 |k I to stick J i| 000000c0 73 20 65 71 75 69 76 61 6c 65 6e 74 20 74 6f 0d |s equivalent to.| 000000d0 00 3c 2f f4 20 20 31 29 20 6d 6f 76 69 6e 67 20 |.</. 1) moving | 000000e0 74 68 65 20 4e 2d 31 20 65 6c 74 73 27 20 70 69 |the N-1 elts' pi| 000000f0 6c 65 20 66 72 6f 6d 20 49 20 74 6f 20 4b 0d 00 |le from I to K..| 00000100 46 29 f4 20 20 32 29 20 6d 6f 76 69 6e 67 20 74 |F). 2) moving t| 00000110 68 65 20 6c 61 73 74 20 65 6c 74 20 66 72 6f 6d |he last elt from| 00000120 20 49 20 74 6f 20 4a 0d 00 50 2f f4 20 20 33 29 | I to J..P/. 3)| 00000130 20 6d 6f 76 69 6e 67 20 74 68 65 20 4e 2d 31 20 | moving the N-1 | 00000140 65 6c 74 73 27 20 70 69 6c 65 20 66 72 6f 6d 20 |elts' pile from | 00000150 4b 20 74 6f 20 4a 0d 00 5a 24 eb 39 3a 87 3a e3 |K to J..Z$.9:.:.| 00000160 63 25 3d 31 b8 31 35 3a fb 63 25 2c 63 25 2a 31 |c%=1.15:.c%,c%*1| 00000170 37 2c 35 2a 31 37 2c 30 3a ed 0d 00 64 29 6e 62 |7,5*17,0:...d)nb| 00000180 25 3d 31 32 20 20 20 20 20 20 20 20 20 20 20 20 |%=12 | 00000190 20 20 20 20 20 20 3a f4 6e 62 20 6f 66 20 72 69 | :.nb of ri| 000001a0 6e 67 73 0d 00 6e 2a 73 25 3d 33 32 20 20 20 20 |ngs..n*s%=32 | 000001b0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 3a | :| 000001c0 f4 73 69 7a 65 20 6f 66 20 72 69 6e 67 0d 00 78 |.size of ring..x| 000001d0 32 6d 61 78 25 3d 28 6e 62 25 2b 31 29 2a 73 25 |2max%=(nb%+1)*s%| 000001e0 20 20 20 20 20 20 20 20 20 3a f4 73 69 7a 65 20 | :.size | 000001f0 6f 66 20 62 69 67 67 65 73 74 20 72 69 6e 67 0d |of biggest ring.| 00000200 00 82 36 de 73 69 7a 65 25 28 32 29 3a 73 69 7a |..6.size%(2):siz| 00000210 65 25 28 29 3d 6d 61 78 25 2c 30 2c 30 20 3a f4 |e%()=max%,0,0 :.| 00000220 73 69 7a 65 73 20 6f 66 20 62 6f 74 74 6f 6d 20 |sizes of bottom | 00000230 72 69 6e 67 73 0d 00 8c 48 e3 63 25 3d 31 b8 6e |rings...H.c%=1.n| 00000240 62 25 3a f2 62 6f 78 28 63 25 2c 30 2c 28 6e 62 |b%:.box(c%,0,(nb| 00000250 25 2b 31 2d 63 25 29 2a 73 25 2c 63 25 2a 73 25 |%+1-c%)*s%,c%*s%| 00000260 2f 32 29 3a ed 20 3a f4 64 72 61 77 20 69 6e 69 |/2):. :.draw ini| 00000270 74 69 61 6c 20 70 6f 73 69 74 69 6f 6e 0d 00 96 |tial position...| 00000280 06 e7 a5 0d 00 a0 15 f2 48 61 6e 6f 69 28 6e 62 |........Hanoi(nb| 00000290 25 2c 30 2c 31 2c 32 29 0d 00 aa 05 e0 0d 00 b4 |%,0,1,2)........| 000002a0 04 0d 00 be 20 dd f2 48 61 6e 6f 69 28 6e 62 25 |.... ..Hanoi(nb%| 000002b0 2c 66 72 6f 6d 25 2c 74 6f 25 2c 74 65 6d 70 25 |,from%,to%,temp%| 000002c0 29 0d 00 c8 0b 20 e7 ac 6e 62 25 8c 0d 00 d2 23 |).... ..nb%....#| 000002d0 20 20 f2 48 61 6e 6f 69 28 6e 62 25 2d 31 2c 66 | .Hanoi(nb%-1,f| 000002e0 72 6f 6d 25 2c 74 65 6d 70 25 2c 74 6f 25 29 0d |rom%,temp%,to%).| 000002f0 00 dc 08 20 20 c8 96 0d 00 e6 29 20 20 f2 62 6f |... .....) .bo| 00000300 78 28 30 2c 66 72 6f 6d 25 2c 73 69 7a 65 25 28 |x(0,from%,size%(| 00000310 66 72 6f 6d 25 29 2c 6e 62 25 2a 73 25 2f 32 29 |from%),nb%*s%/2)| 00000320 0d 00 f0 16 20 20 73 69 7a 65 25 28 66 72 6f 6d |.... size%(from| 00000330 25 29 2d 3d 73 25 0d 00 fa 14 20 20 73 69 7a 65 |%)-=s%.... size| 00000340 25 28 74 6f 25 29 2b 3d 73 25 0d 01 04 27 20 20 |%(to%)+=s%...' | 00000350 f2 62 6f 78 28 6e 62 25 2c 74 6f 25 2c 73 69 7a |.box(nb%,to%,siz| 00000360 65 25 28 74 6f 25 29 2c 6e 62 25 2a 73 25 2f 32 |e%(to%),nb%*s%/2| 00000370 29 0d 01 0e 23 20 20 f2 48 61 6e 6f 69 28 6e 62 |)...# .Hanoi(nb| 00000380 25 2d 31 2c 74 65 6d 70 25 2c 74 6f 25 2c 66 72 |%-1,temp%,to%,fr| 00000390 6f 6d 25 29 0d 01 18 06 20 cd 0d 01 22 05 e1 0d |om%).... ..."...| 000003a0 01 2c 04 0d 01 36 1b dd f2 62 6f 78 28 63 6f 6c |.,...6...box(col| 000003b0 25 2c 78 25 2c 79 25 2c 73 69 7a 65 25 29 0d 01 |%,x%,y%,size%)..| 000003c0 40 0a 20 e6 63 6f 6c 25 0d 01 4a 29 20 c8 93 c8 |@. .col%..J) ...| 000003d0 90 78 25 2a 34 30 30 2b 32 30 30 2d 73 69 7a 65 |.x%*400+200-size| 000003e0 25 2c 79 25 2c 32 2a 73 69 7a 65 25 2c 73 25 2f |%,y%,2*size%,s%/| 000003f0 32 0d 01 54 05 e1 0d ff |2..T....| 000003f8