RosettaCodeData/Task/Smith-numbers/XPL0/smith-numbers.xpl0
2023-07-01 13:44:08 -04:00

32 lines
663 B
Text

func SumDigits(N); \Return sum of digits in N
int N, S;
[S:= 0;
repeat N:= N/10;
S:= S+rem(0);
until N=0;
return S;
];
func SumFactor(N); \Return sum of digits of factors of N
int N0, N, F, S;
[N:= N0; F:= 2; S:= 0;
repeat if rem(N/F) = 0 then \found a factor
[S:= S + SumDigits(F);
N:= N/F;
]
else F:= F+1;
until F > N;
if F = N0 then return 0; \is prime
return S;
];
int C, N;
[C:= 0;
Format(5, 0);
for N:= 0 to 10_000-1 do
if SumDigits(N) = SumFactor(N) then
[RlOut(0, float(N));
C:= C+1;
if rem(C/20) = 0 then CrLf(0);
];
]