Racket 8175 bytes
(let loopp((c 2))(cond[(> c(sqrt n))#t][(= 0(modulo n c))#f][#f][else(loopp(+ 1 c))])) Ungolfed:
(define (f n) ; COMMENTS: (let loop ((c 2)) (cond [(> c (sqrt n)) #t] ; if no divisor found till sq root of number, it must be a prime [(= 0 (modulo n c)) #f] ; if divisor found, it is not a prime [else (loop (add1 c))] ; try with next number ))) Following version is longer but more efficient for checking larger numbers since it keeps & uses previously found prime numbers:
(λ(N)(define(p n(o'(2))(c 2))(cond[(> c n)o][(ormap(λ(x)(= 0(modulo c x)))o) (p n o(+ 1 c))][else(p n(cons c o)(+ 1 c))]))(= N(car(p N)))) Ungolfed version:
(p=subfunction to build prime number list till n; o= list of prime numbers found; c=current number being checked)
(define f (λ (N) (define (p n (o '(2)) (c 2)) (cond [(> c n) o] [(ormap (lambda(x) (= 0 (modulo c x))) o) (p n o (add1 c)) ] [else (p n (cons c o) (add1 c))])) (= N (first (p N))))) Testing:
(f 109) (f 10) (f 11) (f 12) (f 13) (f 49) (f 43) (f 57) (f 47) Output:
#t #f #t #f #t #f #t #f #t