-
Notifications
You must be signed in to change notification settings - Fork 1
/
p52.bas
63 lines (57 loc) · 755 Bytes
/
p52.bas
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
REM note: First digit must be 1 for 6*n
REM TO be same power
power&=10
lower&=-1
success%=0
PRINT TIME$
WHILE success%=0
lower&=lower&+1
IF lower&=power& THEN
lower&=0
power&=power&*10&
END IF
n&=power&+lower&
GOSUB check
WEND
PRINT n&
PRINT TIME$
END
check:
m&=n&
GOSUB sortdigits
b&=m&
success%=1
FOR q&=2 TO 6
m&=(q&*n&)
GOSUB sortdigits
IF m&<>b& THEN
success%=0
RETURN
END IF
NEXT
RETURN
countdigits:
FOR i%=0 TO 9
dc%(i%)=0
NEXT
WHILE m&>0
REM MOD doesn't work with long ints!
t&=m&\10&
r&=m&-(10&*t&)
dc%(r&)=dc%(r&)+1
m&=t&
WEND
RETURN
sorteddigits:
m&=0
FOR k%=0 TO 9
i&=9-k%
FOR j%=1 TO dc%(i&)
m&=i&+(10&*m&)
NEXT
NEXT
RETURN
sortdigits:
GOSUB countdigits
GOSUB sorteddigits
RETURN