forked from adventofcode/logan_2022
56 lines
1.2 KiB
Text
56 lines
1.2 KiB
Text
|
@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")
|
||
|
}
|
||
|
|