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
|
||||
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:
|
||||
base
|
||||
array
|
||||
, base
|
||||
, containers
|
||||
, megaparsec
|
||||
, 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
|
||||
build-depends:
|
||||
aoc
|
||||
, array
|
||||
, base
|
||||
, containers
|
||||
, megaparsec
|
||||
|
|
@ -117,7 +119,8 @@ test-suite doctest
|
|||
build-tool-depends:
|
||||
doctest:doctest
|
||||
build-depends:
|
||||
base
|
||||
array
|
||||
, base
|
||||
, containers
|
||||
, megaparsec
|
||||
, process
|
||||
|
|
@ -152,6 +155,7 @@ test-suite spec
|
|||
build-depends:
|
||||
QuickCheck
|
||||
, aoc
|
||||
, array
|
||||
, base
|
||||
, containers
|
||||
, hspec
|
||||
|
|
|
|||
|
|
@ -0,0 +1,10 @@
|
|||
467..114..
|
||||
...*......
|
||||
..35..633.
|
||||
......#...
|
||||
617*......
|
||||
.....+.58.
|
||||
..592.....
|
||||
......755.
|
||||
...$.*....
|
||||
.664.598..
|
||||
|
|
@ -19,6 +19,7 @@ dependencies:
|
|||
mixin:
|
||||
- (Relude as Prelude, Relude, Relude.Unsafe, Relude.Extra.Enum)
|
||||
- containers
|
||||
- array
|
||||
- text
|
||||
- megaparsec
|
||||
|
||||
|
|
|
|||
|
|
@ -29,4 +29,4 @@ handleError e = do
|
|||
hPutStrLn stderr $ "I ran into an issue: " <> show e
|
||||
|
||||
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 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 _ = 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