day3: Solve part1
This commit is contained in:
parent
1311230bbb
commit
e2d83ba1d6
5 changed files with 72 additions and 5 deletions
|
|
@ -63,7 +63,8 @@ library
|
||||||
DerivingStrategies
|
DerivingStrategies
|
||||||
ghc-options: -Weverything -Wno-implicit-prelude -Wno-missing-export-lists -Wno-missing-import-lists -Wno-missing-kind-signatures -Wno-missed-specialisations -Wno-all-missed-specialisations -Wno-unsafe -Wno-safe -Wno-missing-safe-haskell-mode -Wno-missing-local-signatures -Wno-monomorphism-restriction -Wno-prepositive-qualified-module -fdefer-typed-holes -Wno-unused-packages
|
ghc-options: -Weverything -Wno-implicit-prelude -Wno-missing-export-lists -Wno-missing-import-lists -Wno-missing-kind-signatures -Wno-missed-specialisations -Wno-all-missed-specialisations -Wno-unsafe -Wno-safe -Wno-missing-safe-haskell-mode -Wno-missing-local-signatures -Wno-monomorphism-restriction -Wno-prepositive-qualified-module -fdefer-typed-holes -Wno-unused-packages
|
||||||
build-depends:
|
build-depends:
|
||||||
base
|
array
|
||||||
|
, base
|
||||||
, containers
|
, containers
|
||||||
, megaparsec
|
, megaparsec
|
||||||
, relude
|
, relude
|
||||||
|
|
@ -89,6 +90,7 @@ executable aoc
|
||||||
ghc-options: -Weverything -Wno-implicit-prelude -Wno-missing-export-lists -Wno-missing-import-lists -Wno-missing-kind-signatures -Wno-missed-specialisations -Wno-all-missed-specialisations -Wno-unsafe -Wno-safe -Wno-missing-safe-haskell-mode -Wno-missing-local-signatures -Wno-monomorphism-restriction -Wno-prepositive-qualified-module -fdefer-typed-holes -Wno-unused-packages
|
ghc-options: -Weverything -Wno-implicit-prelude -Wno-missing-export-lists -Wno-missing-import-lists -Wno-missing-kind-signatures -Wno-missed-specialisations -Wno-all-missed-specialisations -Wno-unsafe -Wno-safe -Wno-missing-safe-haskell-mode -Wno-missing-local-signatures -Wno-monomorphism-restriction -Wno-prepositive-qualified-module -fdefer-typed-holes -Wno-unused-packages
|
||||||
build-depends:
|
build-depends:
|
||||||
aoc
|
aoc
|
||||||
|
, array
|
||||||
, base
|
, base
|
||||||
, containers
|
, containers
|
||||||
, megaparsec
|
, megaparsec
|
||||||
|
|
@ -117,7 +119,8 @@ test-suite doctest
|
||||||
build-tool-depends:
|
build-tool-depends:
|
||||||
doctest:doctest
|
doctest:doctest
|
||||||
build-depends:
|
build-depends:
|
||||||
base
|
array
|
||||||
|
, base
|
||||||
, containers
|
, containers
|
||||||
, megaparsec
|
, megaparsec
|
||||||
, process
|
, process
|
||||||
|
|
@ -152,6 +155,7 @@ test-suite spec
|
||||||
build-depends:
|
build-depends:
|
||||||
QuickCheck
|
QuickCheck
|
||||||
, aoc
|
, aoc
|
||||||
|
, array
|
||||||
, base
|
, base
|
||||||
, containers
|
, containers
|
||||||
, hspec
|
, hspec
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,10 @@
|
||||||
|
467..114..
|
||||||
|
...*......
|
||||||
|
..35..633.
|
||||||
|
......#...
|
||||||
|
617*......
|
||||||
|
.....+.58.
|
||||||
|
..592.....
|
||||||
|
......755.
|
||||||
|
...$.*....
|
||||||
|
.664.598..
|
||||||
|
|
@ -19,6 +19,7 @@ dependencies:
|
||||||
mixin:
|
mixin:
|
||||||
- (Relude as Prelude, Relude, Relude.Unsafe, Relude.Extra.Enum)
|
- (Relude as Prelude, Relude, Relude.Unsafe, Relude.Extra.Enum)
|
||||||
- containers
|
- containers
|
||||||
|
- array
|
||||||
- text
|
- text
|
||||||
- megaparsec
|
- megaparsec
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -29,4 +29,4 @@ handleError e = do
|
||||||
hPutStrLn stderr $ "I ran into an issue: " <> show e
|
hPutStrLn stderr $ "I ran into an issue: " <> show e
|
||||||
|
|
||||||
defaultMain :: IO ()
|
defaultMain :: IO ()
|
||||||
defaultMain = Exception.catch (runAoC Y2023 D01 >>= print) handleError
|
defaultMain = Exception.catch (runAoC Y2023 D03 >>= print) handleError
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,58 @@
|
||||||
module AoC.Y2023.D03 (solve) where
|
module AoC.Y2023.D03 where
|
||||||
|
|
||||||
import AoC.Riddle
|
import AoC.Riddle
|
||||||
|
import Data.Array
|
||||||
|
import Data.Char (isDigit)
|
||||||
|
import System.Posix.Internals (const_fd_cloexec)
|
||||||
|
|
||||||
|
type Pos = (Int, Int)
|
||||||
|
type Puzzle = Array Pos Char
|
||||||
|
|
||||||
|
toArray :: [[Char]] -> Puzzle
|
||||||
|
toArray xxs =
|
||||||
|
array
|
||||||
|
((1, 1), (h, w))
|
||||||
|
[ ((y, x), c)
|
||||||
|
| (y, xs) <- zip [1 ..] xxs
|
||||||
|
, (x, c) <- zip [1 ..] xs
|
||||||
|
]
|
||||||
|
where
|
||||||
|
w = case xxs of
|
||||||
|
[] -> 0
|
||||||
|
xs : _ -> length xs
|
||||||
|
h = length xxs
|
||||||
|
|
||||||
|
parse :: Text -> Puzzle
|
||||||
|
parse = toArray . fmap toString . lines
|
||||||
|
|
||||||
|
symbols :: Puzzle -> [(Pos, Char)]
|
||||||
|
symbols = filter (isSymbol <$> snd) . assocs
|
||||||
|
where
|
||||||
|
isSymbol :: Char -> Bool
|
||||||
|
isSymbol c = not (isDigit c || c == '.')
|
||||||
|
|
||||||
|
neighborDeltas :: [Pos]
|
||||||
|
neighborDeltas =
|
||||||
|
[ (-1, -1)
|
||||||
|
, (-1, 0)
|
||||||
|
, (-1, 1)
|
||||||
|
, (0, -1)
|
||||||
|
, (0, 1)
|
||||||
|
, (1, -1)
|
||||||
|
, (1, 0)
|
||||||
|
, (1, 1)
|
||||||
|
]
|
||||||
|
|
||||||
|
neighbors :: Puzzle -> Pos -> [(Pos, Char)]
|
||||||
|
neighbors = undefined
|
||||||
|
|
||||||
|
part1 :: Puzzle -> Integer
|
||||||
|
part1 = const 42
|
||||||
|
|
||||||
solve :: (MonadIO m) => Text -> m (Either Text Solution)
|
solve :: (MonadIO m) => Text -> m (Either Text Solution)
|
||||||
solve _ = pure $ Left "not yet implemented"
|
solve input = do
|
||||||
|
let
|
||||||
|
puzzle = parse input
|
||||||
|
p1 = part1 puzzle
|
||||||
|
print $ symbols puzzle
|
||||||
|
pure $ Right [p1]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue