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
;; P39 (*) A list of prime numbers. | |
;; Given a range of integers by its lower and upper limit, construct a list of all prime numbers in that range. | |
#lang racket | |
(provide (all-defined-out)) | |
(require srfi/1) | |
(define (eratosthenes n) | |
(let loop ((lst (iota n 3)) (acc '(2))) | |
(let ((i (car acc))) | |
(if (< (apply max lst) (expt i 2)) | |
(append (reverse acc) lst) | |
(let ((lst (remove (lambda (x) | |
(zero? (modulo x i))) | |
lst))) | |
(loop (cdr lst) (cons (car lst) acc))))))) | |
(define (p39 m n) | |
(remove (lambda (x) | |
(< x m)) | |
(eratosthenes n))) |
0 件のコメント:
コメントを投稿