annotate lab3/digits.p @ 0:bfdcc3820b32

Basis
author Mike Spivey <mike@cs.ox.ac.uk>
date Thu, 05 Oct 2017 08:04:15 +0100
parents
children
rev   line source
mike@0 1 (* lab3/digits.p *)
mike@0 2
mike@0 3 var q;
mike@0 4
mike@0 5 proc search(k, n, avail);
mike@0 6
mike@0 7 var d, nn;
mike@0 8
mike@0 9 proc avail1(x);
mike@0 10 begin
mike@0 11 if x <> d then
mike@0 12 return avail(x)
mike@0 13 else
mike@0 14 return 0
mike@0 15 end
mike@0 16 end;
mike@0 17
mike@0 18 begin
mike@0 19 if k = 10 then
mike@0 20 print n; newline
mike@0 21 else
mike@0 22 d := 1;
mike@0 23 while d < 10 do
mike@0 24 nn := 10 * n + d;
mike@0 25 if avail(d) and (nn mod k = 0) then
mike@0 26 q := search(k+1, nn, avail1)
mike@0 27 end;
mike@0 28 d := d+1
mike@0 29 end
mike@0 30 end;
mike@0 31 return 0
mike@0 32 end;
mike@0 33
mike@0 34 proc all(x);
mike@0 35 begin
mike@0 36 return 1
mike@0 37 end;
mike@0 38
mike@0 39 begin
mike@0 40 q := search(1, 0, all)
mike@0 41 end.
mike@0 42
mike@0 43 (*<<
mike@0 44 381654729
mike@0 45 >>*)