Previous Up Next

Program beest

This program for the Acorn Atom counts the number of all possible Hamilton paths starting from any point to all other points in a rectangle.

The bottom part of the program contains the assembly instructions that generate the core algorithm for finding the Hamilton path. After the machine code has been generated the, the main loop (starting at line 30) is started. In this loop, first the length and the height of the rectangle are asked for. Then the Hamilton counting algorith is called for all possible starting points, and the grand total is printed.

The original program contained in-line machine instructions stored in the comment in line 5, for turning the top line of the screen into inverted graphics. The LINKLL0 will cause an error in the listing below.

Program listing

Saved as beest from 2900-3200.
    5REM ??????????????
   10P.$12;?#E1=0;P."info"';LINK((?18)*256+7)
   11P.''"DIT PROGRAMMA BEREKENT HET"
   12P.'"AANTAL SLANGEN IN EEN RECHTHOEK"
   13P.''"(RET)";LINK#FFE3
   15A=0DIMA25;$A="P.$7$11;G.(#FFFF&!1)";?16=A;?17=A/256
   20GOS.a
   30P.$12"INVOER"'';LINKLL0;?E1=#80
  100IN."HOOGTE [1,14]  "L;IFL>14OR 0>L P.$13$11;G.100
  101IN."LENGTE [1,6]   "H;IFH>6OR 0>H P.$13$11;G.101
  102IF H=1 OR L=1 P. '"triviaal"''"(RET)";LINK#FFE3;G.30
  104P.$12
  105GOS.s;?#E1=0
  110O=(L+1)/2;Q=(H+1)/2;G=0
  120F.A=1 TO O;F.B=1 TO Q
  125IF H%2=1ANDL%2=1AND(A+B)%2=1 G.140
  130GOS.d;G=G+T*(s-(A*2=L+1))*(2-(B*2=H+1))
  140N.;N.
  150@=1;P.$30"geval  "L","H"   totaal "G/2"         ";LINKLL0
  155LINK#FFE3;G.30
  160eP.A,B,(2-(A*2=L+1))*(2-(B*2=H+1))';R.
  201s
  220F.I=0TOL;F.J=1TOH;F?(I+Z*J)=32;N.;N.
  230F.I=0TO L+1;F?I=V;F?(I+H*Z+Z)=V;N.
  240F.I=0TO H+1;F?(I*Z)=V;F?(1+L+I*Z)=V;N.
  250 ?K=L*H-1;R.
  251dI=#83;?I=0;?C=A+B*Z;F?(?C)=V
  254@=1;P.$30"geval "L","H"   computing "A","B"     ";LINKLL0
  260IFA=1OR1=B THEN ?#85=#FF;LINK#A6000;G.268
  265LINK#A671
  268F?(A+B*Z)=32
  270P.$8$8$7$8$8$8"ready";LINKLL0;LINK#FFE3
  300R.
 1010aC=#80;D=#81;E=#82;I=#83
 1020P.$12"assembler"';LINK(256*?18+7);P.'''"(ADDRES,ADDRES"
 1021P."+580] USED"'",ADDRESS = 0 : NO ASSEMBLING)"''
 1022IN."ADDRES "N
 1025IFN=0 DIMLL0;G.2999
 1029P.''"    wait"$21
 1030B=N+#100;S=B+#100;F=S+#100
 1032   Z=32;!R=#FFE00120
 1050tDIMLL9;LL4=F;F.J=0TO1;P=F+#100
 1060[LDX@0;LDA@L
 1065:LL0 STA N,X;STA B,X;INX;BNE LL0;LDA C
 1070:LL1TAX;LDA F+1,X;CMP F-1,X;BNE LL7
 1071 LDA F+Z,X;CMP F-Z,X;BNE LL7
 1074 TXA; JMP LL4
 1079:LL7 TXA;LDY@0
 1080:LL2 CLC;ADC R,Y;TAX;LDA F,X;CMP@V;BEQ LL6
 1090LDA@V;STA F,X;STX C;LDX I;TYA;STA S,X; INC I;LDA C
 1100LDX I;CPX K;BNE LL1
 1105 TAX;INC N,X;bne LL4;INC B,X
 1110:LL4 DEC I;LDX I;CPX@#FF; BNE LL5;RTS
 1120:LL5 LDY S,X;TAX;LDA@L;STA F,X
 1130:LL6 TXA;SEC;SBC R,Y;INY;CPY @4;BNE LL2;BEQ LL4
 1150];N.;W=LL7
 2050Q=P;F.J=0TO1;P=Q
 2060[LDX@0;LDA@L
 2065:LL0 STA N,X;STA B,X;INX;BNE LL0;LDA C;JMPLL7
 2070:LL1TAX;LDA F+1,X;CMP F-1,X;BNE LL7
 2071 LDA F+Z,X;CMP F-Z,X;BNE LL7
 2072DEC I;LDA I;STA Y;INC I;JSR W ;JMPLL5
 2079:LL7 TXA;LDY@0
 2080:LL2 CLC;ADC R,Y;TAX;LDA F,X;CMP@V;BEQ LL6
 2090LDA@V;STA F,X;STX C;LDX I;TYA;STA S,X; INC I;LDA C
 2100LDX I;CPX K;BNE LL1
 2105 TAX;INC N,X;bne LL4;INC B,X
 2110:LL4 DEC I;LDX I;CPX@#FF; BNE LL5;RTS
 2120:LL5 LDY S,X;TAX;LDA@L;STA F,X
 2130:LL6 TXA;SEC;SBC R,Y;INY;CPY @4;BNE LL2;BEQ LL4
 2150];N.
 2999P.$6;LL0=256*?18+7;R.

hacker page | counting page