Skip to content

Instantly share code, notes, and snippets.

@dbyrne
Created March 19, 2011 18:39
Show Gist options
  • Save dbyrne/877698 to your computer and use it in GitHub Desktop.
Save dbyrne/877698 to your computer and use it in GitHub Desktop.
Project Euler #24 - Clojure
(def digits (sorted-set 0 1 2 3 4 5 6 7 8 9))
(defn nextLex [substr digits]
(let [lex (apply str substr digits)]
(lazy-cat
[lex]
(loop [s (vec lex)
d (sorted-set)]
(let [i (- (int (peek s)) 48)
d (conj d i)]
(if (== (last d) i)
(recur (pop s) d)
(let [z (first (drop-while #(<= % i) d))]
(nextLex (apply str (conj (pop s) (char (+ z 48)))) (disj d z)))))))))
(first (drop 999999 (nextLex "" digits)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment