Knuth's Algol Program
procedure count (n, d); integer n; integer array d; 
begin comment d[i] is set to the number of topological sequences of index i, for 0 <= i <= n;
integer array cc[0:n, 0:n]; comment number of columns in given plane, row; 
integer array rr[0:n]; comment number of rows in given plane;
integer pp; comment number of planes;
integer k; comment recursion depth;
integer array row[0:n]; comment row of given move;
integer array plane[0:n];comment plane of given move;
integer array index[0:n]; comment partial sum for index; 
integer p, r, c; comment current plane, row, column; 
integer t; comment temporary storage; 
for p := 0 step 1 until n do 
begin rr[p]:=0; 
for r := 0 step i until n do cc[p, r] :=0 end; 
for k :=1 step 1 until n do d[k] :=0; 
pp := k := index[0]:= plane[0] := row[0]:= 0; d[0]:= 1; 
up: k:= k + 1; p:= pp; r :=0; 
try: c := cc[p, r]; 
if p > 0 then if cc[p- 1, r] <= c then go to again; 
if r > 0 then if cc[p, r - 1] <= c then go to again; 
if p < plane[k - 1] then go to less; 
if p = plane[k - 1] then if r < row[k - 1] then go to less; 
t := index[k - 1]; go to move; 
less: t := index[k - 1] + k - 1; 
if k + t > n then go to nope; 
move: begin comment We have now decided to choose the point (p, r, c) as the kth element of the topological sequence; end; 
index[k] := t; 
if p + r> 0 then d[k + t] := d[k + t] + 1; 
if t + k >=n then go to again; 
if r + c= 0 then pp := pp + 1; 
if c = 0 then rr[p]:= rr[p] + 1; 
cc[p, r]:= c + 1; 
plane[k] := p; row[k] := r; go to up; 
again: if r > 0 then begin r := r - 1; go to try end; 
if p > 0 then begin p :=p- 1; r := rr[p]; go to try end; 
nope: k := k - 1; 
if k > 0 then begin p := plane[k]; r:=row[k]; 
                            c := cc[p, r] - 1; cc[p, r] := c; 
if c = 0 then rr[p] := rr[p]- 1; 
if r+ c =0 then pp :=pp- 1; 
go to again end; 
end count.

Algol60 to C converter: Marst

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License