Compare commits

...

6 Commits

Author SHA1 Message Date
sejo 19f704f4ee day 22 pt1 stats 2021-12-21 23:55:05 -06:00
sejo 51f807fbfe day 22, pt 1 2021-12-21 23:49:05 -06:00
sejo 64da1ce6d1 stats day 21, pt 1 2021-12-21 09:32:19 -06:00
sejo dc2182e0d1 progress on day 21, pt 2 2021-12-21 01:25:43 -06:00
sejo 7e403be225 day 21, pt 1 2021-12-21 00:30:42 -06:00
sejo 82def2ae0b starting day 19 2021-12-20 23:05:17 -06:00
9 changed files with 355 additions and 0 deletions

44
19/19.awk Normal file
View File

@ -0,0 +1,44 @@
function abs(n){
return (n>=0) ? n : -n
}
function diff(s1, s2){
split(s1,a1,",")
split(s2,a2,",")
sr = ""
for(i in a1)
sr = sr abs(a1[i]-a2[i]) (i<3? "," : "")
return sr
}
function similar(d1, d2){
split(d1,a1,",")
split(d2,a2,",")
if(a1[1]==a2[1] && a1[2]==a2[2] && a1[3]==a2[3]) return 1
if(a1[1]==a2[1] && a1[2]==a2[3] && a1[3]==a2[2]) return 2
if(a1[1]==a2[2] && a1[2]==a2[1] && a1[3]==a2[3]) return 3
if(a1[1]==a2[2] && a1[2]==a2[3] && a1[3]==a2[1]) return 4
if(a1[1]==a2[3] && a1[2]==a2[1] && a1[3]==a2[2]) return 5
if(a1[1]==a2[3] && a1[2]==a2[2] && a1[3]==a2[1]) return 6
return -1
}
BEGIN{
}
NR%2==1{
s1 = $0
next
}
{
r = diff(s1,$0)
diffs[++diffsp] = r
}
END{
print diffsp
for(i=1; i<diffsp; i++){
print diffs[i], diffs[i+1],similar( diffs[i], diffs[i+1] )
}
}

14
19/Makefile Normal file
View File

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

28
21/21.awk Normal file
View File

@ -0,0 +1,28 @@
{
pos[$2] = $5
}
END{
turn = 1
roll= 1
rollcount = 0
do{
r=0
for(i=1;i<=3;i++){
r += roll
roll = roll%100 + 1
rollcount++
}
pos[turn] = 1+(pos[turn]-1+r)%10
score[turn] += pos[turn]
# print roll,turn, pos[turn],score[turn]
turn = (turn==1) ? 2 : 1
}while(score[1]<1000 && score[2]<1000)
if(score[1]>=1000){
print rollcount*score[2]
}
else{
print rollcount*score[1]
}
}

152
21/21_2.awk Normal file
View File

@ -0,0 +1,152 @@
{
pos[$2] = $5
}
END{
for(i=0;i<27;i++){
n2 = int(i/9)
n1 = int( (i%9)/3 )
n0 = int( (i%9)%3 )
sum = n2+n1+n0+3
c[sum]++
print n2+1, n1+1, n0+1, "=", sum
}
print "roll result : amount of times /27"
for(sum in c){
print sum,":",c[sum]
}
for(turn=1;turn<=2;turn++){
print "starting with",pos[turn]
for(i=3;i<=9;i++){
p=pos[turn]; sc=0
print "incrementing",i
for(j=1;j<=15;j++){
p = 1 + (p-1+i)%10
sc+=p
printf "%d ", p
if(sc>=21) break
}
printf ": %d in %d",sc, j
print ""
}
print "----"
}
expn = 6
maxwonturns=0
for(i=0;i<7^expn;i++){
r = i
for(e=0;e<expn;e++){
n[e] = int((r%(7^(e+1)))/7^e)
r -= n[e]
}
printf "running %d: ",i
for(e=expn-1;e>=0;e--){
n[e] += 3
printf "%d ",n[e]
}
print ""
p1 = pos[1]; p2 = pos[2]
s1 = 0; s2 = 0;
nu = 0;
swon = 0
for(j=expn-1;j>=0;j--){
p1 = 1 + (p1-1+n[j])%10
s1 += p1
p2 = 1 + (p2-1+n[j])%10
s2 += p2
nu += c[ n[j] ]
print p1,s1, p2,s2
if(s1>=21){
print "p1 won", s1, nu, expn-j
won[1]++;
wonu[1] += nu
won1[expn-j]++
swon = 1
break
}
if(s2>=21){
print "p2 won", s2, nu, expn-j
wonu[2] += nu
won[2]++
won2[expn-j]++
swon = 1
break
}
}
if(!swon){
print "no one won"
break
} else{
if(maxwonturns<expn-j) maxwonturns=expn-j
}
}
print won[1], won[2], won[1]+won[2], 7^expn
print wonu[1], wonu[2]
print maxwonturns
for(i=1;i<=maxwonturns;i++){
print i,"turns, p1:",won1[i],"p2:",won2[i]
}
exit
turn = 1
roll= 1
rollcount = 0
do{
r=0
for(i=1;i<=3;i++){
r += roll
roll = roll%100 + 1
rollcount++
}
pos[turn] = 1+(pos[turn]-1+r)%10
score[turn] += pos[turn]
# print roll,turn, pos[turn],score[turn]
turn = (turn==1) ? 2 : 1
}while(score[1]<21 && score[2]<21)
print rollcount, score[1], score[2]
}
#roll result : amount of times /27
#3 : 1
#4 : 3
#5 : 6
#6 : 7
#7 : 6
#8 : 3
#9 : 1
# 1 1 1 = 3
# 1 1 2 = 4
# 1 1 3 = 5
# 1 2 1 = 4
# 1 2 2 = 5
# 1 2 3 = 6
# 1 3 1 = 5
# 1 3 2 = 6
# 1 3 3 = 7
# 2 1 1
# 2 1 2
# 2 1 3
# 2 2 1
# 2 2 2
# 2 2 3
# 2 3 1
# 2 3 2
# 2 3 3
# 3 1 1
# 3 1 2
# 3 1 3
# 3 2 1
# 3 2 2
# 3 2 3
# 3 3 1
# 3 3 2
# 3 3 3

14
21/Makefile Normal file
View File

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

37
22/22.awk Normal file
View File

@ -0,0 +1,37 @@
{
state = ($1=="on") ? 1 : 0
split($2,arr,",")
split(arr[1],x,/\.\./)
split(arr[2],y,/\.\./)
split(arr[3],z,/\.\./)
sub(/^.=/,"",x[1])
sub(/^.=/,"",y[1])
sub(/^.=/,"",z[1])
print x[1],x[2],y[1],y[2],z[1],z[2], state
c=0
iz = (strtonum(z[1])<-50) ? -50 : strtonum(z[1])
iy = (strtonum(y[1])<-50) ? -50 : strtonum(y[1])
ix = (strtonum(x[1])<-50) ? -50 : strtonum(x[1])
fz = (strtonum(z[2])>50) ? 50 : strtonum(z[2])
fy = (strtonum(y[2])>50) ? 50 : strtonum(y[2])
fx = (strtonum(x[2])>50) ? 50 : strtonum(x[2])
print iz
for(tz=iz;tz<=fz;tz++){
for(ty=iy;ty<=fy;ty++){
for(tx=ix;tx<=fx;tx++){
# printf "%d,%d,%d:%d\n", tx,ty,tz,state
cube[tx,ty,tz] = state;
c++
}
}
}
print c
}
END{
for(p in cube)
count += cube[p]
print count
}

50
22/22_2.awk Normal file
View File

@ -0,0 +1,50 @@
function size( cu ){
split(cu, c, ",")
return (c[2]-c[1]+1)*(c[4]-c[3]+1)*(c[6]-c[5]+1)
}
function cubestate( cu ){
return substr(cu,length(cu))
}
function intersect(cube1, cube2){
split(cube1,c1,",")
split(cube2,c2,",")
difx = (c1[1]<c2[1]) ? c1[2]-c2[1] + 1 : c2[2] - c1[1] + 1
dify = (c1[3]<c2[3]) ? c1[4]-c2[3] + 1 : c2[4] - c1[3] + 1
difz = (c1[5]<c2[5]) ? c1[6]-c2[5] + 1 : c2[6] - c1[5] + 1
print difx, dify, difz
if(difx>0 && dify>0 && difz>0)
return difx*dify*difz
else
return 0
}
{
state = ($1=="on") ? 1 : 0
split($2,arr,",")
split(arr[1],x,/\.\./)
split(arr[2],y,/\.\./)
split(arr[3],z,/\.\./)
sub(/^.=/,"",x[1])
sub(/^.=/,"",y[1])
sub(/^.=/,"",z[1])
x[1] = strtonum(x[1])
y[1] = strtonum(y[1])
z[1] = strtonum(z[1])
cube[NR] = x[1] "," x[2] "," y[1] "," y[2] "," z[1] "," z[2] "," state
print cube[NR], size(cube[NR]), cubestate(cube[NR])
}
END{
print ""
for(i=1;i<NR;i++){
for(j=i+1;j<=NR;j++){
ints[i,j] = intersect(cube[i],cube[j])
}
}
}

14
22/Makefile Normal file
View File

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

View File

@ -27,6 +27,8 @@ awk -c -f 01.awk inputfile
```
-------Part 1-------- -------Part 2--------
Day Time Rank Score Time Rank Score
22 00:19:18 1596 0 - - -
21 00:29:17 3064 0 - - -
20 12:59:28 11947 0 13:14:02 11669 0 --- same as 18
18 >24h 16659 0 >24h 16484 0 --- solved it afterwards
17 00:41:03 2839 0 00:56:57 2841 0