WackoMcGoose

AoC 2021 EXA Edition: Day 2

Dec 3rd, 2021 (edited)
704
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  * ================================================================
  3.  * AdventOfCode2021-Day2.js - goes in your \Documents\My Games\EXAPUNKS\some-player-id\custom\ folder
  4.  * ================================================================
  5.  */
  6.  
  7. // For the latest Axiom VirtualNetwork+ scripting documentation,
  8. // please visit: http://www.zachtronics.com/virtualnetwork/
  9.  
  10. function getTitle() {
  11.     return "ADVENT OF CODE 2021 DAY 2";
  12. }
  13. function getSubtitle() {
  14.     return "POWERED BY EXAS® (and javascript)";
  15. }
  16. function getDescription() {
  17.     return "https://adventofcode.com/2021/day/2 \nThe sub must be piloted using *down*, *up*, and *forward* commands to increase and decrease *depth*, and increase horizontal *distance*, respectively. Write the commands to the *#MVFW*, *#MVDN*, and *#MVUP* registers, then get their *multiplied amount* from the *#RSLT* register.\nYour input data is in *file 301*. For convenience, the directional keywords are available in file 199.\nFor part 2, use *#FWP2* and *#RSP2* instead of the original \"forward\" and \"result\" registers.";
  18. }
  19.  
  20. //simplify creation of INPUT_DATA with string consts
  21. //and yes, lowercase const names. it's a coding sin, but it makes converting the input data much more drag-and-drop.
  22. const forward = "FORWARD", down = "DOWN", up = "UP";
  23.  
  24. const INPUT_DATA = [/* PASTE YOUR INPUT DATA HERE*/];
  25.  
  26. /* To format your input data, first replace all newlines with spaces, then add a comma before every space. */
  27.  
  28. function initializeTestRun(testRun) {
  29.     var targetHost = createHost("SUBCTRL", 5, 0, 3, 5);
  30.    
  31.     var distance = 0, depth = 0, trueDepth = 0;
  32.    
  33.     var forwardRegister = createRegister(targetHost, 5, 0, "MVFW");
  34.     setRegisterReadCallback(forwardRegister, function() { return distance; });
  35.     setRegisterWriteCallback(forwardRegister, function(value) { distance += value; });
  36.     var upRegister = createRegister(targetHost, 6, 2, "MVUP");
  37.     setRegisterReadCallback(upRegister, function() { return depth; });
  38.     setRegisterWriteCallback(upRegister, function(value) { depth -= value; }); //up goes down
  39.     var downRegister = createRegister(targetHost, 5, 2, "MVDN");
  40.     setRegisterReadCallback(downRegister, function() { return depth; });
  41.     setRegisterWriteCallback(downRegister, function(value) { depth += value; }); //down goes up
  42.     var resultRegister = createRegister(targetHost, 7, 1, "RSLT");
  43.     setRegisterReadCallback(resultRegister, function() { return (distance * depth).toString(); }); //keyword for >9999
  44.    
  45.     //for part 2, var depth actually means "aim" and trueDepth is the real depth
  46.     var forwardRegisterPart2 = createRegister(targetHost, 5, 4, "FWP2");
  47.     setRegisterReadCallback(forwardRegisterPart2, function() { return distance; }); //still the same
  48.     setRegisterWriteCallback(forwardRegisterPart2, function(value) { distance += value; trueDepth += (depth * value); });
  49.     var resultRegisterPart2 = createRegister(targetHost, 7, 4, "RSP2");
  50.     setRegisterReadCallback(resultRegisterPart2, function() { return (distance * trueDepth).toString(); });
  51.    
  52.     createNormalFile(getPlayerHost(), 199, FILE_ICON_TEXT, ["FORWARD", "DOWN", "UP"]);
  53.     createNormalFile(getPlayerHost(), 301, FILE_ICON_DATA, INPUT_DATA);
  54. }
  55.  
  56. function onCycleFinished() {
  57. }
  58.  
  59. /*
  60.  * ================================================================
  61.  * EXA code - these go into the actual in-game EXAs, using the headers for which name is which
  62.  * ================================================================
  63.  */
  64.  
  65. /*
  66.     EXAcode for both puzzles:
  67.    
  68.     -- XA --
  69.     GRAB 301
  70.     LINK 800
  71.     MARK LOOP
  72.     COPY F M
  73.     COPY M X
  74.     TEST X = 0
  75.     TJMP FORWARD
  76.     TEST X = 1
  77.     TJMP DOWN
  78.     TEST X = 2
  79.     TJMP UP
  80.     HALT;//HOW DID U DO THIS
  81.     MARK FORWARD
  82.     COPY F #MVFW            // <-- in part 2, change this to #FWP2
  83.     JUMP NEXT
  84.     MARK DOWN
  85.     COPY F #MVDN
  86.     JUMP NEXT
  87.     MARK UP
  88.     COPY F #MVUP
  89.     JUMP NEXT
  90.     MARK NEXT
  91.     TEST EOF
  92.     FJMP LOOP
  93.     SEEK -9999
  94.     COPY #RSLT M            // <-- in part 2, change this to #RSP2
  95.    
  96.     -- XB --
  97.     GRAB 199
  98.     MARK LOOP
  99.     SEEK -9999
  100.     COPY M X
  101.     TEST X = F
  102.     TJMP FORWARD
  103.     TEST X = F
  104.     TJMP DOWN
  105.     TEST X = F
  106.     TJMP UP
  107.     COPY X F;//FINISH
  108.     JUMP LOOP
  109.     MARK FORWARD
  110.     COPY 0 M
  111.     JUMP LOOP
  112.     MARK DOWN
  113.     COPY 1 M
  114.     JUMP LOOP
  115.     MARK UP
  116.     COPY 2 M
  117.     JUMP LOOP
  118.  
  119.     solution will end up as the fourth value in XB's held file
  120.  
  121.  */
RAW Paste Data