Skip to content

Instantly share code, notes, and snippets.

@omegatakuma
Created August 28, 2012 16:25
Show Gist options
  • Save omegatakuma/3499948 to your computer and use it in GitHub Desktop.
Save omegatakuma/3499948 to your computer and use it in GitHub Desktop.
エラトステネスの篩
(define (prime n)
(let loop ((lst (iota (- n 1) 2))(result '()))
(let ((solve (cons (car lst) result)))
(if (< (last lst) (* (car solve) (car solve)))
(append (reverse result) lst)
(loop (remove (^(x)(zero? (remainder x (car lst)))) lst) solve)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment