June 2018 Update
This commit is contained in:
parent
ba8067c3b7
commit
22f33d4004
5278 changed files with 84726 additions and 14379 deletions
26
Task/Left-factorials/Factor/left-factorials.factor
Normal file
26
Task/Left-factorials/Factor/left-factorials.factor
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
USING: formatting fry io kernel math math.factorials
|
||||
math.functions math.parser math.ranges sequences ;
|
||||
IN: rosetta-code.left-factorials
|
||||
|
||||
: left-factorial ( n -- m ) iota [ n! ] map-sum ;
|
||||
|
||||
: print-left-factorials ( seq quot -- )
|
||||
'[
|
||||
dup left-factorial @
|
||||
[ number>string "!" prepend ] dip
|
||||
"%6s %-6d\n" printf
|
||||
] each nl ; inline
|
||||
|
||||
: digit-count ( n -- count ) log10 floor >integer 1 + ;
|
||||
|
||||
: part1 ( -- ) 11 iota [ ] print-left-factorials ;
|
||||
|
||||
: part2 ( -- ) 20 110 10 <range> [ ] print-left-factorials ;
|
||||
|
||||
: part3 ( -- ) "Number of digits for" print
|
||||
1,000 10,000 1,000 <range>
|
||||
[ digit-count ] print-left-factorials ;
|
||||
|
||||
: main ( -- ) part1 part2 part3 ;
|
||||
|
||||
MAIN: main
|
||||
Loading…
Add table
Add a link
Reference in a new issue