|
|
@ -14,15 +14,13 @@ startingStates prog comps = update 0 (state, (input ++ [0], output)) out |
|
|
|
(state, (input, output)) = out `index` 0 |
|
|
|
|
|
|
|
runSeries :: Seq ((Map.Map Int Int, Int, Int), ([Int], [Int])) -> [Int] -> Int -> Int |
|
|
|
runSeries states comps idx = do |
|
|
|
let (state, (newInput, newOutput:outputs)) = uncurry compute $ index states idx |
|
|
|
let newStates = update idx (state, (newInput, newOutput:outputs)) states |
|
|
|
let newIdx = if idx+1 == Data.List.length comps then 0 else idx+1 |
|
|
|
let ((nextProg, nextY, nextZ), (nextInput, nextOutput)) = index newStates newIdx |
|
|
|
if nextY == -1 |
|
|
|
then newOutput |
|
|
|
else |
|
|
|
runSeries (update newIdx ((nextProg, nextY, nextZ), (nextInput ++ [newOutput], nextOutput)) newStates) comps newIdx |
|
|
|
runSeries states comps idx = if nextY == -1 then newOutput |
|
|
|
else runSeries (update newIdx ((nextProg, nextY, nextZ), (nextInput ++ [newOutput], nextOutput)) newStates) comps newIdx |
|
|
|
where |
|
|
|
(state, (newInput, newOutput:outputs)) = uncurry compute $ index states idx |
|
|
|
newStates = update idx (state, (newInput, newOutput:outputs)) states |
|
|
|
newIdx = if idx+1 == Data.List.length comps then 0 else idx+1 |
|
|
|
((nextProg, nextY, nextZ), (nextInput, nextOutput)) = index newStates newIdx |
|
|
|
|
|
|
|
findMax :: Map.Map Int Int -> [[Int]] -> Int |
|
|
|
findMax prog comps = snd $ maximumBy (comparing snd) $ map (\i -> (i, runSeries (startingStates prog i) i 0)) comps |
|
|
|