This repository has been archived on 2023-12-02. You can view files and clone it, but cannot push or open issues or pull requests.
logan_2022/day4/advent_of_code_day4.txt

56 lines
1.2 KiB
Text
Raw Normal View History

2022-12-04 01:05:51 -05:00
@name Advent of Code
@inputs
@outputs
@persist Input:array [I Overlaps]:number
@trigger
runOnFile(1)
interval(100)
if(first()) {
fileLoad("input.txt")
}
if(fileClk()) {
Input = fileRead():explode("\n")
Input:removeString(Input:count())
I = 1
Overlaps = 0
}
if(fileLoaded() && I <= Input:count()) {
#printTable(Input)
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(fileLoaded() && I > Input:count()) {
print(Overlaps)
print(I)
runOnTick(0)
stoptimer("interval")
}