RosettaCodeData/Task/Fermat-numbers/Factor/fermat-numbers.factor

16 lines
477 B
Factor
Raw Permalink Normal View History

2023-07-01 11:58:00 -04:00
USING: formatting io kernel lists lists.lazy math math.functions
math.primes.factors sequences ;
: lfermats ( -- list )
0 lfrom [ [ 1 2 2 ] dip ^ ^ + ] lmap-lazy ;
CHAR: ₀ 10 lfermats ltake list>array [
"First 10 Fermat numbers:" print
[ dupd "F%c = %d\n" printf 1 + ] each drop nl
] [
"Factors of first few Fermat numbers:" print [
dupd factors dup length 1 = " (prime)" "" ?
"Factors of F%c: %[%d, %]%s\n" printf 1 +
] each drop
] 2bi