mirror of
https://codeberg.org/JasterV/aoc2024-haskell.git
synced 2026-04-27 02:15:43 +00:00
day4 partTwo WIP
This commit is contained in:
parent
f5c4473280
commit
883e5fb8da
2 changed files with 25 additions and 2 deletions
|
|
@ -20,4 +20,8 @@ partOne input =
|
|||
countXMAS [] = 0
|
||||
|
||||
partTwo :: String -> Int
|
||||
partTwo _input = 0
|
||||
partTwo input =
|
||||
let matrix = M.buildMatrix (lines input)
|
||||
in length $ filter (isXMAS . fst) $ filter ((== 'a') . snd) $ M.toList matrix
|
||||
where
|
||||
isXMAS = undefined
|
||||
|
|
|
|||
|
|
@ -1,10 +1,20 @@
|
|||
{-# LANGUAGE LambdaCase #-}
|
||||
{-# LANGUAGE ScopedTypeVariables #-}
|
||||
|
||||
module Day4.Matrix (Matrix, buildMatrix, groupWith) where
|
||||
module Day4.Matrix
|
||||
( Matrix,
|
||||
buildMatrix,
|
||||
groupWith,
|
||||
getValue,
|
||||
getValues,
|
||||
toList,
|
||||
)
|
||||
where
|
||||
|
||||
import Data.Foldable (find)
|
||||
import Data.IntMap.Lazy (IntMap)
|
||||
import qualified Data.IntMap.Lazy as IntMap
|
||||
import Data.Maybe
|
||||
|
||||
type AssocList k v = [(k, v)]
|
||||
|
||||
|
|
@ -23,6 +33,15 @@ buildMatrix xs = Matrix (go xs 0 [])
|
|||
let acc' = ((row, column), x) : acc
|
||||
in parseRow xs' (row, column + 1) acc'
|
||||
|
||||
toList :: Matrix v -> [((Int, Int), v)]
|
||||
toList (Matrix assoc) = assoc
|
||||
|
||||
getValue :: (Int, Int) -> Matrix v -> Maybe v
|
||||
getValue position (Matrix assoc) = snd <$> find ((== position) . fst) assoc
|
||||
|
||||
getValues :: [(Int, Int)] -> Matrix v -> [v]
|
||||
getValues positions matrix = mapMaybe (`getValue` matrix) positions
|
||||
|
||||
{--
|
||||
Given a matrix of elements and a function mapping a position into an aggregation of its values,
|
||||
group the elements by the aggregation result
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue