Skip to content

Instantly share code, notes, and snippets.

@dagda1
Last active August 29, 2015 14:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dagda1/98caf10b195adda97f27 to your computer and use it in GitHub Desktop.
Save dagda1/98caf10b195adda97f27 to your computer and use it in GitHub Desktop.
(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 "2\n3\n6"
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