Commit 824f6103 authored by Gilles Coremans's avatar Gilles Coremans
Browse files

Add Day 2 solution

parent 5a7fc161
import Data.List.Split
passwordCorrect input = len >= min && len <= max
where
len = foldl (\cnt c -> if [c] == char
then cnt + 1
else cnt) 0 pw
splitInput = splitOn ": " input
pol = splitInput !! 0
pw = splitInput !! 1
splitPol = splitOneOf "- " pol
min = read $ splitPol !! 0
max = read $ splitPol !! 1
char = splitPol !! 2
main = do input <- getContents
print $ length $ filter passwordCorrect $ lines input
import Data.List.Split
passwordCorrect input = ((pw !! (idx1 - 1)) == char) /= ((pw !! (idx2 - 1)) == char)
where
splitInput = splitOn ": " input
pol = splitInput !! 0
pw = splitInput !! 1
splitPol = splitOneOf "- " pol
idx1 = read $ splitPol !! 0
idx2 = read $ splitPol !! 1
char = head $ splitPol !! 2
main = do input <- getContents
print $ length $ filter passwordCorrect $ lines input
This diff is collapsed.
......@@ -16,7 +16,6 @@ executable 01_1
main-is: 01/1.hs
build-depends: base >=4.14 && <4.15
default-language: Haskell2010
executable 01_2
main-is: 01/2.hs
build-depends: base >=4.14 && <4.15
......@@ -27,3 +26,8 @@ executable 02_1
build-depends: base >=4.14 && <4.15,
split >= 0.2.3.4
default-language: Haskell2010
executable 02_2
main-is: 02/2.hs
build-depends: base >=4.14 && <4.15,
split >= 0.2.3.4
default-language: Haskell2010
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment