~jojo/Carth

ref: b144030d9a5428cf4472e3c55258d8983c20982d Carth/test/tests/good/sieve-of-eratosthenes.carth -rw-r--r-- 314 bytes
b144030dJoJo Make main IO Unit, i.e. (Fun RealWorld [Unit RealWorld]) 1 year, 2 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
;; 7927

(import std)

(define (main real-world)
  (let1 primes (sieve (range-from 2))
    (display (show-int (unwrap! (iter/nth (cast 1000) primes))) real-world)))

(define (sieve xs)
  (Iter (fun (_)
          (let1 [x xs'] (next! xs)
            (Some [x (sieve (filter (<o not (flip divisible? x)) xs'))])))))