common build-directives
build-depends: base >=4.16
default-language: Haskell2010
+ hs-source-dirs: ., app, lib
+ other-modules: AoC
ghc-options: -O2
-Wall
-threaded
-- LANGUAGE extensions used by modules in this package.
-- other-extensions:
build-depends: base ^>=4.16.4.0
- hs-source-dirs: app
+ hs-source-dirs: app, lib
default-language: Haskell2010
+library
+ import: common-extensions
+ build-depends: base >=4.16
+ hs-source-dirs: ., app, lib
+ exposed-modules: AoC
+
executable advent01
import: common-extensions, build-directives
main-is: advent01/Main.hs
-- Writeup at https://work.njae.me.uk/2022/12/01/advent-of-code-2022-day-1/
-import System.Environment
+import AoC
import Data.List
import Data.List.Split
import Data.Ord
print $ part1 calories
print $ part2 calories
-getDataFileName :: IO String
-getDataFileName =
- do args <- getArgs
- progName <- getProgName
- let baseDataName = if null args
- then progName
- else head args
- let dataFileName = "data/" ++ baseDataName ++ ".txt"
- return dataFileName
-
part1 :: [[Int]] -> Int
part1 = maximum . fmap sum
-- Writeup at https://work.njae.me.uk/2022/12/02/advent-of-code-2022-day-2/
-import System.Environment
+import AoC
import Data.Text ()
import qualified Data.Text.IO as TIO
import Data.Attoparsec.Text hiding (Result)
let match2 = successfulParse2 text
print $ part2 match2
-getDataFileName :: IO String
-getDataFileName =
- do args <- getArgs
- progName <- getProgName
- let baseDataName = if null args
- then progName
- else head args
- let dataFileName = "data/" ++ baseDataName ++ ".txt"
- return dataFileName
-
part1 :: [Round] -> Int
part1 = sum . fmap scoreRound
-- Writeup at https://work.njae.me.uk/2022/12/03/advent-of-code-2022-day-3/
-import System.Environment
+import AoC
import Data.Char
import qualified Data.Set as S
import Data.List
print $ part1 rucksacks
print $ part2 rucksacks
-getDataFileName :: IO String
-getDataFileName =
- do args <- getArgs
- progName <- getProgName
- let baseDataName = if null args
- then progName
- else head args
- let dataFileName = "data/" ++ baseDataName ++ ".txt"
- return dataFileName
-
part1 :: [Rucksack] -> Int
part1 = sum . fmap (priority . commonItem)
-- Writeup at https://work.njae.me.uk/2022/12/04/advent-of-code-2022-day-4/
-import System.Environment
+import AoC
import Data.Text (Text)
import qualified Data.Text.IO as TIO
import Data.Attoparsec.Text hiding (Result)
print $ part1 pairs
print $ part2 pairs
-getDataFileName :: IO String
-getDataFileName =
- do args <- getArgs
- progName <- getProgName
- let baseDataName = if null args
- then progName
- else head args
- let dataFileName = "data/" ++ baseDataName ++ ".txt"
- return dataFileName
-
part1 :: [Pair] -> Int
part1 = length . (filter hasContainment)
-- Writeup at https://work.njae.me.uk/2022/12/04/advent-of-code-2022-day-4/
-import System.Environment
+import AoC
import Data.Text (Text)
import qualified Data.Text.IO as TIO
import Data.Attoparsec.Text hiding (Result)
print $ part1 pairs
print $ part2 pairs
-getDataFileName :: IO String
-getDataFileName =
- do args <- getArgs
- progName <- getProgName
- let baseDataName = if null args
- then progName
- else head args
- let dataFileName = "data/" ++ baseDataName ++ ".txt"
- return dataFileName
-
part1 :: [Pair] -> Int
part1 = length . (filter hasContainment)
-- Writeup at https://work.njae.me.uk/2022/12/04/advent-of-code-2022-day-4/
-import System.Environment
+import AoC
import Data.Text (Text)
import qualified Data.Text.IO as TIO
import Data.Attoparsec.Text hiding (take)
putStrLn $ part1 wharf moves
putStrLn $ part2 wharf moves
-
-getDataFileName :: IO String
-getDataFileName =
- do args <- getArgs
- progName <- getProgName
- let baseDataName = if null args
- then progName
- else head args
- let dataFileName = "data/" ++ baseDataName ++ ".txt"
- return dataFileName
-
-
part1 :: Wharf -> [Move] -> String
part1 wharf moves = showTops $ applyMoves1 wharf moves
-- Writeup at https://work.njae.me.uk/2022/12/06/advent-of-code-2022-day-6/
-import System.Environment
+import AoC
import Data.List
-- test = "mjqjpqmgbljsphdztnvjfqwrcgsmlb"
print $ part1 text
print $ part2 text
-getDataFileName :: IO String
-getDataFileName =
- do args <- getArgs
- progName <- getProgName
- let baseDataName = if null args
- then progName
- else head args
- let dataFileName = "data/" ++ baseDataName ++ ".txt"
- return dataFileName
-
part1 :: String -> Int
part1 = interestingPosition 4
--- /dev/null
+module AoC ( getDataFileName ) where
+
+import System.Environment
+
+getDataFileName :: IO String
+getDataFileName =
+ do args <- getArgs
+ progName <- getProgName
+ let baseDataName = if null args
+ then progName
+ else head args
+ let dataFileName = "data/" ++ baseDataName ++ ".txt"
+ return dataFileName