-
Notifications
You must be signed in to change notification settings - Fork 3
/
disarium.a60
44 lines (42 loc) · 1.73 KB
/
disarium.a60
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
b̲e̲g̲i̲n̲
c̲o̲m̲m̲e̲n̲t̲ Find some Disarium numbers - numbers whose digit position-power sums
are equal to the number, e.g. 135 = 1^1 + 3^2 + 5^3.
Output: 0 1 2 3 4 5 6 7 8 9 89 135 175 518 598 1306 1676 2427;
i̲n̲t̲e̲g̲e̲r̲ a̲r̲r̲a̲y̲ power [1 : 9, 0 : 9];
i̲n̲t̲e̲g̲e̲r̲ count, powerOfTen, length, n, d;
c̲o̲m̲m̲e̲n̲t̲ compute the nth powers of 0-9;
f̲o̲r̲ d := 0 s̲t̲e̲p̲ 1 u̲n̲t̲i̲l̲ 9 d̲o̲
power[1, d] := d;
f̲o̲r̲ n := 2 s̲t̲e̲p̲ 1 u̲n̲t̲i̲l̲ 8 d̲o̲ b̲e̲g̲i̲n̲
power[n, 0] := 0;
f̲o̲r̲ d := 1 s̲t̲e̲p̲ 1 u̲n̲t̲i̲l̲ 9 d̲o̲
power[n, d] := power[n - 1, d] * d
e̲n̲d̲ n;
c̲o̲m̲m̲e̲n̲t̲ print the first few Disarium numbers;
count := 0;
powerOfTen := 10;
length := 1;
n := -1;
f̲o̲r̲ n := n + 1 w̲h̲i̲l̲e̲ count < 18 d̲o̲ b̲e̲g̲i̲n̲
i̲n̲t̲e̲g̲e̲r̲ v, dps, p;
i̲f̲ n = powerOfTen t̲h̲e̲n̲ b̲e̲g̲i̲n̲
c̲o̲m̲m̲e̲n̲t̲ the number of digfits just increased;
powerOfTen := powerOfTen * 10;
length := length + 1
e̲n̲d̲;
c̲o̲m̲m̲e̲n̲t̲ form the digit power sum;
v := n;
dps := 0;
f̲o̲r̲ p := length s̲t̲e̲p̲ -1 u̲n̲t̲i̲l̲ 1 d̲o̲ b̲e̲g̲i̲n̲
dps := dps + power[p, v - (v ÷ 10 * 10)];
v := v ÷ 10
e̲n̲d̲ p;
i̲f̲ dps = n t̲h̲e̲n̲ b̲e̲g̲i̲n̲
c̲o̲m̲m̲e̲n̲t̲ n is Disarium;
count := count + 1;
SPACE(1);
print(n)
e̲n̲d̲
e̲n̲d̲ n;
NLCR
e̲n̲d̲