Given a list of passwords in the following shape;
1-3 a: abcde
'a-'b 'c: 'd
check if 'c
is represented between 'a
and 'b
times in 'd
.
This seems fairly straight forward. I should be able to fold over the list, checking for each value wether its valid and if so, increment. We need to do some splitting / string mangling, that should be interesting.
So what seemed quite straight forward turned out to be a bit of a pain. I tried doing some string splitting magic, and tried doing some regex (the latter required some packages), but I eventually opted to go for 'parsec' and got that to work reasonably well...
Going from a to be was reasonably straight forward, with the caveat that the min / max values for the passwords could be out of bounds. So we needed a safe lookup for elements in a list at index x.
Parser Combinators are awesome, and a lot less weird to use than I would imagine, Haskell's do notation makes it really nice and simple to make this happen. All-in-all, I would have to say this was a real struggle. I found some stuff on Hoogle, but trying to import it was a pain, and since I'm relying on this experts guy simple make setup, I couldn't go 'cabal install x' or 'stack do y'... Might have to rethink that one.