math.primes.twins: calculating twin primes.
parent
7a15418cf4
commit
449814a387
|
@ -0,0 +1,13 @@
|
||||||
|
! Copyright (C) 2012 John Benediktsson
|
||||||
|
! See http://factorcode.org/license.txt for BSD license
|
||||||
|
|
||||||
|
USING: tools.test ;
|
||||||
|
|
||||||
|
IN: math.primes.twins
|
||||||
|
|
||||||
|
{ { } } [ 3 twin-primes-upto ] unit-test
|
||||||
|
{ { V{ 3 5 } V{ 5 7 } V{ 11 13 } } } [ 13 twin-primes-upto ] unit-test
|
||||||
|
|
||||||
|
{ t } [ 3 5 twin-primes? ] unit-test
|
||||||
|
{ f } [ 2 4 twin-primes? ] unit-test
|
||||||
|
{ f } [ 3 7 twin-primes? ] unit-test
|
|
@ -0,0 +1,13 @@
|
||||||
|
! Copyright (C) 2012 John Benediktsson
|
||||||
|
! See http://factorcode.org/license.txt for BSD license
|
||||||
|
|
||||||
|
USING: combinators.short-circuit grouping kernel math
|
||||||
|
math.primes sequences ;
|
||||||
|
|
||||||
|
IN: math.primes.twins
|
||||||
|
|
||||||
|
: twin-primes-upto ( n -- seq )
|
||||||
|
primes-upto 2 <clumps> [ first2 - abs 2 = ] filter ;
|
||||||
|
|
||||||
|
: twin-primes? ( x y -- ? )
|
||||||
|
{ [ - abs 2 = ] [ nip prime? ] [ drop prime? ] } 2&& ;
|
Loading…
Reference in New Issue