Advent of Code 2025

Continuing to try day 10 in Haskell

Changed files
+48 -7
src
+48 -7
src/Day10.hs
···
else
(0 : go (n+1) (b:bs))
-
gaussJordan :: Map (Int,Int) (Ratio Int) -> Map Int (Ratio Int) -> (Map (Int,Int) (Ratio Int), Map Int (Ratio Int), Int)
-
gaussJordan m g = error "GJ"
solveMachine2 :: [Button] -> [Int] -> Maybe Int
-
solveMachine2 buttons goal =
-
let mat = Map.fromList [((i,j),1 % 1) | (i,b) <- zip [0..] buttons, j <- b]
-
g = Map.fromList $ zip [0..] (map (% 1) goal)
-
(mat', g', rank) = gaussJordan mat g
-
in Just 0
part2 :: String -> String
part2 input =
···
else
(0 : go (n+1) (b:bs))
+
type Matrix = (Int, Int, Map (Int,Int) (Ratio Int))
+
+
cols :: Matrix -> Int
+
cols (_, c, _) = c - 1
+
+
rows :: Matrix -> Int
+
rows (r, _, _) = r
+
+
mat :: Matrix -> Map (Int,Int) (Ratio Int)
+
mat (_, _, m) = m
+
+
minimum' :: Ord a => [a] -> Maybe a
+
minimum' [] = Nothing
+
minimum' as = Just $ minimum as
+
+
pivotCell :: Matrix -> Int -> Int -> Maybe (Int, Int)
+
pivotCell m minRow minCol =
+
minimum' [(i,j) | i <- [minCol..cols m - 1],
+
j <- [minRow..rows m - 1],
+
(mat m) Map.! (i,j) /= 0]
+
+
eraseColumn :: Int -> Int -> Matrix -> Matrix
+
eraseColumn i j m = error "TODO"
+
+
swapCols :: Int -> Int -> Matrix -> Matrix
+
swapCols i i' m = error "TODO"
+
-- let (r,c,d) = m
+
-- d' = Map.fromList
+
-- ([((i,j), d Map.! (i',j)) | j <- [0..rows - 1]] ++
+
-- [((i',j), d Map.! (i,j)) | j <- [0..rows - 1]])
+
-- in (r,c,Map.union d' d)
+
+
gaussJordan :: Map (Int,Int) (Ratio Int) -> Map (Int,Int) (Ratio Int)
+
gaussJordan mat = error "TODO" -- go mat 0 0
+
-- where go m minRow minCol =
+
-- case pivotCell m minRow minCol of
+
-- Nothing -> m
+
-- Just (i,j) ->
+
-- let m' = eraseColumn minCol minRow $
+
-- normalizeRow minCol minRow $
+
-- swapRows j minRow $
+
-- swapCols i minCol m
+
-- in go m' (minRow + 1) (minCol + 1)
solveMachine2 :: [Button] -> [Int] -> Maybe Int
+
solveMachine2 buttons goal = error "TODO"
+
-- let mat = Map.fromList [((i,j),1 % 1) | (i,b) <- zip [0..] buttons, j <- b]
+
-- g = Map.fromList $ zip [0..] (map (% 1) goal)
+
-- (mat', g', rank) = gaussJordan mat g
+
-- in Just 0
part2 :: String -> String
part2 input =