Skip to content

Instantly share code, notes, and snippets.

@mjgpy3
Created December 2, 2020 11:11
Show Gist options
  • Select an option

  • Save mjgpy3/dd80460e15e7482fcd1d82fca93f14f4 to your computer and use it in GitHub Desktop.

Select an option

Save mjgpy3/dd80460e15e7482fcd1d82fca93f14f4 to your computer and use it in GitHub Desktop.
aoc-2020-day2.hs
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
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