Clean bench
This commit is contained in:
@@ -15,7 +15,7 @@ paths =
|
||||
]
|
||||
|
||||
solutions :: [(Integer, [Day], FilePath)]
|
||||
solutions = filter (\(n, d, p) -> length d > 1) $ zip3 [1 ..] days paths
|
||||
solutions = filter (\(n, d, p) -> not (null d)) $ zip3 [1 ..] days paths
|
||||
|
||||
makeGroup :: (Show a) => (a, [Day], FilePath) -> Benchmark
|
||||
makeGroup (n, d, f) =
|
||||
@@ -33,5 +33,5 @@ makeBenchmarks f = zipWith name [1 ..] . map (makeBench f)
|
||||
groups :: [Benchmark]
|
||||
groups = map makeGroup solutions
|
||||
|
||||
main =
|
||||
defaultMain groups
|
||||
main :: IO ()
|
||||
main = defaultMain groups
|
||||
@@ -11,14 +11,14 @@ type Intermediate = [(Interval, Interval)]
|
||||
|
||||
makeInterval :: (Ord a) => a -> a -> (a, a)
|
||||
makeInterval a b
|
||||
| a > b = (b, a)
|
||||
| otherwise = (a, b)
|
||||
| a > b = (b, a)
|
||||
| otherwise = (a, b)
|
||||
|
||||
parser :: Parser Intermediate
|
||||
parser = someLines ((,) <$> interval <* char ',' <*> interval)
|
||||
where
|
||||
interval :: Parser Interval
|
||||
interval = makeInterval <$> number <* char '-' <*> number
|
||||
where
|
||||
interval :: Parser Interval
|
||||
interval = makeInterval <$> number <* char '-' <*> number
|
||||
|
||||
contains :: Interval -> Interval -> Bool
|
||||
contains (a, b) (c, d) = a <= c && b >= d
|
||||
@@ -29,9 +29,6 @@ overlap (a, b) (c, d) = not (b < c || a > d)
|
||||
sym :: (a -> a -> Bool) -> (a -> a -> Bool)
|
||||
sym f a b = f a b || f b a
|
||||
|
||||
pairFilter :: (a -> b -> Bool) -> [(a, b)] -> [(a, b)]
|
||||
pairFilter f = filter (uncurry f)
|
||||
|
||||
part1 :: Intermediate -> Int
|
||||
part1 = count (uncurry $ sym contains)
|
||||
|
||||
|
||||
@@ -72,6 +72,3 @@ part2 = uncurry ((fmap head .) . foldl (move CM9001))
|
||||
|
||||
day :: Day
|
||||
day = parsecDay parser (definitive . part1, definitive . part2)
|
||||
|
||||
fast :: Day
|
||||
fast = day
|
||||
@@ -30,5 +30,5 @@ days =
|
||||
, [D02.day]
|
||||
, [D03.day]
|
||||
, [D04.day]
|
||||
, [D05.day, D05.fast]
|
||||
, [D05.day]
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user