Day 2 done
This commit is contained in:
12
aoc.cabal
12
aoc.cabal
@ -21,6 +21,7 @@ executable 1
|
||||
-- other-modules:
|
||||
-- other-extensions:
|
||||
build-depends: base ^>=4.21.0.0
|
||||
, text
|
||||
hs-source-dirs: app
|
||||
default-language: GHC2021
|
||||
|
||||
@ -30,6 +31,7 @@ executable 2
|
||||
-- other-modules:
|
||||
-- other-extensions:
|
||||
build-depends: base ^>=4.21.0.0
|
||||
, text
|
||||
hs-source-dirs: app
|
||||
default-language: GHC2021
|
||||
executable 3
|
||||
@ -38,6 +40,7 @@ executable 3
|
||||
-- other-modules:
|
||||
-- other-extensions:
|
||||
build-depends: base ^>=4.21.0.0
|
||||
, text
|
||||
hs-source-dirs: app
|
||||
default-language: GHC2021
|
||||
executable 4
|
||||
@ -46,6 +49,7 @@ executable 4
|
||||
-- other-modules:
|
||||
-- other-extensions:
|
||||
build-depends: base ^>=4.21.0.0
|
||||
, text
|
||||
hs-source-dirs: app
|
||||
default-language: GHC2021
|
||||
executable 5
|
||||
@ -54,6 +58,7 @@ executable 5
|
||||
-- other-modules:
|
||||
-- other-extensions:
|
||||
build-depends: base ^>=4.21.0.0
|
||||
, text
|
||||
hs-source-dirs: app
|
||||
default-language: GHC2021
|
||||
executable 6
|
||||
@ -62,6 +67,7 @@ executable 6
|
||||
-- other-modules:
|
||||
-- other-extensions:
|
||||
build-depends: base ^>=4.21.0.0
|
||||
, text
|
||||
hs-source-dirs: app
|
||||
default-language: GHC2021
|
||||
executable 7
|
||||
@ -70,6 +76,7 @@ executable 7
|
||||
-- other-modules:
|
||||
-- other-extensions:
|
||||
build-depends: base ^>=4.21.0.0
|
||||
, text
|
||||
hs-source-dirs: app
|
||||
default-language: GHC2021
|
||||
executable 8
|
||||
@ -78,6 +85,7 @@ executable 8
|
||||
-- other-modules:
|
||||
-- other-extensions:
|
||||
build-depends: base ^>=4.21.0.0
|
||||
, text
|
||||
hs-source-dirs: app
|
||||
default-language: GHC2021
|
||||
executable 9
|
||||
@ -86,6 +94,7 @@ executable 9
|
||||
-- other-modules:
|
||||
-- other-extensions:
|
||||
build-depends: base ^>=4.21.0.0
|
||||
, text
|
||||
hs-source-dirs: app
|
||||
default-language: GHC2021
|
||||
executable 10
|
||||
@ -94,6 +103,7 @@ executable 10
|
||||
-- other-modules:
|
||||
-- other-extensions:
|
||||
build-depends: base ^>=4.21.0.0
|
||||
, text
|
||||
hs-source-dirs: app
|
||||
default-language: GHC2021
|
||||
executable 11
|
||||
@ -102,6 +112,7 @@ executable 11
|
||||
-- other-modules:
|
||||
-- other-extensions:
|
||||
build-depends: base ^>=4.21.0.0
|
||||
, text
|
||||
hs-source-dirs: app
|
||||
default-language: GHC2021
|
||||
executable 12
|
||||
@ -110,5 +121,6 @@ executable 12
|
||||
-- other-modules:
|
||||
-- other-extensions:
|
||||
build-depends: base ^>=4.21.0.0
|
||||
, text
|
||||
hs-source-dirs: app
|
||||
default-language: GHC2021
|
||||
|
||||
34
app/2.hs
34
app/2.hs
@ -1,6 +1,36 @@
|
||||
{-# LANGUAGE LambdaCase #-}
|
||||
{-# LANGUAGE LambdaCase, OverloadedStrings #-}
|
||||
module Main where
|
||||
|
||||
import Data.Text (Text)
|
||||
import Data.Text qualified as T
|
||||
import Data.Text.IO qualified as T
|
||||
import Data.Functor
|
||||
|
||||
parse :: Text -> [(Int,Int)]
|
||||
parse = map
|
||||
((\(a,b) -> (read (T.unpack a), read (T.unpack $ T.drop 1 b))) . T.breakOn "-") .
|
||||
T.split (==',')
|
||||
|
||||
solve1 :: [(Int,Int)] -> Int
|
||||
solve1 = sum . go . (>>= \(a,b) -> [a..b])
|
||||
where
|
||||
go :: [Int] -> [Int]
|
||||
go = filter
|
||||
(\a -> let d = T.show a in uncurry (==) $
|
||||
T.splitAt (T.length d `div` 2) d)
|
||||
|
||||
solve2 :: [(Int,Int)] -> Int
|
||||
solve2 = sum . go . (>>= \(a,b) -> [a..b])
|
||||
where
|
||||
go :: [Int] -> [Int]
|
||||
go = filter
|
||||
(\a -> let d = T.show a in
|
||||
or $ [1..T.length d - 1] >>= \i ->
|
||||
let c = T.chunksOf i d in pure $
|
||||
all (== head c) c)
|
||||
|
||||
|
||||
main :: IO ()
|
||||
main = pure ()
|
||||
main = T.readFile "inputs/2" <&> parse >>= \i ->
|
||||
print (solve1 i) >>
|
||||
print (solve2 i)
|
||||
|
||||
1
inputs/2
Normal file
1
inputs/2
Normal file
@ -0,0 +1 @@
|
||||
2558912-2663749,1-19,72-85,82984-100358,86-113,193276-237687,51-69,779543-880789,13004-15184,2768-3285,4002-4783,7702278-7841488,7025-8936,5858546565-5858614010,5117615-5149981,4919-5802,411-466,126397-148071,726807-764287,7454079517-7454227234,48548-61680,67606500-67729214,9096-10574,9999972289-10000034826,431250-455032,907442-983179,528410-680303,99990245-100008960,266408-302255,146086945-146212652,9231222-9271517,32295166-32343823,32138-36484,4747426142-4747537765,525-652,333117-414840,13413537-13521859,1626-1972,49829276-50002273,69302-80371,8764571787-8764598967,5552410836-5552545325,660-782,859-1056
|
||||
Reference in New Issue
Block a user