Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d007eca
commit 0b281d6
Showing
1 changed file
with
19 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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))))))) |