chore: complete day 6
parent
9012b7b125
commit
faba37ef4b
@ -1,16 +1,35 @@
|
|||||||
module Days.Day06 (day06) where
|
module Days.Day06 (day06) where
|
||||||
|
|
||||||
import AOC (Solution (..))
|
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
|
||||||
day06 = Solution parseInput part1 part2
|
day06 = Solution parseInput part1 part2
|
||||||
|
|
||||||
parseInput :: T.Text -> a
|
isUnique :: String -> Bool
|
||||||
parseInput = error "parseInput not defined for day 06"
|
isUnique str = length (nub str) == length str
|
||||||
|
|
||||||
part1 :: a -> Int
|
detectUnique :: Int -> String -> Char -> String
|
||||||
part1 = error "part1 not defined for day 06"
|
detectUnique n acc x =
|
||||||
|
if isUnique (take n $ reverse acc)
|
||||||
|
then acc ++ "0"
|
||||||
|
else acc ++ [x]
|
||||||
|
|
||||||
part2 :: a -> Int
|
parseInput :: T.Text -> String
|
||||||
part2 = error "part2 not defined for day 06"
|
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…
Reference in New Issue