# Project Euler Problem 79

Problem 79 asks us to crack a primitive security ‘feature’ asked by some (hypothetical) banks. Given 50 successful login attempts using an ordered subset of the digits from a passcode, we need to find what the original passcode was.

The algorithm to do this turns out to be pretty simple:

1. Assume that there are no repeated digits. This makes the problem much easier.
2. Since the given numbers [a,b,c] are ordered, each login attempt tells us that a is before b, a is before c, and b is before c.
3. Collect these orderings into sets – one set for each number.
4. Sort the digits so that the ordered dependencies are all satisfied.

In Clojure, that looks like this:

(defn conj-in
"Conjs v into a set under key k of map m."
[m k v]
(assoc m k (conj (or (m k) #{}) v)))

(defn euler-79 []
You may notice that this algorithm slightly cheats because of the strong assumption #1 and the fact that the data uniquely determines the possible password. Given less perfect data, several combinations of letters might be possible for which that this algorithm cannot account. Specifically,  (sort-by #(count (val %))) will not yield the correct answer except in these specific circumstances.