projects
/
advent-of-code-22.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
d26baeb
)
Tidying up
author
Neil Smith
<NeilNjae@users.noreply.github.com>
Mon, 26 Dec 2022 10:04:13 +0000
(10:04 +0000)
committer
Neil Smith
<NeilNjae@users.noreply.github.com>
Mon, 26 Dec 2022 10:04:13 +0000
(10:04 +0000)
advent-of-code22.cabal
patch
|
blob
|
history
advent02/Main.hs
patch
|
blob
|
history
advent07/Main.hs
patch
|
blob
|
history
advent14/Main.hs
patch
|
blob
|
history
advent15/Main.hs
patch
|
blob
|
history
advent25/Main.hs
patch
|
blob
|
history
diff --git
a/advent-of-code22.cabal
b/advent-of-code22.cabal
index 3504e46d0eee73c96bb039437a2b9411535623df..496c42c349ef66cefc0de247e30cc4a9d9efc208 100644
(file)
--- a/
advent-of-code22.cabal
+++ b/
advent-of-code22.cabal
@@
-135,7
+135,7
@@
executable advent06
executable advent07
import: common-extensions, build-directives
main-is: advent07/Main.hs
executable advent07
import: common-extensions, build-directives
main-is: advent07/Main.hs
- build-depends: text, attoparsec, containers,
path-tree,
rosezipper
+ build-depends: text, attoparsec, containers, rosezipper
executable advent08
import: common-extensions, build-directives
executable advent08
import: common-extensions, build-directives
@@
-233,4
+233,3
@@
executable advent24
executable advent25
import: common-extensions, build-directives
main-is: advent25/Main.hs
executable advent25
import: common-extensions, build-directives
main-is: advent25/Main.hs
--- build-depends: split
diff --git
a/advent02/Main.hs
b/advent02/Main.hs
index 231531749fb68bb0ca9d11b7654e15eb3ae06c47..074157a0d9bdd8f6b50ed9695deed1875861f00a 100644
(file)
--- a/
advent02/Main.hs
+++ b/
advent02/Main.hs
@@
-1,7
+1,7
@@
-- Writeup at https://work.njae.me.uk/2022/12/02/advent-of-code-2022-day-2/
import AoC
-- Writeup at https://work.njae.me.uk/2022/12/02/advent-of-code-2022-day-2/
import AoC
-import Data.Text ()
+import Data.Text (
Text
)
import qualified Data.Text.IO as TIO
import Data.Attoparsec.Text hiding (Result)
import Control.Applicative
import qualified Data.Text.IO as TIO
import Data.Attoparsec.Text hiding (Result)
import Control.Applicative
@@
-52,6
+52,13
@@
roundFromResult (ShapeResult shape result) = Round shape p2s
-- Parse the input file
-- Parse the input file
+match1P :: Parser [Round]
+match2P :: Parser [ShapeResult]
+roundP :: Parser Round
+shapeResultP :: Parser ShapeResult
+p1ShapeP, p2ShapeP, aP, bP, cP, xP, yP, zP :: Parser Shape
+resultP, xrP, yrP, zrP :: Parser Result
+
match1P = roundP `sepBy` endOfLine
roundP = Round <$> p1ShapeP <*> (" " *> p2ShapeP)
match1P = roundP `sepBy` endOfLine
roundP = Round <$> p1ShapeP <*> (" " *> p2ShapeP)
@@
-73,13
+80,14
@@
xrP = Loss <$ "X"
yrP = Draw <$ "Y"
zrP = Win <$ "Z"
yrP = Draw <$ "Y"
zrP = Win <$ "Z"
--- successfulParse :: Text -> (Integer, [Maybe Integer])
+successfulParse1 :: Text -> [Round]
successfulParse1 input =
case parseOnly match1P input of
Left _err -> [] -- TIO.putStr $ T.pack $ parseErrorPretty err
successfulParse1 input =
case parseOnly match1P input of
Left _err -> [] -- TIO.putStr $ T.pack $ parseErrorPretty err
- Right match
-> match
+ Right match
es -> matches
+successfulParse2 :: Text -> [ShapeResult]
successfulParse2 input =
case parseOnly match2P input of
Left _err -> [] -- TIO.putStr $ T.pack $ parseErrorPretty err
successfulParse2 input =
case parseOnly match2P input of
Left _err -> [] -- TIO.putStr $ T.pack $ parseErrorPretty err
- Right match
-> match
+ Right match
es -> matches
diff --git
a/advent07/Main.hs
b/advent07/Main.hs
index dcc076c9d2b4e89316548900ab18c0dfef3e1654..077b35b36366df1af9b10b13d1c4195fa5cf1d2b 100644
(file)
--- a/
advent07/Main.hs
+++ b/
advent07/Main.hs
@@
-10,7
+10,6
@@
import Data.Maybe
import Data.Tree
import Data.Tree.Zipper hiding (tree)
import qualified Data.Map.Strict as M
import Data.Tree
import Data.Tree.Zipper hiding (tree)
import qualified Data.Map.Strict as M
--- import Data.Map.Strict ((!), (!?))
import Data.List (foldl', sort)
data ParsedObject = CD String
import Data.List (foldl', sort)
data ParsedObject = CD String
diff --git
a/advent14/Main.hs
b/advent14/Main.hs
index 0ded02b02faa7975a03aadfd38344c0616d72a26..924b413ff3ed18d00a2446c8a74b47ac225da968 100644
(file)
--- a/
advent14/Main.hs
+++ b/
advent14/Main.hs
@@
-4,7
+4,6
@@
import AoC
import Data.Text (Text)
import qualified Data.Text.IO as TIO
import Data.Attoparsec.Text hiding (take, D)
import Data.Text (Text)
import qualified Data.Text.IO as TIO
import Data.Attoparsec.Text hiding (take, D)
-import Control.Applicative
import Data.List
import Data.Ix
import Data.Maybe
import Data.List
import Data.Ix
import Data.Maybe
diff --git
a/advent15/Main.hs
b/advent15/Main.hs
index 9ed5d862ee465d5e496feab50c27f6a236aaa34e..96f3213e24aec982051ca6afccf7a3918f92028f 100644
(file)
--- a/
advent15/Main.hs
+++ b/
advent15/Main.hs
@@
-4,12
+4,9
@@
import AoC
import Data.Text (Text)
import qualified Data.Text.IO as TIO
import Data.Attoparsec.Text hiding (take, D)
import Data.Text (Text)
import qualified Data.Text.IO as TIO
import Data.Attoparsec.Text hiding (take, D)
-import Control.Applicative
-import Data.List
import Data.Ix
import qualified Data.Set as S
import Linear hiding (Trace, trace, distance)
import Data.Ix
import qualified Data.Set as S
import Linear hiding (Trace, trace, distance)
-import Control.Lens
type Position = V2 Int
type Position = V2 Int
@@
-22,7
+19,8
@@
instance Semigroup Region where
r1 <> r2 = Region (\p -> getRegion r1 p || getRegion r2 p)
instance Monoid Region where
r1 <> r2 = Region (\p -> getRegion r1 p || getRegion r2 p)
instance Monoid Region where
- mempty = Region (\p -> False)
+ -- mempty = Region (\p -> False)
+ mempty = Region (const False)
main :: IO ()
main =
main :: IO ()
main =
diff --git
a/advent25/Main.hs
b/advent25/Main.hs
index 4e6cf876029e4dd73645a67d553b3688a8fadf58..28c33f751f4afc874e952d4b29371472782536f9 100644
(file)
--- a/
advent25/Main.hs
+++ b/
advent25/Main.hs
@@
-10,7
+10,6
@@
main =
numStrs <- readFile dataFileName
let fuels = fmap readSnafu $ lines numStrs
putStrLn $ showSnafu $ sum fuels
numStrs <- readFile dataFileName
let fuels = fmap readSnafu $ lines numStrs
putStrLn $ showSnafu $ sum fuels
- -- print $ part1 fuels
readSnafu :: String -> Int
readSnafu cs = foldl' go 0 cs
readSnafu :: String -> Int
readSnafu cs = foldl' go 0 cs
@@
-36,7
+35,7
@@
packSnafu :: [Int] -> String
packSnafu digits
| carry == 0 = shown
| otherwise = (snafuRep carry) : shown
packSnafu digits
| carry == 0 = shown
| otherwise = (snafuRep carry) : shown
- where (carry, shown) = foldl' packSnafuDigit (0, "")
digits
+ where (carry, shown) = foldl' packSnafuDigit (0, "")
packSnafuDigit :: (Int, String) -> Int -> (Int, String)
packSnafuDigit (carry, acc) d
packSnafuDigit :: (Int, String) -> Int -> (Int, String)
packSnafuDigit (carry, acc) d