comparison 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
comparison
equal deleted inserted replaced
-1:000000000000 0:bfdcc3820b32
1 (* lab3/digits.p *)
2
3 var q;
4
5 proc search(k, n, avail);
6
7 var d, nn;
8
9 proc avail1(x);
10 begin
11 if x <> d then
12 return avail(x)
13 else
14 return 0
15 end
16 end;
17
18 begin
19 if k = 10 then
20 print n; newline
21 else
22 d := 1;
23 while d < 10 do
24 nn := 10 * n + d;
25 if avail(d) and (nn mod k = 0) then
26 q := search(k+1, nn, avail1)
27 end;
28 d := d+1
29 end
30 end;
31 return 0
32 end;
33
34 proc all(x);
35 begin
36 return 1
37 end;
38
39 begin
40 q := search(1, 0, all)
41 end.
42
43 (*<<
44 381654729
45 >>*)