Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,24 @@
import "/math" for Int
import "/fmt" for Fmt
import "/seq" for Lst
var sumDigits = Fn.new { |n|
var sum = 0
while (n > 0) {
sum = sum + n%10
n = (n/10).floor
}
return sum
}
var smiths = []
System.print("The Smith numbers below 10,000 are:")
for (i in 2...10000) {
if (!Int.isPrime(i)) {
var thisSum = sumDigits.call(i)
var factors = Int.primeFactors(i)
var factSum = factors.reduce(0) { |acc, f| acc + sumDigits.call(f) }
if (thisSum == factSum) smiths.add(i)
}
}
for (chunk in Lst.chunks(smiths, 16)) Fmt.print("$4d", chunk)