Created
December 2, 2020 11:11
-
-
Save mjgpy3/dd80460e15e7482fcd1d82fca93f14f4 to your computer and use it in GitHub Desktop.
aoc-2020-day2.hs
This file contains hidden or 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
| module Main where | |
| input = | |
| [ | |
| -- Use vim `s/...` to make input look like this | |
| (9, 10, 'm', "mmmmnxmmmwm"), | |
| -- ... | |
| ] | |
| isValidPassword (min, max, needle, hay) = | |
| let | |
| occurs = length $ filter (== needle) hay | |
| in | |
| min <= occurs && occurs <= max | |
| main = print $ length $ filter isValidPassword input |
This file contains hidden or 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
| module Main where | |
| import Data.Bits (xor) | |
| input = | |
| [ | |
| -- Use vim `s/...` to make input look like this | |
| (9, 10, 'm', "mmmmnxmmmwm"), | |
| -- ... | |
| ] | |
| isValidPassword (a, b, needle, hay) = | |
| needleAt1 a `xor` needleAt1 b | |
| where | |
| needleAt1 = (==) needle . (hay !!) . subtract 1 | |
| main = print $ length $ filter isValidPassword input |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment