projects
/
advent-of-code-16.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
3dfbda1
)
Tidying
author
Neil Smith
<neil.git@njae.me.uk>
Tue, 20 Dec 2016 10:52:12 +0000
(10:52 +0000)
committer
Neil Smith
<neil.git@njae.me.uk>
Tue, 20 Dec 2016 10:52:12 +0000
(10:52 +0000)
advent20.hs
patch
|
blob
|
history
diff --git
a/advent20.hs
b/advent20.hs
index 8935f8656dd8b2ed5b4b1e492e353e27ccba38a7..3f43710703f82a8274c8216626547232a7b88a7b 100644
(file)
--- 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')
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
high :: Interval -> Int
high (Interval _ h) = h
--- input = 5
-input = 3012210
-
main :: IO ()
main = do
text <- readFile "advent20.txt"
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)
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
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)
| 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)
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
intervalFile = intervalLine `endBy` newline
--- IntervalLine = choice [cpyL, incL, decL, jnzL]
intervalLine = Interval <$> int <*> (string "-" *> int)
intervalLine = Interval <$> int <*> (string "-" *> int)
-
parseIfile :: String -> Either ParseError [Interval]
parseIfile input = parse intervalFile "(unknown)" input
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
successfulParse :: Either ParseError [a] -> [a]
successfulParse (Left _) = []
successfulParse (Right a) = a