advent2020/thirteen.txt

36 lines
1.0 KiB
Plaintext

$ time tail -1 input13 |gawk -M 'function nxt(i,j,tgt,inc) {while((i+j)%tgt) i+=inc; return i} BEGIN {RS=",";i=0;inc=1} !/x/ {i=nxt(i,NR-1,$1,inc); inc*=$1; print i}'
0
779
481668
7955927
140192817
655916688
21112963571
37989391978419
840493039281088
real 0m0.004s
user 0m0.000s
sys 0m0.004s
$ time { tr , \\n |gawk -M 'function n(i,j,t,c) {while((i+j)%t) i+=c; return i} !/x/ {i=n(i,NR-1,$1,c); c=$1*(c?c:1); print i}'; } <<<41,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,37,x,x,x,x,x,379,x,x,x,x,x,x,x,23,x,x,x,x,13,x,x,x,17,x,x,x,x,x,x,x,x,x,x,x,29,x,557,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,19
$ { tr , \\n |gawk -M 'function n(i,j,t,c) {
while((i+j)%t) i+=c;
return i
}
!/x/ {
i=n(i,NR-1,$1,c);
c=$1*(c?c:1);
print i
}'; } <<<41,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,37,x,x,x,x,x,379,x,x,x,x,x,x,x,23,x,x,x,x,13,x,x,x,17,x,x,x,x,x,x,x,x,x,x,x,29,x,557,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,19
779
481668
7955927
140192817
655916688
21112963571
37989391978419
840493039281088