úÎ!fSbH      !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGIntcode machine representation(c) Eric Mertens, 2019ISCemertens@gmail.com Trustworthyq intcodeVMachine state is comprised of the program counter, relative base pointer, and memory.Interact with registers using:  ,  Interact with memory using: (), Build new machines with: ÿUpdates to memory are stored separately from the initial values which can enable equality comparisons to be relatively efficient. This efficiency comes from being able to compare the inital memory using only pointer equality when two machines are created by the same call to .intcodeprogram counterintcoderelative base pointerintcodememory updatesintcodeinitial memoryHintcode4Value stored in initial memory image at given index.intcodeMemory lookup.intcodeuConstruct machine from a list of initial values starting at address 0. Program counter and relative base start at 0.intcode%Store value at given memory position. intcode$Add offset to relative base pointer. intcode%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]Hintcode machine intcode position intcode value intcode machine intcode position intcode value intcodeinitial memory intcode position intcode value intcodeoffset intcodeprogram counter intcodememory values    Intcode opcodes(c) Eric Mertens, 2019ISCemertens@gmail.comSafe456+üintcode4Opcodes parameterized over argument representations.intcode addition:  c = a + bintcodemultiplication:  c = a * bintcodeinput:  a = input()intcodeoutput:  output(a)intcode jump-if-true: if a then goto bintcodejump-if-false: if !a then goto bintcode less-than:  c = a < bintcodeequals:  c = a == bintcodeadjust-rel-base: rel += aintcodehaltintcodeParameter modesintcodeabsolute positionintcode immediateintcoderelative positionintcodeBDecode an instruction to determine the opcode and parameter modes. decode 1002Just (Mul Abs Imm Abs)Iintcode?Compute the parameter mode for an argument at a given position.Jintcode$Extract the ith digit from a number. digit 0 24688 digit 3 24682 digit 4 24680intcode%Arguments visited from left to right.intcodeopcode Iintcode opcode intcode position Jintcode position intcodenumber intcodedigit Intcode interpreter(c) Eric Mertens, 2019ISCemertens@gmail.comSafeZÇ*intcode4Error when a machine fails to decode an instruction.,intcodeResult of small-step semantics.-intcode no effect.intcodeoutput/intcodeinput0intcodehalt1intcodebad instruction2intcode'Possible effects from running a machine3intcodeOutput an integer4intcodeInput an integer5intcodeHalt execution6intcodeExecution failure7intcodeLRun intcode program using stdio. Non-ASCII outputs are printed as integers.ANote that input and output is affected by handle buffering modes.KrunIO (run (new [104,72,104,101,104,108,104,108,104,111,104,33,104,10,99]))Hello!'runIO (run (new [104,-50,104,1000,99]))<<-50>><<1000>>8intcode75 generalized to an arbitrary input and output handle.9intcode.Run a given memory image as a list transducer.Use :% when you want to provide a specific 2.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.;intcodeFBig-step semantics of virtual machine. The implementation details of [ are abstracted away and the program behavior can be observed by interpreting the various 2 constructors.-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) Output 1 Halt `followedBy` FaultOutput 1 FaultFault `followedBy` undefinedFault>intcodeœProvide an input to the first occurrence of an input request in a program effect. It is considered a fault if a program terminates before using the input.?feedInput [5,6] (Input (\x -> Input (\y -> Output (x*y) Halt)))Output 30 HaltfeedInput [7] HaltFault?intcode(Small-step semantics of virtual machine.Kintcode,Apply a decoded opcode to the machine state.8intcodeinput handle intcodeoutput handle intcodeeffect 9intcodeinitial memory intcodeinputs intcodeoutputs :intcodeprogram effect intcodeinputs intcodeoutputs >intcodeinputs Kintcodeopcode with pointers intcodemachine with PC updated  *+,-./0123456789:;<=>?9 23456;<=>:,-./01?*+78<9 Intcode source file parser(c) Eric Mertens, 2019ISCemertens@gmail.comSafeb Gintcode)Parse a list of comma separated integers.parseInts "1, - 2, 3,-4"Just [1,-2,3,-4] parseInts " "Just []parseInts "1,2,3,x"NothingLintcodeHelper function for GGintcodeparser input intcodeparsed integers Lintcodereversed accumulator intcodeparser input intcodeparsed integers GGM      !"#$%&'()*+,-..//0123456789:;<=>?@ABCDEFGHIJKLMNO&intcode-0.3.0.0-FDZZZguWyzlH44f2kaG0idIntcode.MachineIntcode.OpcodeIntcode Intcode.ParseMachinepcrelBase memUpdates memInitial!newset addRelBasejmp memoryList $fEqMachine $fOrdMachine $fShowMachineOpcodeAddMulInpOutJnzJzLtEqArbHltModeAbsImmReldecode$fTraversableOpcode$fEqMode $fOrdMode $fReadMode $fShowMode $fEqOpcode $fOrdOpcode $fReadOpcode $fShowOpcode$fFunctorOpcode$fFoldableOpcode IntcodeFaultStepStepOutStepInStepHalt StepFaultEffectOutputInputHaltFaultrunIOhRunIO intcodeToList effectListrun>>> followedBy feedInputstep$fExceptionIntcodeFault $fShowEffect $fShowStep$fEqIntcodeFault$fOrdIntcodeFault$fShowIntcodeFault$fReadIntcodeFault parseInts indexImage parameterdigit opcodeImpl parseInts'