Compare commits
3 Commits
6f1ac45a15
...
12cc89de34
Author | SHA1 | Date |
---|---|---|
sejo | 12cc89de34 | |
sejo | d39dc8b14b | |
sejo | 7fb110a3cc |
|
@ -0,0 +1,51 @@
|
|||
BEGIN{ RS = "" }
|
||||
NR==1{
|
||||
template = $0
|
||||
RS ="\n"
|
||||
next
|
||||
}
|
||||
{
|
||||
pair[NR] = $1
|
||||
ins[NR] = $3
|
||||
}
|
||||
END{
|
||||
|
||||
for(s=1;s<=10;s++){
|
||||
sp=0; delete toins; delete st
|
||||
for(i=1;i<length(template);i++){
|
||||
p = substr(template,i,2)
|
||||
for(k in pair){
|
||||
if(pair[k]==p){
|
||||
st[sp] = i
|
||||
toins[sp++] = ins[k]
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
nt = ""
|
||||
for(i=1;i<=length(template);i++){
|
||||
nt = nt substr(template,i,1)
|
||||
for(j in st) if(st[j]==i) nt = nt toins[j]
|
||||
}
|
||||
print length(nt)
|
||||
template = nt
|
||||
}
|
||||
min = length(template)
|
||||
max = 0
|
||||
for(i=1;i<=length(template);i++){
|
||||
c = substr(template,i,1)
|
||||
count[c]++
|
||||
if(count[c]>max){
|
||||
max = count[c]
|
||||
maxc = c
|
||||
}
|
||||
}
|
||||
for(c in count){
|
||||
if(count[c]<min){
|
||||
min = count[c]
|
||||
minc = c
|
||||
}
|
||||
}
|
||||
print max, maxc, min, minc
|
||||
print max-min
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
BEGIN{ RS = "" }
|
||||
NR==1{
|
||||
template = $0
|
||||
RS ="\n"
|
||||
next
|
||||
}
|
||||
{ ins[$1] = $3 }
|
||||
|
||||
END{
|
||||
# setup
|
||||
for(i=1;i<length(template);i++){
|
||||
p = substr(template,i,2)
|
||||
paircount[p]++
|
||||
}
|
||||
# iterate
|
||||
for(s=1;s<=40;s++){
|
||||
delete newpaircount; delete countl; delete countr
|
||||
for(p in paircount){
|
||||
n = paircount[p]
|
||||
c1 = substr(p,1,1)
|
||||
c2 = substr(p,2,1)
|
||||
toins = ins[p]
|
||||
# print p, c1, toins, c2, n
|
||||
newpaircount[c1 toins]+=n
|
||||
newpaircount[toins c2]+=n
|
||||
countl[c1]+=n
|
||||
countr[toins]+=n
|
||||
countl[toins]+=n
|
||||
countr[c2]+=n
|
||||
}
|
||||
delete paircount
|
||||
for(p in newpaircount) paircount[p] = newpaircount[p]
|
||||
|
||||
min = 999999999999
|
||||
max = 0
|
||||
for(c in countl){
|
||||
count[c] = countl[c]>countr[c] ? countl[c] : countr[c]
|
||||
if(count[c]>max) max=count[c]
|
||||
if(count[c]<min) min=count[c]
|
||||
}
|
||||
if(s==10) print "part 1: ", max-min
|
||||
if(s==40) print "part 2: ", max-min
|
||||
}
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
1t:
|
||||
awk -f 14.awk test
|
||||
|
||||
1i:
|
||||
awk -f 14.awk input
|
||||
|
||||
2t:
|
||||
awk -f 14_2.awk test
|
||||
|
||||
2i:
|
||||
awk -f 14_2.awk input
|
||||
|
||||
paste:
|
||||
xclip -sel c -o > test
|
|
@ -27,6 +27,7 @@ awk -c -f 01.awk inputfile
|
|||
```
|
||||
-------Part 1-------- -------Part 2--------
|
||||
Day Time Rank Score Time Rank Score
|
||||
14 00:27:53 4878 0 01:07:47 3311 0
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue