···
67
-
gaussJordan :: Map (Int,Int) (Ratio Int) -> Map Int (Ratio Int) -> (Map (Int,Int) (Ratio Int), Map Int (Ratio Int), Int)
68
-
gaussJordan m g = error "GJ"
67
+
type Matrix = (Int, Int, Map (Int,Int) (Ratio Int))
69
+
cols :: Matrix -> Int
70
+
cols (_, c, _) = c - 1
72
+
rows :: Matrix -> Int
75
+
mat :: Matrix -> Map (Int,Int) (Ratio Int)
78
+
minimum' :: Ord a => [a] -> Maybe a
79
+
minimum' [] = Nothing
80
+
minimum' as = Just $ minimum as
82
+
pivotCell :: Matrix -> Int -> Int -> Maybe (Int, Int)
83
+
pivotCell m minRow minCol =
84
+
minimum' [(i,j) | i <- [minCol..cols m - 1],
85
+
j <- [minRow..rows m - 1],
86
+
(mat m) Map.! (i,j) /= 0]
88
+
eraseColumn :: Int -> Int -> Matrix -> Matrix
89
+
eraseColumn i j m = error "TODO"
91
+
swapCols :: Int -> Int -> Matrix -> Matrix
92
+
swapCols i i' m = error "TODO"
94
+
-- d' = Map.fromList
95
+
-- ([((i,j), d Map.! (i',j)) | j <- [0..rows - 1]] ++
96
+
-- [((i',j), d Map.! (i,j)) | j <- [0..rows - 1]])
97
+
-- in (r,c,Map.union d' d)
99
+
gaussJordan :: Map (Int,Int) (Ratio Int) -> Map (Int,Int) (Ratio Int)
100
+
gaussJordan mat = error "TODO" -- go mat 0 0
101
+
-- where go m minRow minCol =
102
+
-- case pivotCell m minRow minCol of
105
+
-- let m' = eraseColumn minCol minRow $
106
+
-- normalizeRow minCol minRow $
107
+
-- swapRows j minRow $
108
+
-- swapCols i minCol m
109
+
-- in go m' (minRow + 1) (minCol + 1)
solveMachine2 :: [Button] -> [Int] -> Maybe Int
71
-
solveMachine2 buttons goal =
72
-
let mat = Map.fromList [((i,j),1 % 1) | (i,b) <- zip [0..] buttons, j <- b]
73
-
g = Map.fromList $ zip [0..] (map (% 1) goal)
74
-
(mat', g', rank) = gaussJordan mat g
112
+
solveMachine2 buttons goal = error "TODO"
113
+
-- let mat = Map.fromList [((i,j),1 % 1) | (i,b) <- zip [0..] buttons, j <- b]
114
+
-- g = Map.fromList $ zip [0..] (map (% 1) goal)
115
+
-- (mat', g', rank) = gaussJordan mat g
part2 :: String -> String