chore: complete day 6

main
sgoudham 2 years ago
parent 9012b7b125
commit faba37ef4b
Signed by: hammy
GPG Key ID: 44E818FD5457EEA4

@ -1,16 +1,35 @@
module Days.Day06 (day06) where
import AOC (Solution (..))
import qualified Data.Text as T
import Data.List
import Data.Maybe
import Data.Text qualified as T
day06 :: Solution
day06 = Solution parseInput part1 part2
parseInput :: T.Text -> a
parseInput = error "parseInput not defined for day 06"
isUnique :: String -> Bool
isUnique str = length (nub str) == length str
part1 :: a -> Int
part1 = error "part1 not defined for day 06"
detectUnique :: Int -> String -> Char -> String
detectUnique n acc x =
if isUnique (take n $ reverse acc)
then acc ++ "0"
else acc ++ [x]
part2 :: a -> Int
part2 = error "part2 not defined for day 06"
parseInput :: T.Text -> String
parseInput = T.unpack
part1 :: String -> Int
part1 input = fromJust $ elemIndex '0' (foldl (detectUnique chars) accumulator iterable)
where
chars = 4
accumulator = take chars input
iterable = drop chars input
part2 :: String -> Int
part2 input = fromJust $ elemIndex '0' (foldl (detectUnique chars) accumulator iterable)
where
chars = 14
accumulator = take chars input
iterable = drop chars input

Loading…
Cancel
Save