Merge branch 'for-slava' of git://git.rfc1149.net/factor

db4
Daniel Ehrenberg 2009-02-06 14:36:37 -06:00
commit 9890ee27f4
2 changed files with 6 additions and 1 deletions

View File

@ -6,3 +6,4 @@ USING: math.primes.factors tools.test ;
{ { 999983 1000003 } } [ 999969000187000867 unique-factors ] unit-test
{ 999967000236000612 } [ 999969000187000867 totient ] unit-test
{ 0 } [ 1 totient ] unit-test
{ { 425612003 } } [ 425612003 factors ] unit-test

View File

@ -16,7 +16,11 @@ IN: math.primes.factors
PRIVATE>
: group-factors ( n -- seq )
[ 2 [ over 1 > ] [ write-factor next-prime ] [ ] while 2drop ] { } make ;
[
2
[ 2dup sq < ] [ write-factor next-prime ] [ ] until
drop dup 2 < [ drop ] [ 1 2array , ] if
] { } make ;
: unique-factors ( n -- seq ) group-factors [ first ] map ;