úÎ!J©F£D      !"#$%&'()*+,-./0123456789:;<=>?@ABCIntcode interpreter(c) Eric Mertens, 2019ISCemertens@gmail.com Trustworthy456E3intcode#Error when a machine fails to step.intcode4Opcodes parameterized over argument representations.intcodeaddition:  c = a + bintcodemultiplication:  c = a * bintcodeinput:  a = input()intcodeoutput:  output(a)intcodejump-if-true: if a then goto bintcodejump-if-false: if !a then goto b intcodeless-than:  c = a < b intcodeequals:  c = a == b intcodeadjust-rel-base: rel += a intcodehalt intcodeParameter modesintcodeabsolute positionintcode immediateintcoderelative positionintcodeResult of small-step semantics.intcode no effectintcodeoutputintcodeinputintcodehaltintcodebad instructionintcode'Possible effects from running a machineintcodeOutput an integerintcodeInput an integerintcodeHalt executionintcodeExecution failureintcodeMachine state.intcodeprogram counterintcoderelative base pointer intcodememory updates!intcodeinitial memory"intcode Run intcode program using stdio.KrunIO (run (new [104,72,104,101,104,108,104,108,104,111,104,33,104,10,99]))Hello!#intcode.Run a given memory image as a list transducer.Use $% when you want to provide a specific .Throws: 4 when machine faults or too few inputs are provided.GintCodeToList [3,12,6,12,15,1,13,14,13,4,13,99,-1,0,1,9] <$> [[0],[10]] [[0],[1]]BintCodeToList [3,3,1105,-1,9,1101,0,0,12,4,12,99,1] <$> [[0],[10]] [[0],[1]]:{ intCodeToList5[3,21,1008,21,8,20,1005,20,22,107,8,21,20,1006,20,31,31106,0,36,98,0,0,1002,21,125,20,4,20,1105,1,46,104,2999,1105,1,46,1101,1000,1,20,4,20,1105,1,46,98,99]<$> [[7],[8],[9]]:}[[999],[1000],[1001]]$intcodeVEvaluate a program's effect as a function from a list of inputs to a list of outputs.Throws: 4 when machine faults or too few inputs are provided.Dintcode4Value stored in initial memory image at given index.%intcode!Memory lookup from 0-based index.&intcodeuConstruct machine from a list of initial values starting at address 0. Program counter and relative base start at 0.'intcode6Update the value stored at a given location in memory.Eintcode;Update the relative base pointer by adding an offset to it.Fintcode%Set program counter to a new address.(intcode¦Generate a list representation of memory starting from zero. This can get big for sparsely filled memory using large addresses. Returned values start at position 0.#memoryList (set 8 10 (new [1,2,3]))[1,2,3,0,0,0,0,0,10])intcode&Big-step semantics of virtual machine.-run (new [1102,34915192,34915192,7,4,7,99,0])Output 1219070632396864 Haltrun (new [3,1,99])Input <function>*intcode™Compose two effects together. Outputs from first argument are used as inputs to the second effect. Composed effect halts when the second machine halts.,let mult n = Input (\i -> Output (i*n) Halt),let add n = Input (\i -> Output (i+n) Halt)!effectList (mult 3 >>> add 1) [4][13]+intcode<Run first effect until it halts, then run the second effect.(Output 1 Halt `followedBy` Output 2 HaltOutput 1 (Output 2 Halt),intcode›Provide an input to the first occurence of an input request in a program effect. It is considered a fault if a program terminates before using the input.,let mult n = Input (\i -> Output (i*n) Halt)feedInput [6] (mult 5)Output 30 Halt-intcode(Small-step semantics of virtual machine..intcodeBDecode an instruction to determine the opcode and parameter modes. decode 1002Just (Mul Abs Imm Abs)Gintcode?Compute the parameter mode for an argument at a given position.Hintcode$Extract the ith digit from a number. digit 0 24688 digit 3 24682 digit 4 24680/intcode%Arguments visited from left to right. #intcodeinitial memory intcodeinputs intcodeoutputs $intcodeprogram effect intcodeinputs intcodeoutputs %intcode machine intcode position intcode value &intcodeinitial memory intcodenew machine 'intcode position intcode new value Eintcodeoffset Fintcodeprogram counter ,intcodeinputs .intcodeopcode Gintcodeopcode intcode position Hintcode position intcodenumber intcodedigit /   !"#$%&'()*+,-./#" !%&'()*$+,-   .*9 I      !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGH&intcode-0.1.0.0-4OePIktfCMnBzmtyhNvAJeIntcode IntcodeFaultOpcodeAddMulInpOutJnzJzLtEqArbHltModeAbsImmRelStepStepOutStepInStepHalt StepFaultEffectOutputInputHaltFaultMachinepcrelBasememoryimagerunIO intCodeToList effectList!newset memoryListrun>>> followedBy feedInputstepdecode$fTraversableOpcode$fExceptionIntcodeFault $fEqMachine $fOrdMachine $fShowMachine $fShowEffect $fShowStep$fEqMode $fOrdMode $fReadMode $fShowMode $fEqOpcode $fOrdOpcode $fReadOpcode $fShowOpcode$fFunctorOpcode$fFoldableOpcode$fEqIntcodeFault$fOrdIntcodeFault$fShowIntcodeFault$fReadIntcodeFault indexImage adjustRelBasejmp parameterdigit