fixed up split in day 4
This commit is contained in:
parent
c1c14a1fe9
commit
f48f0459ac
17
day4.hs
17
day4.hs
@ -9,7 +9,7 @@ import Data.List (sort, nub)
|
|||||||
main :: IO ()
|
main :: IO ()
|
||||||
main = do
|
main = do
|
||||||
raw <- readFile "day4.txt"
|
raw <- readFile "day4.txt"
|
||||||
let ls = parse $ lines raw
|
let ls = map (concat . (map words)) $ split "" $ lines raw
|
||||||
ansA = length $ filter (== True) $ map solveA ls
|
ansA = length $ filter (== True) $ map solveA ls
|
||||||
ansB = length $ filter (== True) $ map solveB ls
|
ansB = length $ filter (== True) $ map solveB ls
|
||||||
in do
|
in do
|
||||||
@ -96,12 +96,9 @@ hgtValid s' =
|
|||||||
s = drop 1 $ dropWhile (/= ':') s'
|
s = drop 1 $ dropWhile (/= ':') s'
|
||||||
(val,unit) = head $ (reads s :: [(Int,String)])
|
(val,unit) = head $ (reads s :: [(Int,String)])
|
||||||
|
|
||||||
parse :: [String] -> [[String]]
|
split :: Eq a => a -> [a] -> [[a]]
|
||||||
parse [] = []
|
split _ [] = []
|
||||||
parse s = parse' s [] []
|
split d as = chunk : (split d rest)
|
||||||
|
where
|
||||||
parse' :: [String] -> [String] -> [[String]] -> [[String]]
|
chunk = takeWhile (/= d) as
|
||||||
parse' [] as bs = bs ++ [as]
|
rest = drop 1 $ dropWhile (/= d) as
|
||||||
parse' (s:ss) as bs
|
|
||||||
| s == "" = parse' ss [] $ bs ++ [as]
|
|
||||||
| otherwise = parse' ss (as ++ (words s)) bs
|
|
||||||
|
Loading…
Reference in New Issue
Block a user