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 &nbsp; '''1''' &nbsp; is both &nbsp; 0 &nbsp; and &nbsp; 1, &nbsp; your function should return &nbsp; '''0''' &nbsp; 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$:" print
5 $ log10 >integer 1 + . nl
 
Line 93 ⟶ 101:
0 1 2 9 262144
 
Number of digits in $5$:
183231
 
rf(1) = 10
rf(2) = 2
rf(6) = 3
1,827

edits