From 145f1adde4d5f2ae68c7dca87682718bbcbe52ca Mon Sep 17 00:00:00 2001 From: Logan G Date: Sun, 4 Dec 2022 01:19:16 -0700 Subject: [PATCH] Added README to Day 4 because language is weird --- day4/README.md | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 day4/README.md diff --git a/day4/README.md b/day4/README.md new file mode 100644 index 0000000..b8667d7 --- /dev/null +++ b/day4/README.md @@ -0,0 +1,70 @@ +This is my solution to the Day 4 puzzle in the 2022 Advent of Code. + +It is written in a language called Expression 2, a scripting language for the Wiremod addon in Garry's Mod. + +Due to the unusual nature of the language, here is an annotated verison of Part 1: +```golo +@name Advent of Code +@inputs +@outputs +# These variables persist through multiple executions of the script +@persist Input:array [I Overlaps]:number +@trigger + +# When the file has successfully uploaded, run this script +runOnFile(1) + +# Run this script every 100ms +interval(100) + +# When you first place the E2 entity down, upload the input dataset to the server +if(first()) { + fileLoad("input.txt") +} + +# If the current reason the script is being executed is the file being uploaded, parse it. +if(fileClk()) { + Input = fileRead():explode("\n") + Input:removeString(Input:count()) + I = 1 + Overlaps = 0 +} + +# If the file is fully loaded and the index variable is below the maximum of the array, loop through it. +if(fileLoaded() && I <= Input:count()) { + #printTable(Input) + + # This function will loop forever until the execution time limit for the current game tick is almost met, then the loop will break and wait until the next time the script is ran to continue + while(perf()) { + #print(Input[I,string]) + Thing = Input[I,string]:explode(",") + + Range1 = Thing[1,string]:explode("-") + Range2 = Thing[2,string]:explode("-") + + if(Range1[1,string]:toNumber() >= Range2[1,string]:toNumber() + && Range1[2,string]:toNumber() <= Range2[2,string]:toNumber()) { + #print(I+": True1") + Overlaps++ + } elseif(Range2[1,string]:toNumber() >= Range1[1,string]:toNumber() + && Range2[2,string]:toNumber() <= Range1[2,string]:toNumber()) { + #print(I+": True2") + Overlaps++ + } else { + #print(I+": False") + } + I++ + if(I > Input:count()) { + break + } + } +} + +# If the file is fully loaded and I is above the array size (meaning it is done), print the results +if(fileLoaded() && I > Input:count()) { + print(Overlaps) + print(I) + runOnTick(0) + stoptimer("interval") +} +```