RosettaCodeData/Task/Bell-numbers/Factor/bell-numbers-1.factor

14 lines
430 B
Factor
Raw Permalink Normal View History

2023-07-01 11:58:00 -04:00
USING: formatting io kernel math math.matrices sequences vectors ;
: next-row ( prev -- next )
[ 1 1vector ]
[ dup last [ + ] accumulate swap suffix! ] if-empty ;
: aitken ( n -- seq )
V{ } clone swap [ next-row dup ] replicate nip ;
0 50 aitken col [ 15 head ] [ last ] bi
"First 15 Bell numbers:\n%[%d, %]\n\n50th: %d\n\n" printf
"First 10 rows of the Bell triangle:" print
10 aitken [ "%[%d, %]\n" printf ] each