Skip to content

Instantly share code, notes, and snippets.

@dagda1
Created February 5, 2015 21:12
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/1f765e0fcade3193f1e0 to your computer and use it in GitHub Desktop.
Save dagda1/1f765e0fcade3193f1e0 to your computer and use it in GitHub Desktop.
(require [clojure.string :as str :only (split-lines join)]))
(def t "2\n3\n6")
(defn work [input]
(let [lines (map read-string (str/split-lines input))]
(letfn [(is-prime? [n]
(empty? (filter #(= 0 (mod n %)) (range 2 n))))
(parse-primes [[x & xs]]
(prn (last (take x (filter #(is-prime? %) (iterate inc 2)))))
(if (seq xs)
(recur xs)))]
(parse-primes (rest lines)))))
(work t)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment