X-Git-Url: https://git.njae.me.uk/?a=blobdiff_plain;f=app%2Fadvent15.hs;fp=app%2Fadvent15.hs;h=0000000000000000000000000000000000000000;hb=fd498a2713d69a5d55179ff07e58ce296d6fba94;hp=5970bd661c191054a14faf51896bfe441e13d4fc;hpb=3a26b187d5dc23b05fb73daabe52a92976a7a3c7;p=advent-of-code-16.git diff --git a/app/advent15.hs b/app/advent15.hs deleted file mode 100644 index 5970bd6..0000000 --- a/app/advent15.hs +++ /dev/null @@ -1,43 +0,0 @@ -module Main(main) where - -import Text.Parsec -import Text.ParserCombinators.Parsec.Number - -type Disk = (Int -> Bool) - -main :: IO () -main = do - text <- readFile "data/advent15.txt" - let disks = successfulParse $ parseIfile text - part1 disks - part2 disks - -part1 :: [Disk] -> IO () -part1 disks = print $ head $ filter (canFall disks) [0..] - -part2 :: [Disk] -> IO () -part2 disks = print $ head $ filter (canFall disks2) [0..] - where disks2 = disks ++ [diskify 7 11 0] - -canFall :: [Disk] -> Int -> Bool -canFall ds i = all (\d -> (d i)) ds - - -instructionFile = instructionLine `endBy` newline -instructionLine = diskify <$> (string "Disc #" *> int) - <*> (string " has " *> int) - <*> (string " positions; at time=0, it is at position " *> int) - <* (string ".") - -diskify :: Int -> Int -> Int -> (Int -> Bool) -diskify n size pos0 = (\i -> (size + n + pos0 + i) `mod` size == 0) - -parseIfile :: String -> Either ParseError [Disk] -parseIfile input = parse instructionFile "(unknown)" input - -parseIline :: String -> Either ParseError Disk -parseIline input = parse instructionLine "(unknown)" input - -successfulParse :: Either ParseError [a] -> [a] -successfulParse (Left _) = [] -successfulParse (Right a) = a