Last active
August 29, 2015 14:14
-
-
Save dagda1/c0165842dce687c6ab16 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns scratch.core | |
(require [clojure.string :as str :only (split-lines join)])) | |
(defn sieve [s] | |
(cons (first s) | |
(lazy-seq (sieve (filter #(not= 0 (mod % (first s))) | |
(rest s)))))) | |
(defn nth-prime [n] | |
(last (take n (sieve (cons 2 (iterate (partial + 2) 3)))))) | |
(defn print-primes [[x & xs]] | |
(prn x) | |
(if (seq xs) | |
(recur xs))) | |
(let [input (slurp *in*) | |
ranks (rest (map read-string (str/split-lines input))) | |
primes (map nth-prime ranks)] | |
(print-primes primes)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment