Compare commits

...

2 Commits

Author SHA1 Message Date
sejo 6f1ac45a15 stats day 13 (started late) 2021-12-13 01:24:55 -06:00
sejo 88c9045046 day 13! (2 includes pt 1 and 2) 2021-12-13 01:24:04 -06:00
4 changed files with 106 additions and 0 deletions

39
13/13.awk Normal file
View File

@ -0,0 +1,39 @@
BEGIN{ RS = "" }
NR==1{
for(i=1;i<=NF;i++) m[i] = $i
}
NR==2{
for(i=1;i<=NF;i++){
if($i~"x" || $i~"y") f[fp++] = $i
}
}
END{
fi = 0
print f[fi]
for(i in m){
split(m[i],arr,",")
x = arr[1]
y = arr[2]
if(f[fi]~"x"){
fx = f[fi]
sub("x=","",fx)
if(x-fx>0){
x = 2*fx-x
}
}
else if(f[fi]~"y"){
fy = f[fi]
sub("y=","",fy)
if(y-fy>0){
y = 2*fy-y
}
}
if(!p[x,y]){
p[x,y] = 1
nm[j++] = x "," y
}
}
print j
}

52
13/13_2.awk Normal file
View File

@ -0,0 +1,52 @@
BEGIN{ RS = "" }
NR==1{
for(i=1;i<=NF;i++) m[i] = $i
}
NR==2{
for(i=1;i<=NF;i++){
if($i~"x" || $i~"y") f[fp++] = $i
}
}
END{
for(fi in f){
j=0
for(i in m){
split(m[i],arr,",")
x = arr[1]; y = arr[2]
if(f[fi]~"x"){
fx = f[fi]
sub("x=","",fx)
if(x-fx>0) x = 2*fx-x
}
else if(f[fi]~"y"){
fy = f[fi]
sub("y=","",fy)
if(y-fy>0) y = 2*fy-y
}
if(!p[x,y]){
p[x,y] = 1
nm[j++] = x "," y
}
}
delete m; delete p
for(i in nm) m[i] = nm[i]
delete nm
if(fi==0) print "part 1:", j
}
for(i in m){
split(m[i],arr,",")
x = arr[1]; y = arr[2]
if(x>maxx) maxx=x
if(y>maxy) maxy=y
p[x,y] = 1
}
print "part 2:"
for(y=0;y<=maxy;y++){
for(x=0;x<=maxx;x++){
printf "%c", p[x,y] ? "#" : "."
}
print ""
}
}

14
13/Makefile Normal file
View File

@ -0,0 +1,14 @@
1t:
awk -f 13.awk test
1i:
awk -f 13.awk input
2t:
awk -f 13_2.awk test
2i:
awk -f 13_2.awk input
paste:
xclip -sel c -o > test

View File

@ -27,6 +27,7 @@ awk -c -f 01.awk inputfile
```
-------Part 1-------- -------Part 2--------
Day Time Rank Score Time Rank Score
13 02:02:33 9507 0 02:19:53 9225 0 --- started late
12 01:57:59 7241 0 02:16:49 6447 0
11 00:46:21 4284 0 00:49:55 4145 0
10 00:19:04 4202 0 00:28:32 3347 0