23 lines
374 B
Text
23 lines
374 B
Text
/** Solver for the Rosetta Code problem Smith numbers
|
|
|
|
https://rosettacode.org/wiki/Smith_numbers
|
|
*/
|
|
for n = 2 to 10000
|
|
if isSmith[n]
|
|
print["$n "]
|
|
|
|
println[]
|
|
|
|
isSmith[n] :=
|
|
{
|
|
if isPrime[n]
|
|
return false
|
|
sn = sumDigits[n]
|
|
ss = 0
|
|
for [b,p] = factor[n]
|
|
ss = ss + sumDigits[b] * p
|
|
|
|
return sn == ss
|
|
}
|
|
|
|
sumDigits[n] := sum[integerDigits[n]]
|