Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * ================================================================
- * AdventOfCode2021-Day2.js - goes in your \Documents\My Games\EXAPUNKS\some-player-id\custom\ folder
- * ================================================================
- */
- // For the latest Axiom VirtualNetwork+ scripting documentation,
- // please visit: http://www.zachtronics.com/virtualnetwork/
- function getTitle() {
- return "ADVENT OF CODE 2021 DAY 2";
- }
- function getSubtitle() {
- return "POWERED BY EXAS® (and javascript)";
- }
- function getDescription() {
- 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.";
- }
- //simplify creation of INPUT_DATA with string consts
- //and yes, lowercase const names. it's a coding sin, but it makes converting the input data much more drag-and-drop.
- const forward = "FORWARD", down = "DOWN", up = "UP";
- const INPUT_DATA = [/* PASTE YOUR INPUT DATA HERE*/];
- /* To format your input data, first replace all newlines with spaces, then add a comma before every space. */
- function initializeTestRun(testRun) {
- var targetHost = createHost("SUBCTRL", 5, 0, 3, 5);
- var distance = 0, depth = 0, trueDepth = 0;
- var forwardRegister = createRegister(targetHost, 5, 0, "MVFW");
- setRegisterReadCallback(forwardRegister, function() { return distance; });
- setRegisterWriteCallback(forwardRegister, function(value) { distance += value; });
- var upRegister = createRegister(targetHost, 6, 2, "MVUP");
- setRegisterReadCallback(upRegister, function() { return depth; });
- setRegisterWriteCallback(upRegister, function(value) { depth -= value; }); //up goes down
- var downRegister = createRegister(targetHost, 5, 2, "MVDN");
- setRegisterReadCallback(downRegister, function() { return depth; });
- setRegisterWriteCallback(downRegister, function(value) { depth += value; }); //down goes up
- var resultRegister = createRegister(targetHost, 7, 1, "RSLT");
- setRegisterReadCallback(resultRegister, function() { return (distance * depth).toString(); }); //keyword for >9999
- //for part 2, var depth actually means "aim" and trueDepth is the real depth
- var forwardRegisterPart2 = createRegister(targetHost, 5, 4, "FWP2");
- setRegisterReadCallback(forwardRegisterPart2, function() { return distance; }); //still the same
- setRegisterWriteCallback(forwardRegisterPart2, function(value) { distance += value; trueDepth += (depth * value); });
- var resultRegisterPart2 = createRegister(targetHost, 7, 4, "RSP2");
- setRegisterReadCallback(resultRegisterPart2, function() { return (distance * trueDepth).toString(); });
- createNormalFile(getPlayerHost(), 199, FILE_ICON_TEXT, ["FORWARD", "DOWN", "UP"]);
- createNormalFile(getPlayerHost(), 301, FILE_ICON_DATA, INPUT_DATA);
- }
- function onCycleFinished() {
- }
- /*
- * ================================================================
- * EXA code - these go into the actual in-game EXAs, using the headers for which name is which
- * ================================================================
- */
- /*
- EXAcode for both puzzles:
- -- XA --
- GRAB 301
- LINK 800
- MARK LOOP
- COPY F M
- COPY M X
- TEST X = 0
- TJMP FORWARD
- TEST X = 1
- TJMP DOWN
- TEST X = 2
- TJMP UP
- HALT;//HOW DID U DO THIS
- MARK FORWARD
- COPY F #MVFW // <-- in part 2, change this to #FWP2
- JUMP NEXT
- MARK DOWN
- COPY F #MVDN
- JUMP NEXT
- MARK UP
- COPY F #MVUP
- JUMP NEXT
- MARK NEXT
- TEST EOF
- FJMP LOOP
- SEEK -9999
- COPY #RSLT M // <-- in part 2, change this to #RSP2
- -- XB --
- GRAB 199
- MARK LOOP
- SEEK -9999
- COPY M X
- TEST X = F
- TJMP FORWARD
- TEST X = F
- TJMP DOWN
- TEST X = F
- TJMP UP
- COPY X F;//FINISH
- JUMP LOOP
- MARK FORWARD
- COPY 0 M
- JUMP LOOP
- MARK DOWN
- COPY 1 M
- JUMP LOOP
- MARK UP
- COPY 2 M
- JUMP LOOP
- solution will end up as the fourth value in XB's held file
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement