Last active
August 29, 2015 14:16
-
-
Save rinfz/e1dadb81095d459e30c3 to your computer and use it in GitHub Desktop.
sexy primes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(import srfi-1) | |
(require-extension srfi-1) | |
(define (is-prime? n) | |
(cond | |
((<= n 3) (>= n 2)) | |
((or (= (modulo n 2) 0) (= (modulo n 3) 0)) #f) | |
(else (do ((i 5 (+ i 6))) ((> i (+ (sqrt n) 1))) | |
(if (or (= (modulo n i) 0) (= (modulo n (+ i 2)) 0)) | |
#f)) #t))) | |
(define (prime-gap n g) | |
(if (and (is-prime? n) (is-prime? (- n g))) | |
(list (- n g) n) | |
#f)) | |
(define proc (lambda vars | |
(length vars))) | |
(define (argcheck args default) | |
(define len (length args)) | |
(cond | |
((= len 2) (string->number (list-ref args 1))) | |
((= len 4) (string->number (list-ref args 3))) | |
(else default))) | |
(define (main args) | |
(define gap (argcheck (args) 6)) | |
(display (remove (lambda (x) (not x)) (map (lambda (x) (prime-gap x gap)) (iota (* 1 1000) 1)))) | |
(newline) | |
(exit)) | |
(if (not (equal? (program-name) "csi")) | |
(main argv)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment