Skip to content

Commit

Permalink
Programmatically solved 79.
Browse files Browse the repository at this point in the history
  • Loading branch information
darrenaustin committed Oct 6, 2011
1 parent d007eca commit 0b281d6
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/dma/euler/p079.clj
@@ -0,0 +1,19 @@
(ns dma.euler.p079
(:use dma.euler.numeric)
(:use clojure.set))

;; Solved this on paper, but thought it would be fun to programmically solve it.

(defn in-front-map [keys]
(loop [keys keys in-front {}]
(if (seq keys)
(recur (rest keys) (assoc in-front (first keys) (set (rest keys))))
in-front)))

(defn solution {:answer 73162890} []
(let [logins (map #(digits (read-string %)) (.split (slurp "data/keylog.txt") "\n"))]
(number
(reverse
(map first (sort-by #(count (second %))
(reduce #(merge-with union % (in-front-map %2))
{} logins)))))))

0 comments on commit 0b281d6

Please sign in to comment.