diff --git a/.github/workflows/haskell-ci.yml b/.github/workflows/haskell-ci.yml index 7ef03ee..6005afa 100644 --- a/.github/workflows/haskell-ci.yml +++ b/.github/workflows/haskell-ci.yml @@ -137,8 +137,6 @@ jobs: touch cabal.project echo "packages: $GITHUB_WORKSPACE/source/common" >> cabal.project echo "packages: $GITHUB_WORKSPACE/source/solutions" >> cabal.project - echo "packages: $GITHUB_WORKSPACE/source/intcode" >> cabal.project - echo "packages: $GITHUB_WORKSPACE/source/asmprog" >> cabal.project cat cabal.project - name: sdist run: | @@ -154,28 +152,18 @@ jobs: echo "PKGDIR_advent=${PKGDIR_advent}" >> "$GITHUB_ENV" PKGDIR_solutions="$(find "$GITHUB_WORKSPACE/unpacked" -maxdepth 1 -type d -regex '.*/solutions-[0-9.]*')" echo "PKGDIR_solutions=${PKGDIR_solutions}" >> "$GITHUB_ENV" - PKGDIR_intcode="$(find "$GITHUB_WORKSPACE/unpacked" -maxdepth 1 -type d -regex '.*/intcode-[0-9.]*')" - echo "PKGDIR_intcode=${PKGDIR_intcode}" >> "$GITHUB_ENV" - PKGDIR_asmprog="$(find "$GITHUB_WORKSPACE/unpacked" -maxdepth 1 -type d -regex '.*/asmprog-[0-9.]*')" - echo "PKGDIR_asmprog=${PKGDIR_asmprog}" >> "$GITHUB_ENV" rm -f cabal.project cabal.project.local touch cabal.project touch cabal.project.local echo "packages: ${PKGDIR_advent}" >> cabal.project echo "packages: ${PKGDIR_solutions}" >> cabal.project - echo "packages: ${PKGDIR_intcode}" >> cabal.project - echo "packages: ${PKGDIR_asmprog}" >> cabal.project echo "package advent" >> cabal.project echo " ghc-options: -Werror=missing-methods" >> cabal.project echo "package solutions" >> cabal.project echo " ghc-options: -Werror=missing-methods" >> cabal.project - echo "package intcode" >> cabal.project - echo " ghc-options: -Werror=missing-methods" >> cabal.project - echo "package asmprog" >> cabal.project - echo " ghc-options: -Werror=missing-methods" >> cabal.project cat >> cabal.project <> cabal.project.local + $HCPKG list --simple-output --names-only | perl -ne 'for (split /\s+/) { print "constraints: any.$_ installed\n" unless /^(advent|solutions)$/; }' >> cabal.project.local cat cabal.project cat cabal.project.local - name: dump install plan @@ -207,10 +195,6 @@ jobs: ${CABAL} -vnormal check cd ${PKGDIR_solutions} || false ${CABAL} -vnormal check -imissing-upper-bounds - cd ${PKGDIR_intcode} || false - ${CABAL} -vnormal check - cd ${PKGDIR_asmprog} || false - ${CABAL} -vnormal check - name: haddock run: | $CABAL v2-haddock --disable-documentation --haddock-all $ARG_COMPILER --with-haddock $HADDOCK $ARG_TESTS $ARG_BENCH all diff --git a/asmprog/AsmProg.hs b/asmprog/AsmProg.hs deleted file mode 100644 index cbaa075..0000000 --- a/asmprog/AsmProg.hs +++ /dev/null @@ -1,49 +0,0 @@ -{-# Language TemplateHaskell, LambdaCase #-} -module AsmProg where - -import Advent.ReadS ( P(..) ) -import Control.Applicative ( Alternative(empty, (<|>)) ) -import Control.Lens ( LensLike', use, makeLenses ) -import Control.Monad.State ( MonadState ) - -data Registers = Registers { _regA, _regB, _regC, _regD :: !Int } - deriving (Read, Show, Eq, Ord) - -makeLenses ''Registers - -zeroRegisters :: Registers -zeroRegisters = Registers 0 0 0 0 - -class HasRegisters a where - reg :: Functor f => Register -> LensLike' f a Int - -data Register = A|B|C|D - deriving (Show, Eq, Ord) - -instance HasRegisters Registers where - reg A = regA - reg B = regB - reg C = regC - reg D = regD - {-# INLINE reg #-} - -data Value = Int !Int | Reg !Register - deriving Show - -rval :: (MonadState r m, HasRegisters r) => Value -> m Int -rval v = - case v of - Int i -> pure i - Reg r -> use (reg r) -{-# INLINE rval #-} - -pValue :: P Value -pValue = Int <$> P reads <|> Reg <$> pReg - -pReg :: P Register -pReg = P lex >>= \case - "a" -> pure A - "b" -> pure B - "c" -> pure C - "d" -> pure D - _ -> empty diff --git a/asmprog/LICENSE b/asmprog/LICENSE deleted file mode 100644 index 16080eb..0000000 --- a/asmprog/LICENSE +++ /dev/null @@ -1,13 +0,0 @@ -Copyright (c) 2021 Eric Mertens - -Permission to use, copy, modify, and/or distribute this software for any purpose -with or without fee is hereby granted, provided that the above copyright notice -and this permission notice appear in all copies. - -THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH -REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND -FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, -INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS -OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER -TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF -THIS SOFTWARE. diff --git a/asmprog/asmprog.cabal b/asmprog/asmprog.cabal deleted file mode 100644 index 9fcf2f5..0000000 --- a/asmprog/asmprog.cabal +++ /dev/null @@ -1,24 +0,0 @@ -cabal-version: 3.6 -name: asmprog -version: 0.1.0.0 -category: None -synopsis: Support library for 2016 -description: These are my cleaned-up solutions to the Advent of Code - programming game. -license: ISC -license-file: LICENSE -author: Eric Mertens -maintainer: emertens@gmail.com -copyright: 2021 Eric Mertens -build-type: Simple -Tested-With: GHC == {9.6.6, 9.8.2, 9.10.1} - -library - hs-source-dirs: . - exposed-modules: AsmProg - build-depends: - base ^>= {4.18, 4.19, 4.20}, - advent, - lens, - mtl - default-language: Haskell2010 diff --git a/cabal.project b/cabal.project index 62ac615..16c0dc1 100644 --- a/cabal.project +++ b/cabal.project @@ -4,5 +4,8 @@ package * packages: common/advent.cabal solutions/solutions.cabal - intcode/intcode.cabal - asmprog/asmprog.cabal + +source-repository-package + type: git + location: https://github.com/glguy/intcode + tag: 1a9daae346eb458065c1926e60e89d5c43856607 \ No newline at end of file diff --git a/common/advent.cabal b/common/advent.cabal index 579ddb5..0fae2f3 100644 --- a/common/advent.cabal +++ b/common/advent.cabal @@ -33,6 +33,7 @@ library exposed-modules: Advent + Advent.AsmProg Advent.Box Advent.Chinese Advent.Coord @@ -72,6 +73,8 @@ library containers ^>= {0.6, 0.7}, fgl ^>= 5.8, MemoTrie ^>= 0.6, + mtl ^>= 2.3.1, + lens ^>= 5.3.2, random ^>= 1.2, template-haskell, transformers ^>= {0.5, 0.6}, diff --git a/common/src/Advent/AsmProg.hs b/common/src/Advent/AsmProg.hs new file mode 100644 index 0000000..40a977e --- /dev/null +++ b/common/src/Advent/AsmProg.hs @@ -0,0 +1,69 @@ +{-# Language LambdaCase #-} +{-| +Module : Advent.AsmProg +Description : Support module for 2016 +Copyright : (c) Eric Mertens, 2024 +License : ISC +Maintainer : emertens@gmail.com + +This module supports a set of 3 tasks from the 2016 problem set that +used a 4 register machine state. + +-} +module Advent.AsmProg where + +import Advent.ReadS (P(..)) +import Control.Applicative ( Alternative(empty, (<|>)) ) +import Control.Lens (use) +import Control.Monad.State ( MonadState ) + +data Registers = Registers { _regA, _regB, _regC, _regD :: !Int } + deriving (Read, Show, Eq, Ord) + +regA :: Functor f => (Int -> f Int) -> Registers -> f Registers +regA f r = (\x -> r { _regA = x}) <$> f (_regA r) + +regB :: Functor f => (Int -> f Int) -> Registers -> f Registers +regB f r = (\x -> r { _regB = x}) <$> f (_regB r) + +regC :: Functor f => (Int -> f Int) -> Registers -> f Registers +regC f r = (\x -> r { _regC = x}) <$> f (_regC r) + +regD :: Functor f => (Int -> f Int) -> Registers -> f Registers +regD f r = (\x -> r { _regD = x}) <$> f (_regD r) + +zeroRegisters :: Registers +zeroRegisters = Registers 0 0 0 0 + +class HasRegisters a where + reg :: Functor f => Register -> (Int -> f Int) -> a -> f a + +data Register = A | B | C | D + deriving (Show, Eq, Ord) + +instance HasRegisters Registers where + reg A = regA + reg B = regB + reg C = regC + reg D = regD + {-# INLINE reg #-} + +data Value = Int !Int | Reg !Register + deriving Show + +rval :: (MonadState r m, HasRegisters r) => Value -> m Int +rval = \case + Int i -> pure i + Reg r -> use (reg r) +{-# INLINE rval #-} + +pValue :: P Value +pValue = Int <$> P reads <|> Reg <$> pReg + +pReg :: P Register +pReg = P lex >>= \case + "a" -> pure A + "b" -> pure B + "c" -> pure C + "d" -> pure D + _ -> empty diff --git a/inputs/2024/13.txt b/inputs/2024/13.txt new file mode 100644 index 0000000..e69de29 diff --git a/solutions/solutions.cabal b/solutions/solutions.cabal index c360865..7bb0acf 100644 --- a/solutions/solutions.cabal +++ b/solutions/solutions.cabal @@ -202,7 +202,7 @@ executable sln_2016_11 executable sln_2016_12 import: day main-is: 2016/12.hs - build-depends: asmprog, containers, vector, lens + build-depends: containers, vector, lens executable sln_2016_13 import: day @@ -252,7 +252,7 @@ executable sln_2016_22 executable sln_2016_23 import: day main-is: 2016/23.hs - build-depends: asmprog, containers, vector, lens, transformers + build-depends: containers, vector, lens, transformers executable sln_2016_24 import: day @@ -262,7 +262,7 @@ executable sln_2016_24 executable sln_2016_25 import: day main-is: 2016/25.hs - build-depends: asmprog, containers, vector, lens, transformers + build-depends: containers, vector, lens, transformers -- 2017 --------------------------------------------------------------- @@ -1172,3 +1172,8 @@ executable sln_2024_12 import: day main-is: 2024/12.hs build-depends: containers + +executable sln_2024_13 + import: day + main-is: 2024/13.hs + build-depends: containers, array diff --git a/solutions/src/2016/12.hs b/solutions/src/2016/12.hs index 59d6cd5..355eb53 100644 --- a/solutions/src/2016/12.hs +++ b/solutions/src/2016/12.hs @@ -13,7 +13,7 @@ module Main where import Advent (getInputLines) import Advent.ReadS -import AsmProg +import Advent.AsmProg import Control.Applicative (Alternative((<|>), empty)) import Control.Lens ((^.), (&~), (+=), (-=), (.=), (<~)) import Data.Foldable (for_) diff --git a/solutions/src/2016/23.hs b/solutions/src/2016/23.hs index 14acb6c..968adcf 100644 --- a/solutions/src/2016/23.hs +++ b/solutions/src/2016/23.hs @@ -13,7 +13,7 @@ module Main where import Advent ( getInputLines ) import Advent.ReadS ( P(..), runP ) -import AsmProg +import Advent.AsmProg import Control.Lens import Control.Applicative (Alternative((<|>), empty)) import Control.Monad.Trans.State.Strict ( evalState, State ) diff --git a/solutions/src/2016/25.hs b/solutions/src/2016/25.hs index 67bb605..ce4e6a8 100644 --- a/solutions/src/2016/25.hs +++ b/solutions/src/2016/25.hs @@ -17,7 +17,7 @@ module Main where import Advent.Input ( getInputLines ) import Advent.ReadS ( P(..), runP ) -import AsmProg +import Advent.AsmProg import Control.Applicative ( Alternative(empty) ) import Control.Lens (use, (+=), (-=), (.=), (<~), makeLenses, Contains(contains)) import Control.Monad.Trans.State ( evalState ) diff --git a/solutions/src/2024/13.hs b/solutions/src/2024/13.hs new file mode 100644 index 0000000..2912b5d --- /dev/null +++ b/solutions/src/2024/13.hs @@ -0,0 +1,33 @@ +{-# Language QuasiQuotes, TemplateHaskell, BlockArguments, LambdaCase, ImportQualifiedPost #-} +{-# OPTIONS_GHC -w #-} +{-| +Module : Main +Description : Day 13 solution +Copyright : (c) Eric Mertens, 2024 +License : ISC +Maintainer : emertens@gmail.com + + + +-} +module Main where + +import Data.Map (Map) +import Data.Map qualified as Map +import Data.Set (Set) +import Data.Set qualified as Set +import Data.List +import Data.Maybe +import Data.Array.Unboxed + +import Advent +import Advent.Coord +import Advent.Search +import System.Environment + +main :: IO () +main = + -- withArgs ["/Users/emertens/Source/advent/example.txt"] + do + input <- [format|2024 13 (%s%n)*|] + print input \ No newline at end of file