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

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 . parse 4
q2 = length . parse 14
parse :: Int -> String -> String
parse n a = parse' n (splitAt n a)
parse' :: Int -> (String, String) -> String
parse' n (a, b)
| length (nub (drop (length a - n) a)) == n = a
| otherwise =
let (c, cs) = last $ readP_to_S get b
in parse' n (a ++ [c], cs)