~jojo/Carth

ref: 2ffd86d155a095c6a5293cc68fe7ac02daed235e Carth/test/tests/good/sieve-of-eratosthenes.carth -rw-r--r-- 290 bytes
2ffd86d1JoJo Fix partitionWith reversing lists. Caused def order issue in genInit 1 year, 1 month ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
;; 7927

(import std)

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

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