This repository has been archived on 2023-12-03. You can view files and clone it, but cannot push or open issues or pull requests.
thomas_2022/day_4/main.txt
Quantum e1fb818195
Fuck E2
Worthless fucking language

Fuck
2022-12-04 01:56:55 -05:00

65 lines
1.2 KiB
Text

@name Day 4
@inputs
@outputs
@persist Lines:array Overlaps:number Overlaps2:number I:number Done:number
@trigger
runOnTick(100)
runOnFile(1)
if(first()){
print("load")
fileLoad("input.txt")
Overlaps = 0
I = 1
}
if(fileLoaded() && Lines:count() == 0) {
Data = fileRead()
Lines = Data:explode("\n")
#print(Data)
}
In = "2-4,6-8\n2-3,4-5\n5-7,7-9\n2-8,3-7\n6-6,4-6\n2-6,4-8"
#Lines = In:explode("\n")
#print(In)
if(Lines:count() != 0 && Done == 0) {
while(perf()) {
#print(Lines[I, string])
V = Lines[I, string]
Pair = V:explode(",")
First = Pair[1, string]:explode("-")
Second = Pair[2, string]:explode("-")
L1 = First[1,string]:toNumber()
R1 = First[2,string]:toNumber()
L2 = Second[1,string]:toNumber()
R2 = Second[2,string]:toNumber()
Ol = (L1 <= L2 && R1 >= R2) || (L2 <= L1 && R2 >= R1)
if(Ol) {
#print(Pair, "overlap")
Overlaps++
}
Ol2 = (L1 <= R2 && L2 <= R1)
if(Ol2) {
#print(Pair, "overlap")
Overlaps2++
}
#print(D1, D2)
I++
if(I > Lines:count() - 1) {
Done = 1
break
}
}
}
print(Overlaps, Overlaps2, I)