Program KL BEEST

This program for the Acorn Atom draws all possibleHamilton paths in a gride starting at a certain point.

The program consists of two parts. The second part contains the assembly instructions that generate the core algorithm for finding the Hamilton path. After the secons part is ran, it runs the first part, which contains the interface part of the program. This asks for parameters: length, height x-pos (1..length) and y-pos (1..height) of the starting position, and draws the solutions in low-resolution graphics. The screen is filled with solutions from the bottom of the screen upwards, from left to right. Once a screen is filled, and there are more solutions, the screen is cleared. At the end (before new parameters are asked for) the total number of solutions is printed.

Part 1

Saved as KL BEEST P1 from 8200-8300.
  190G.d
  200bLINK#FFE3;P.$12"T"T''
  201dIN."L"L,H,A,B
  220F.I=0TOL;F.J=1TOH;F?(I+16*J)=32;N.;N.
  230F.I=0TO L+1;F?I=V;F?(I+H*16+16)=V;N.
  240F.I=0TO H+1;F?(I*16)=V;F?(1+L+I*16)=V;N.
  250 ?K=L*H-1;I=#83;?I=0;?C=A+B*16;F?(?C)=V
  255M=L*H-2;A=A*2+1;B=B*2+1
  256O=999;N=O
  260!R=#FFF00110;LINK #A700
  270aIF?I=#FF G.b
  272O=O+1+2*L;IFO>64-2*L O=A;N=N+1+2*H;IFN>48-2*H CLEAR0;N=B
  275PLOT12,O,N
  280F.J=0TOM;G.(290+J?#A600)
  290PLOT1,0,2;G.s
  291PLOT1,2,0;G.s
  292PLOT1,0,-2;G.s
  293PLOT1,-2,0;G.s
  295sN.
  297T=T+1
  300LINKQ;G.a

Part 2

Saved as KL BEEST P2 from A000-A200.
   10C=#80;D=#81;E=#82;I=#83
   20K=#84;R=#85;V=42;L=32
   30F=#A500;S=#A600
   40REMG.d
   50tDIMLL9;F.J=0TO1;P=#A700
   60[:LL0 LDA C
   70:LL1
   73 TAX;LDA F+1,X;CMP F-1,X;BNE LL7
   74 LDA F+16,X;CMP F-16,X;BNE LL7
   75 TXA; JMP LL4
   79:LL7 TXA;LDY@0
   80:LL2 CLC;ADC R,Y;TAX;LDA F,X;CMP@V;BEQ LL6
   90LDA@V;STA F,X;STX C;LDX I;TYA;STA S,X; INC I;LDA C
  100LDX I;CPX K;BNE LL1;STA C;STX D;STY E;RTS
  105:LL3 LDA C;LDX D;LDY E
  110:LL4 DEC I;LDX I;CPX@#FF; BNE LL5;RTS
  120:LL5 LDY S,X;TAX;LDA@L;STA F,X
  130:LL6 TXA;SEC;SBC R,Y;INY;CPY @4;BNE LL2;BEQ LL4
  150];N.;Q=LL3
  200 ?18=#82;G.d

Input file for Acorn Atom Emulator

If you want to run this program on the Acorn Atom Emulator, please load the kl_beest input file

Snap shot of running program


hacker page | Acorn Atom Emulator page