Little update to day 3

This commit is contained in:
Steph 2022-12-04 14:20:49 +01:00
parent a2f722c670
commit 5758ad46d8

View File

@ -20,13 +20,12 @@ main = do
type Rucksack = (String, String)
parseData :: String -> [Rucksack]
parseData input = compartments
parseData input = zip firstCompartments secondCompartments
where
rucksacks = lines input
compartmentSize = map ((`div` 2) . length) rucksacks
firstCompartments = map (\(s, r) -> take s r) (zip compartmentSize rucksacks)
secondCompartments = map (\(s, r) -> drop s r) (zip compartmentSize rucksacks)
compartments = zip firstCompartments secondCompartments
firstCompartments = map (uncurry take) (zip compartmentSize rucksacks)
secondCompartments = map (uncurry drop) (zip compartmentSize rucksacks)
inBoth :: Eq a => [a] -> [a] -> [a]
inBoth a b = [x | x <- a, y <- b, x == y]