WackoMcGoose

AoC 2021 EXA Edition: Day 1

Dec 1st, 2021 (edited)
1,133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  * ================================================================
  3.  * AdventOfCode2021-Day1.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 1";
  12. }
  13. function getSubtitle() {
  14.     return "POWERED BY EXAS® (and javascript)";
  15. }
  16. function getDescription() {
  17.     return "https://adventofcode.com/2021/day/1 \nSanta is scanning the seabed for his sleigh keys! Count how many times the depth measurement *increases*. The depth reading log can be found in *file 300*. Hurry, Christmas is counting on you!\nPart 2, take the *rolling sum of three readings*, and count how many times that rolling sum increases.";
  18. }
  19.  
  20. const INPUT_DATA = [/* PASTE YOUR INPUT DATA HERE*/];
  21.  
  22. /* To format your input data, replace all newlines with commas, producing an array */
  23.  
  24. function initializeTestRun(testRun) {
  25.     //exapunks doesn't let numbers go higher than 9999? lmao time to cheat with both hands and do it in js
  26.     let cmpA0 = 0, cmpA1 = 0, cmpA2 = 0, cmpB0 = 0, cmpB1 = 0, cmpB2 = 0;
  27.  
  28.     //we actually do need to use the default host for some register-making
  29.     var targetHost = createHost("EMPTYHOST", 5, 0, 4, 3);
  30.     createNormalFile(getPlayerHost(), 300, FILE_ICON_DATA, INPUT_DATA);
  31.     var cmpA0Register = createRegister(targetHost, 5, 2, "CMA0");
  32.     setRegisterWriteCallback(cmpA0Register, function(value) { cmpA0 = value; });
  33.     setRegisterReadCallback(cmpA0Register, function() { return cmpA0; });
  34.     var cmpA1Register = createRegister(targetHost, 6, 2, "CMA1");
  35.     setRegisterWriteCallback(cmpA1Register, function(value) { cmpA1 = value; });
  36.     setRegisterReadCallback(cmpA1Register, function() { return cmpA1; });
  37.     var cmpA2Register = createRegister(targetHost, 7, 2, "CMA2");
  38.     setRegisterWriteCallback(cmpA2Register, function(value) { cmpA2 = value; });
  39.     setRegisterReadCallback(cmpA2Register, function() { return cmpA2; });
  40.     var cmpB0Register = createRegister(targetHost, 5, 0, "CMB0");
  41.     setRegisterWriteCallback(cmpB0Register, function(value) { cmpB0 = value; });
  42.     setRegisterReadCallback(cmpB0Register, function() { return cmpB0; });
  43.     var cmpB1Register = createRegister(targetHost, 6, 0, "CMB1");
  44.     setRegisterWriteCallback(cmpB1Register, function(value) { cmpB1 = value; });
  45.     setRegisterReadCallback(cmpB1Register, function() { return cmpB1; });
  46.     var cmpB2Register = createRegister(targetHost, 7, 0, "CMB2");
  47.     setRegisterWriteCallback(cmpB2Register, function(value) { cmpB2 = value; });
  48.     setRegisterReadCallback(cmpB2Register, function() { return cmpB2; });
  49.    
  50.     var cmpDiffRegister = createRegister(targetHost, 8, 1, "CMDF");
  51.     setRegisterReadCallback(cmpDiffRegister, function() {
  52.         //sumifications on demand
  53.         //but you gotta move values to and from registers yourself bruh
  54.         var sumOld = cmpA0 + cmpA1 + cmpA2;
  55.         var sumNew = cmpB0 + cmpB1 + cmpB2;
  56.         return sumNew - sumOld;
  57.     });
  58. }
  59. function onCycleFinished() {
  60. }
  61.  
  62. /*
  63.  * ================================================================
  64.  * EXA code - these go into the actual in-game EXAs, using the headers for which name is which
  65.  * ================================================================
  66.  */
  67.  
  68. /*
  69.     EXAcode for first puzzle:
  70.    
  71.     -- XA --
  72.     GRAB 300
  73.     COPY F X
  74.     MARK GETDIFFS
  75.     COPY X T
  76.     COPY F X
  77.     SUBI X T M
  78.     TEST EOF
  79.     FJMP GETDIFFS
  80.    
  81.     -- XB --
  82.     COPY 0 X
  83.     MARK READDIFFS
  84.     TEST M > 0
  85.     FJMP READDIFFS
  86.     ADDI X 1 X
  87.     JUMP READDIFFS
  88.    
  89.     solution is XB's X register
  90.    
  91.     ---
  92.  
  93.     EXAcode for second puzzle:
  94.  
  95.     -- XA --
  96.     GRAB 300
  97.     LINK 800
  98.     ;//INITIAL SETUP
  99.     COPY F #CMA0
  100.     COPY F #CMA1
  101.     COPY #CMA1 #CMB0
  102.     COPY F #CMA2
  103.     COPY #CMA2 #CMB1
  104.     MARK LOOP
  105.     COPY F #CMB2
  106.     COPY -1 M;//SIGNAL XB
  107.     VOID M;//XB DONE
  108.     COPY #CMA1 #CMA0
  109.     COPY #CMA2 #CMA1
  110.     COPY #CMB2 #CMA2
  111.     COPY #CMB1 #CMB0
  112.     COPY #CMB2 #CMB1
  113.     TEST EOF
  114.     FJMP LOOP
  115.     NOOP;//RUN 2 HERE 4 ANSWER
  116.    
  117.     -- XB --
  118.     LINK 800
  119.     ;//X STARTS AT 0
  120.     MARK LOOP
  121.     VOID M;//XA DONE
  122.     TEST #CMDF > 0
  123.     COPY -1 M;//SIGNAL XA GO
  124.     FJMP LOOP
  125.     ADDI X 1 X
  126.     JUMP LOOP
  127.  
  128.     fast-run to the NOOP at the end of XA, then result is XB's X register
  129.  */
Add Comment
Please, Sign In to add comment