Skip to content

Commit

Permalink
merge asmprog into advent
Browse files Browse the repository at this point in the history
  • Loading branch information
glguy committed Dec 13, 2024
1 parent 183f70d commit 4797669
Show file tree
Hide file tree
Showing 13 changed files with 122 additions and 111 deletions.
18 changes: 1 addition & 17 deletions .github/workflows/haskell-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand All @@ -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 <<EOF
EOF
$HCPKG list --simple-output --names-only | perl -ne 'for (split /\s+/) { print "constraints: any.$_ installed\n" unless /^(advent|asmprog|intcode|solutions)$/; }' >> 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
Expand Down Expand Up @@ -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
Expand Down
49 changes: 0 additions & 49 deletions asmprog/AsmProg.hs

This file was deleted.

13 changes: 0 additions & 13 deletions asmprog/LICENSE

This file was deleted.

24 changes: 0 additions & 24 deletions asmprog/asmprog.cabal

This file was deleted.

7 changes: 5 additions & 2 deletions cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 3 additions & 0 deletions common/advent.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ library

exposed-modules:
Advent
Advent.AsmProg
Advent.Box
Advent.Chinese
Advent.Coord
Expand Down Expand Up @@ -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},
Expand Down
69 changes: 69 additions & 0 deletions common/src/Advent/AsmProg.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
{-# Language LambdaCase #-}
{-|
Module : Advent.AsmProg
Description : Support module for 2016
Copyright : (c) Eric Mertens, 2024
License : ISC
Maintainer : [email protected]
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
Empty file added inputs/2024/13.txt
Empty file.
11 changes: 8 additions & 3 deletions solutions/solutions.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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 ---------------------------------------------------------------

Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion solutions/src/2016/12.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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_)
Expand Down
2 changes: 1 addition & 1 deletion solutions/src/2016/23.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down
2 changes: 1 addition & 1 deletion solutions/src/2016/25.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down
33 changes: 33 additions & 0 deletions solutions/src/2024/13.hs
Original file line number Diff line number Diff line change
@@ -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 : [email protected]
<https://adventofcode.com/2024/day/13>
-}
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

0 comments on commit 4797669

Please sign in to comment.