Added Day 4 solutions in E2

This commit is contained in:
Logan G 2022-12-03 23:05:51 -07:00
parent 43958d4529
commit 0d58695d68
Signed by: logan
GPG key ID: E328528C921E7A7A
4 changed files with 1130 additions and 0 deletions

View file

@ -0,0 +1,55 @@
@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")
}

View file

@ -0,0 +1,55 @@
@name Advent of Code Part 2
@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(Range2[1,string]:toNumber() <= Range1[2,string]:toNumber()
&& Range2[2,string]:toNumber() >= Range1[1,string]:toNumber()) {
#print(I+": True1")
Overlaps++
} elseif (Range1[1,string]:toNumber() <= Range2[2,string]:toNumber()
&& Range1[2,string]:toNumber() >= Range2[1,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")
}

1000
day4/input.txt Normal file

File diff suppressed because it is too large Load diff

20
day4/input2.txt Normal file
View file

@ -0,0 +1,20 @@
51-88,52-87
41-55,22-56
6-74,74-86
51-98,52-86
8-77,3-94
76-76,77-97
29-42,29-35
59-97,60-60
9-86,27-86
58-85,59-85
23-41,26-39
87-91,74-93
13-83,83-84
16-82,15-82
15-95,14-96
1-1,2-93
3-87,2-74
6-47,7-78
47-68,47-92
4-64,5-68