Special factorials: Difference between revisions
Make note about rf(1); update Factor program and output accordingly.
(→{{header|Wren}}: More efficient.) |
(Make note about rf(1); update Factor program and output accordingly.) |
||
Line 34:
* Show rf(119). The result should be undefined.
<br />
;Notes
: Since the factorial inverse of '''1''' is both 0 and 1, your function should return '''0''' in this case since it is normal to use the first match found in a series.
<br />
;See also
* [[Factorial]]
Line 48 ⟶ 53:
<lang factor>USING: formatting io kernel math math.factorials math.functions
math.parser math.ranges prettyprint sequences sequences.extras ;
IN: rosetta-code.special-factorials
: sf ( n -- m ) [1..b] [ n! ] map-product ;
Line 55 ⟶ 61:
: $ ( n -- m ) [1..b] [ ] [ swap ^ ] map-reduce ;
: (rf) ( n -- m )
[ 1 1 ] dip [ dup reach > ]
[ [ 1 + [ * ] keep ] dip ] while swapd = swap and ;
: rf ( n -- m ) dup 1 = [ drop 0 ] [ (rf) ] if ;
: .show ( n quot -- )
Line 74 ⟶ 82:
5 [ $ ] .show nl
"Number of digits in
5 $ log10 >integer 1 + . nl
Line 93 ⟶ 101:
0 1 2 9 262144
Number of digits in
183231
rf(1) =
rf(2) = 2
rf(6) = 3
|