This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| newAmps :: [Int] -> [Int] -> Amps |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Intcode ( | |
| Status, | |
| Program | |
| ) | |
| data Amps = Amps { | |
| ampsOf::[Program], | |
| activeAmp::Int | |
| } deriving(Show) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| runProgram :: Program -> Program | |
| runProgram prog = case status prog of | |
| Running -> runProg . runStep $ prog | |
| AwaitInput -> if (length . input $ prog) > 0 | |
| then runProg . runStep $ prog | |
| else prog | |
| _ -> prog | |
| runStep :: Program -> Program | |
| runStep = ... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| data Program = Program { | |
| input::[Int], | |
| intCode::[Int], | |
| status::Status, | |
| -- ip: Instruction Pointer | |
| ip::Int, | |
| -- rb: Relative Base | |
| rb::Int, | |
| output::[Int] | |
| } deriving(Show, Eq) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| runProgram :: Int -> State Program Int |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| runProgram :: State Program () | |
| runProgram = do | |
| prog <- get | |
| case programState prog of | |
| Running -> do | |
| runStep' | |
| runProgram | |
| _ -> return () | |
| runStep' :: State Program () |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| runProgram :: Program -> Program | |
| runProgram prog = case status prog of | |
| Running -> runProgram . runStep $ prog | |
| _ -> prog | |
| runStep :: Program -> Program | |
| runStep prog = ... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| data Program = Program { | |
| intCode::[Int], | |
| status::Status, | |
| -- Instruction Pointer: ip | |
| ip::Int | |
| } deriving(Show) | |
| data Status = Running | Terminated | Crashed deriving(Show) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import qualified Lib as L (someFunc) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import quailfied Lib as L |