Skip to content

Commit

Permalink
A
Browse files Browse the repository at this point in the history
  • Loading branch information
BNAndras committed Oct 5, 2024
1 parent 4a4dffa commit 3fe879b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
7 changes: 4 additions & 3 deletions exercises/practice/nth-prime/.meta/example.rkt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#lang racket

(provide nth-prime)

(define/contract (nth-prime number)
(-> exact-positive-integer? exact-positive-integer?)
(let loop ([candidate 2]
Expand All @@ -13,8 +15,7 @@
[else (loop (add1 candidate)
count)])))

(define/contract (prime? number)
(-> natural? boolean?)
(define (prime? number)
(cond
[(zero? number) #f]
[(= number 1) #f]
Expand All @@ -25,4 +26,4 @@
(cond
[(> (expt factor 2) number) #t]
[(zero? (remainder number factor)) #f]
[else (loop (+ factor 2))]))]))
[else (loop (+ factor 2))]))]))
1 change: 1 addition & 0 deletions exercises/practice/nth-prime/nth-prime-test.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@
104743)
(test-exn "there is no zeroth prime"
exn:fail? (lambda () (nth-prime 0)))))

(run-tests suite))

0 comments on commit 3fe879b

Please sign in to comment.