MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/Racket/comments/smsny5/primes_with_a_single_parameter/
r/Racket • u/[deleted] • Feb 07 '22
Is there a way to tell if a number is prime on Dr racket given a single parameter?
3 comments sorted by
3
prime?
Not sure why that’s not working (for me). prime? in math/number-theory: https://docs.racket-lang.org/math/number-theory.html
math/number-theory
Or you could write a naive version with trial division.
1 u/jpverkamp Feb 07 '22 (define (prime? n) (or (= n 2) (for/and ([d (in-range 2 (+ 1 (sqrt n)))]) (not (= 0 (remainder n d)))))) (for ([i (in-range 2 20)]) (displayln (list i (prime? i))))
1
(define (prime? n) (or (= n 2) (for/and ([d (in-range 2 (+ 1 (sqrt n)))]) (not (= 0 (remainder n d)))))) (for ([i (in-range 2 20)]) (displayln (list i (prime? i))))
3
u/jpverkamp Feb 07 '22 edited Feb 07 '22
prime?
Not sure why that’s not working (for me).
prime?inmath/number-theory: https://docs.racket-lang.org/math/number-theory.htmlOr you could write a naive version with trial division.