Factorial primes: Difference between revisions
Content added Content deleted
Thundergnat (talk | contribs) m (Undo revision 338726 by Dr-neptune (talk) Erroneously overwrote Python) Tag: Undo |
Thundergnat (talk | contribs) m (Undo revision 338725 by Dr-neptune (talk) Erroneously overwrote Python) Tag: Undo |
||
Line 726: | Line 726: | ||
=={{header|Racket}}== |
=={{header|Racket}}== |
||
<syntaxhighlight lang="racket"> |
<syntaxhighlight lang="racket"> |
||
#lang racket |
#lang racket |
||
(require |
(require (only-in math/number-theory prime?)) |
||
(define (factorial-boundary-stream) |
(define (factorial-boundary-stream) |
||
Line 753: | Line 752: | ||
(let ([fact (format-large-number fact)]) |
(let ([fact (format-large-number fact)]) |
||
(displayln (format "~a! ~a 1 = ~a" n op fact))))) |
(displayln (format "~a! ~a 1 = ~a" n op fact))))) |
||
(define (prime? n) |
|||
(if (zero? (mpz_probab_prime_p (mpz n) 10)) #f #t)) |
|||
(for ([i (in-stream |
(for ([i (in-stream |
||
(stream-take |
(stream-take |
||
(stream-filter (λ (l) (prime? (third l))) (factorial-boundary-stream)) |
(stream-filter (λ (l) (prime? (third l))) (factorial-boundary-stream)) 14))] |
||
[n (in-naturals 1)]) |
[n (in-naturals 1)]) |
||
(begin |
(begin |
||
(display (format "~a:\t" n)) |
(display (format "~a:\t" n)) |
||
(factorial-printer i))) |
(factorial-printer i))) |
||
;; time output of above code: 2.46 seconds |
|||
</syntaxhighlight> |
</syntaxhighlight> |
||
Line 792: | Line 786: | ||
22: 166! - 1 = 9003691705778437366...9999999999999999999 (total 298 digits) |
22: 166! - 1 = 9003691705778437366...9999999999999999999 (total 298 digits) |
||
23: 320! + 1 = 2116103347219252482...0000000000000000001 (total 665 digits) |
23: 320! + 1 = 2116103347219252482...0000000000000000001 (total 665 digits) |
||
24: |
24: 324! - 1 = 2288997460179102321...9999999999999999999 (total 675 digits) |
||
25: |
25: 340! + 1 = 5100864472103711080...0000000000000000001 (total 715 digits) |
||
26: |
26: 379! - 1 = 2484030746096470705...9999999999999999999 (total 815 digits) |
||
27: |
27: 399! + 1 = 1600863071165597381...0000000000000000001 (total 867 digits) |
||
28: |
28: 427! + 1 = 2906347176960734841...0000000000000000001 (total 940 digits) |
||
29: |
29: 469! - 1 = 6771809666814951090...9999999999999999999 (total 1051 digits) |
||
</pre> |
|||
30: 546! - 1 = 1413020092614183254...9999999999999999999 (total 1260 digits) |
|||
cpu time: 2440 real time: 2440 gc time: 3</pre> |
|||
=={{header|Raku}}== |
=={{header|Raku}}== |