module Days.Day06 where

import AOCUtil
import Data.Char
import Data.List
import GHC.Utils.Misc

runA :: IO ()
runA = interactF "data/day06.txt" (show . solve)

runB :: IO ()
runB = interactF "data/day06.txt" (show . solveB)

solve :: String -> Int
solve = fst . head . filter (noDups 4) . zip [4 ..] . filter ((== 4) . length) . map (take 4) . tails

solveB :: String -> Int
solveB = fst . head . filter (noDups 14) . zip [14 ..] . filter ((== 14) . length) . map (take 14) . tails

noDups :: Int -> (Int, [Char]) -> Bool
noDups l (i, ls) = (== l) . length . nub . sort $ ls
