Signed-off-by: Amneesh Singh <natto@weirdnatto.in>
This commit is contained in:
2022-12-06 10:56:10 +05:30
parent 38201248c4
commit e636e4c421

25
day6.hs Normal file
View File

@@ -0,0 +1,25 @@
import Data.List (nub)
import Text.ParserCombinators.ReadP
main :: IO ()
main = do
input <- readFile "day6.in"
putStr "Q1: "
print $ q1 input
putStr "Q2: "
print $ q2 input
q1, q2 :: String -> Int
q1 = length . flip parse 4
q2 = length . flip parse 14
parse :: String -> Int -> String
parse a = parse' ("", a)
parse' :: (String, String) -> Int -> String
parse' (a, b) n
| length (nub (drop (length a - n) a)) == n = a
| otherwise =
let (c, cs) = last $ readP_to_S get b
in parse' (a ++ [c], cs) n