Added README to Day 4 because language is weird

This commit is contained in:
Logan G 2022-12-04 01:19:16 -07:00
parent 0d58695d68
commit 145f1adde4
Signed by: logan
GPG key ID: E328528C921E7A7A

70
day4/README.md Normal file
View file

@ -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")
}
```