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

48 lines
863 B
Text
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

F factors(=n)
[Int] rt
V f = 2
I n == 1
rt.append(1)
E
L
I 0 == (n % f)
rt.append(f)
n I/= f
I n == 1
R rt
E
f++
R rt
F sum_digits(=n)
V sum = 0
L n > 0
V m = n % 10
sum += m
n -= m
n I/= 10
R sum
F add_all_digits(lst)
V sum = 0
L(i) 0 .< lst.len
sum += sum_digits(lst[i])
R sum
F list_smith_numbers(cnt)
[Int] r
L(i) 4 .< cnt
V fac = factors(i)
I fac.len > 1
I sum_digits(i) == add_all_digits(fac)
r.append(i)
R r
V sn = list_smith_numbers(10'000)
print(Count of Smith Numbers below 10k: sn.len)
print()
print(First 15 Smith Numbers:)
print_elements(sn[0.<15])
print()
print(Last 12 Smith Numbers below 10000:)
print_elements(sn[(len)-12..])