Merge branch 'master' of http://factorcode.org/git/factor
						commit
						03267aa42c
					
				|  | @ -11,7 +11,11 @@ HELP: prime? | ||||||
| { $values { "n" "an integer" } { "?" "a boolean" } } | { $values { "n" "an integer" } { "?" "a boolean" } } | ||||||
| { $description "Test if an integer is a prime number." } ; | { $description "Test if an integer is a prime number." } ; | ||||||
| 
 | 
 | ||||||
| { primes-upto primes-between } related-words | { nprimes primes-upto primes-between } related-words | ||||||
|  | 
 | ||||||
|  | HELP: nprimes | ||||||
|  | { $values { "n" "a non-negative integer" } { "seq" "a sequence" } } | ||||||
|  | { $description "Return a sequence containing the " { $snippet "n" } " first primes numbers." } ; | ||||||
| 
 | 
 | ||||||
| HELP: primes-upto | HELP: primes-upto | ||||||
| { $values { "n" "an integer" } { "seq" "a sequence" } } | { $values { "n" "an integer" } { "seq" "a sequence" } } | ||||||
|  |  | ||||||
|  | @ -8,6 +8,11 @@ IN: math.primes.tests | ||||||
| { { 2 } } [ 2 primes-upto >array ] unit-test | { { 2 } } [ 2 primes-upto >array ] unit-test | ||||||
| { { } } [ 1 primes-upto >array ] unit-test | { { } } [ 1 primes-upto >array ] unit-test | ||||||
| { { 999983 1000003 } } [ 999982 1000010 primes-between >array ] unit-test | { { 999983 1000003 } } [ 999982 1000010 primes-between >array ] unit-test | ||||||
|  | { { } } [ 0 nprimes ] unit-test | ||||||
|  | { { 2 3 5 7 } } [ 4 nprimes ] unit-test | ||||||
|  | { t } [ 1000 nprimes [ prime? ] all? ] unit-test | ||||||
|  | { 1000 } [ 1000 nprimes length ] unit-test | ||||||
|  | { 1000 } [ 1000 nprimes last primes-upto length ] unit-test | ||||||
| 
 | 
 | ||||||
| { { 4999963 4999999 5000011 5000077 5000081 } } | { { 4999963 4999999 5000011 5000077 5000081 } } | ||||||
| [ 4999962 5000082 primes-between >array ] unit-test | [ 4999962 5000082 primes-between >array ] unit-test | ||||||
|  |  | ||||||
|  | @ -1,6 +1,6 @@ | ||||||
| ! Copyright (C) 2007-2009 Samuel Tardieu. | ! Copyright (C) 2007-2009 Samuel Tardieu. | ||||||
| ! See http://factorcode.org/license.txt for BSD license. | ! See http://factorcode.org/license.txt for BSD license. | ||||||
| USING: combinators combinators.short-circuit fry kernel math | USING: combinators combinators.short-circuit fry kernel make math | ||||||
| math.bitwise math.functions math.order math.primes.erato | math.bitwise math.functions math.order math.primes.erato | ||||||
| math.primes.erato.private math.primes.miller-rabin math.ranges | math.primes.erato.private math.primes.miller-rabin math.ranges | ||||||
| literals random sequences sets vectors ; | literals random sequences sets vectors ; | ||||||
|  | @ -66,6 +66,8 @@ PRIVATE> | ||||||
| 
 | 
 | ||||||
| : primes-upto ( n -- seq ) 2 swap primes-between ; | : primes-upto ( n -- seq ) 2 swap primes-between ; | ||||||
| 
 | 
 | ||||||
|  | : nprimes ( n -- seq ) [ 2 swap [ dup , next-prime ] times ] { } make nip ; | ||||||
|  | 
 | ||||||
| : coprime? ( a b -- ? ) gcd nip 1 = ; foldable | : coprime? ( a b -- ? ) gcd nip 1 = ; foldable | ||||||
| 
 | 
 | ||||||
| : random-prime ( numbits -- p ) | : random-prime ( numbits -- p ) | ||||||
|  |  | ||||||
|  | @ -49,7 +49,7 @@ xml.writer xmode.highlight ; %> | ||||||
| "resource:extra/websites/factorcode/examples.txt" utf8 file-lines | "resource:extra/websites/factorcode/examples.txt" utf8 file-lines | ||||||
| { "----" } split random | { "----" } split random | ||||||
| "factor" [ highlight-lines ] with-html-writer | "factor" [ highlight-lines ] with-html-writer | ||||||
| [ xml>string write ] each | [ xml>string write-html ] each | ||||||
| %></pre> | %></pre> | ||||||
| 
 | 
 | ||||||
| <p>See the <a href="http://concatenative.org/wiki/view/Factor/Examples">example programs</a> page on the wiki for more.</p> | <p>See the <a href="http://concatenative.org/wiki/view/Factor/Examples">example programs</a> page on the wiki for more.</p> | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue