Skip to content

Commit

Permalink
math.factorials: adding reverse-factorial.
Browse files Browse the repository at this point in the history
  • Loading branch information
mrjbq7 committed Nov 29, 2016
1 parent 54feb5d commit 1e2e2dc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
6 changes: 6 additions & 0 deletions extra/math/factorials/factorials-tests.factor
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,9 @@ IN: math.factorials

{ V{ 3 5 7 29 31 211 2309 2311 } }
[ 10,000 iota [ primorial-prime? ] filter ] unit-test

{ 10 } [ 3628800 reverse-factorial ] unit-test
{ 12 } [ 479001600 reverse-factorial ] unit-test
{ 3 } [ 6 reverse-factorial ] unit-test
{ 1 } [ 1 reverse-factorial ] unit-test
{ f } [ 18 reverse-factorial ] unit-test
3 changes: 3 additions & 0 deletions extra/math/factorials/factorials.factor
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,6 @@ PRIVATE>

: primorial-prime? ( n -- ? )
{ [ prime? ] [ 2 > ] [ [ primorial ] -prime? ] } 1&& ;

: reverse-factorial ( m -- n )
1 1 [ 2over > ] [ 1 + [ * ] keep ] while [ = ] dip and ;

0 comments on commit 1e2e2dc

Please sign in to comment.