From: Neil Smith Date: Tue, 20 Dec 2016 10:52:12 +0000 (+0000) Subject: Tidying X-Git-Url: https://git.njae.me.uk/?a=commitdiff_plain;h=fd300170c824138ea4053ac30a18c25c5b5949e6;p=advent-of-code-16.git Tidying --- diff --git a/advent20.hs b/advent20.hs index 8935f86..3f43710 100644 --- a/advent20.hs +++ b/advent20.hs @@ -1,4 +1,4 @@ -import Text.Parsec hiding (State) +import Text.Parsec import Text.ParserCombinators.Parsec.Number import Control.Applicative ((<$), (<*), (*>), (<*>), liftA) import Data.List (foldl') @@ -11,9 +11,6 @@ low (Interval l _) = l high :: Interval -> Int high (Interval _ h) = h --- input = 5 -input = 3012210 - main :: IO () main = do text <- readFile "advent20.txt" @@ -32,9 +29,6 @@ part2 intervals = do let highGap = 4294967295 - (high $ last ints) print (lowGap + gapCount + highGap) --- 4294967295 - - disjoint :: Interval -> Interval -> Bool disjoint (Interval a b) (Interval c d) | b < c = True @@ -62,25 +56,18 @@ mergeAdjacent (i1:intervals) i0 | low i0 == high i1 + 1 = (Interval (low i1) (high i0)):intervals | otherwise = i1:(mergeAdjacent intervals i0) - gaps :: [Interval] -> Int gaps [] = 0 gaps [_] = 0 gaps ((Interval _ b):(Interval c d):intervals) = (c - b - 1) + gaps ((Interval c d):intervals) - intervalFile = intervalLine `endBy` newline --- IntervalLine = choice [cpyL, incL, decL, jnzL] intervalLine = Interval <$> int <*> (string "-" *> int) - parseIfile :: String -> Either ParseError [Interval] parseIfile input = parse intervalFile "(unknown)" input -parseIline :: String -> Either ParseError Interval -parseIline input = parse intervalLine "(unknown)" input - successfulParse :: Either ParseError [a] -> [a] successfulParse (Left _) = [] successfulParse (Right a) = a