Compare commits

...

2 Commits

Author SHA1 Message Date
sejo 3a71c63507 stats for day 12 2021-12-12 01:19:19 -06:00
sejo 23efe48a10 day 12! 2021-12-12 01:18:48 -06:00
8 changed files with 347 additions and 0 deletions

72
12/12.awk Normal file
View File

@ -0,0 +1,72 @@
# queue
function enq( d ){
q[tail++] = d
}
function deq(){
return q[head++]
}
function peek(){
return q[head]
}
function qempty(){
return head>=tail
}
# paths
function linkedto(path, d ){
t = path
gsub(d,"",t)
gsub("-","",t)
return t
}
function dests(arr,node){
delete arr
p=0
for( i in path ){
if(path[i]~node){
arr[p++] = linkedto(path[i],node)
}
}
}
function hasduplicate( str ){ # true if lowercase duplicates
split(str, arr, ",")
for(i in arr){
if( tolower(arr[i]) == arr[i]){
for( j in arr ){
if (i!=j && arr[i] == arr[j])
return 1
}
}
}
return 0
}
{
path[NR] = $0
}
END{
s = "start"
enq(s)
do{
if(peek()~"end"){
stack[sp++] = deq() # done
}
else if(hasduplicate(peek())){
deq()
}
else if(!qempty()){
s=deq(); #print "deq:", s, head, tail
split(s, arr, ",")
nd = arr[length(arr)]
dests(a, nd)
for(i in a){
enq( s "," a[i] )
# print "enq:", s "," a[i]
}
}
}while(!qempty())
# for(i in stack) print stack[i]
print sp
}

80
12/12_2.awk Normal file
View File

@ -0,0 +1,80 @@
# queue
function enq( d ){
q[tail++] = d
}
function deq(){
return q[head++]
}
function peek(){
return q[head]
}
function qempty(){
return head>=tail
}
# paths
function linkedto(path, d ){
t = path
gsub(d,"",t)
gsub("-","",t)
return t
}
function dests(arr,node){
delete arr
p=0
for( i in path ){
if(path[i]~node){
arr[p++] = linkedto(path[i],node)
}
}
}
function hasduplicate( str ){ # new rule for part 2
split(str, arr, ",")
sing = 0
for(i in arr){
if( tolower(arr[i]) == arr[i]){ # if lowercase
count = 0
for( j in arr ){
if (i!=j && arr[i] == arr[j]) count++
}
if( arr[i]=="start" ){
if(count>0) return 1
} else{
if(count>0) sing++
if(count>1 || sing>2) return 1
}
}
}
return 0
}
{
path[NR] = $0
}
END{
s = "start"
enq(s)
do{
if(peek()~"end"){
stack[sp++] = deq() # done
}
else if(hasduplicate(peek())){
deq()
}
else if(!qempty()){
s=deq()
split(s, arr, ",")
nd = arr[length(arr)]
dests(a, nd)
for(i in a){
enq( s "," a[i] )
}
}
}while(!qempty())
# for(i in stack) print stack[i]
print sp
}

14
12/Makefile Normal file
View File

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

36
12/paths Normal file
View File

@ -0,0 +1,36 @@
start,A,b,A,b,A,c,A,end
start,A,b,A,b,A,end
start,A,b,A,b,end
start,A,b,A,c,A,b,A,end
start,A,b,A,c,A,b,end
start,A,b,A,c,A,c,A,end
start,A,b,A,c,A,end
start,A,b,A,end
start,A,b,d,b,A,c,A,end
start,A,b,d,b,A,end
start,A,b,d,b,end
start,A,b,end
start,A,c,A,b,A,b,A,end
start,A,c,A,b,A,b,end
start,A,c,A,b,A,c,A,end
start,A,c,A,b,A,end
start,A,c,A,b,d,b,A,end
start,A,c,A,b,d,b,end
start,A,c,A,b,end
start,A,c,A,c,A,b,A,end
start,A,c,A,c,A,b,end
start,A,c,A,c,A,end
start,A,c,A,end
start,A,end
start,b,A,b,A,c,A,end
start,b,A,b,A,end
start,b,A,b,end
start,b,A,c,A,b,A,end
start,b,A,c,A,b,end
start,b,A,c,A,c,A,end
start,b,A,c,A,end
start,b,A,end
start,b,d,b,A,c,A,end
start,b,d,b,A,end
start,b,d,b,end
start,b,end

54
12/pathso Normal file
View File

@ -0,0 +1,54 @@
start,A,end
start,b,end
start,A,b,end
start,b,A,end
start,A,c,A,end
start,A,b,A,end
start,b,A,b,end
start,b,d,b,end
start,A,c,A,b,end
start,A,b,A,b,end
start,A,b,d,b,end
start,b,A,c,A,end
start,b,A,b,A,end
start,b,d,b,A,end
start,A,c,A,c,A,end
start,A,c,A,b,A,end
start,A,b,A,c,A,end
start,A,b,A,b,A,end
start,A,b,d,b,A,end
start,b,A,c,A,b,end
start,A,c,A,c,A,b,end
start,A,c,A,b,A,b,end
start,A,c,A,b,d,b,end
start,A,b,A,c,A,b,end
start,b,A,c,A,c,A,end
start,b,A,c,A,b,A,end
start,b,A,b,A,c,A,end
start,b,d,b,A,c,A,end
start,A,c,A,c,A,b,A,end
start,A,c,A,b,A,c,A,end
start,A,c,A,b,A,b,A,end
start,A,c,A,b,d,b,A,end
start,A,b,A,c,A,c,A,end
start,A,b,A,c,A,b,A,end
start,A,b,A,b,A,c,A,end
start,A,b,d,b,A,c,A,end
start,b,A,c,A,c,A,b,end
start,A,c,A,c,A,b,A,b,end
start,A,c,A,c,A,b,d,b,end
start,A,c,A,b,A,c,A,b,end
start,A,b,A,c,A,c,A,b,end
start,b,A,c,A,c,A,b,A,end
start,b,A,c,A,b,A,c,A,end
start,b,A,b,A,c,A,c,A,end
start,b,d,b,A,c,A,c,A,end
start,A,c,A,c,A,b,A,b,A,end
start,A,c,A,c,A,b,d,b,A,end
start,A,c,A,b,A,c,A,b,A,end
start,A,c,A,b,A,b,A,c,A,end
start,A,c,A,b,d,b,A,c,A,end
start,A,b,A,c,A,c,A,b,A,end
start,A,b,A,c,A,b,A,c,A,end
start,A,b,A,b,A,c,A,c,A,end
start,A,b,d,b,A,c,A,c,A,end

36
12/spaths Normal file
View File

@ -0,0 +1,36 @@
start,A,b,A,b,A,c,A,end
start,A,b,A,b,A,end
start,A,b,A,b,end
start,A,b,A,c,A,b,A,end
start,A,b,A,c,A,b,end
start,A,b,A,c,A,c,A,end
start,A,b,A,c,A,end
start,A,b,A,end
start,A,b,d,b,A,c,A,end
start,A,b,d,b,A,end
start,A,b,d,b,end
start,A,b,end
start,A,c,A,b,A,b,A,end
start,A,c,A,b,A,b,end
start,A,c,A,b,A,c,A,end
start,A,c,A,b,A,end
start,A,c,A,b,d,b,A,end
start,A,c,A,b,d,b,end
start,A,c,A,b,end
start,A,c,A,c,A,b,A,end
start,A,c,A,c,A,b,end
start,A,c,A,c,A,end
start,A,c,A,end
start,A,end
start,b,A,b,A,c,A,end
start,b,A,b,A,end
start,b,A,b,end
start,b,A,c,A,b,A,end
start,b,A,c,A,b,end
start,b,A,c,A,c,A,end
start,b,A,c,A,end
start,b,A,end
start,b,d,b,A,c,A,end
start,b,d,b,A,end
start,b,d,b,end
start,b,end

54
12/spathso Normal file
View File

@ -0,0 +1,54 @@
start,A,b,A,b,A,c,A,c,A,end
start,A,b,A,b,A,c,A,end
start,A,b,A,b,A,end
start,A,b,A,b,end
start,A,b,A,c,A,b,A,c,A,end
start,A,b,A,c,A,b,A,end
start,A,b,A,c,A,b,end
start,A,b,A,c,A,c,A,b,A,end
start,A,b,A,c,A,c,A,b,end
start,A,b,A,c,A,c,A,end
start,A,b,A,c,A,end
start,A,b,A,end
start,A,b,d,b,A,c,A,c,A,end
start,A,b,d,b,A,c,A,end
start,A,b,d,b,A,end
start,A,b,d,b,end
start,A,b,end
start,A,c,A,b,A,b,A,c,A,end
start,A,c,A,b,A,b,A,end
start,A,c,A,b,A,b,end
start,A,c,A,b,A,c,A,b,A,end
start,A,c,A,b,A,c,A,b,end
start,A,c,A,b,A,c,A,end
start,A,c,A,b,A,end
start,A,c,A,b,d,b,A,c,A,end
start,A,c,A,b,d,b,A,end
start,A,c,A,b,d,b,end
start,A,c,A,b,end
start,A,c,A,c,A,b,A,b,A,end
start,A,c,A,c,A,b,A,b,end
start,A,c,A,c,A,b,A,end
start,A,c,A,c,A,b,d,b,A,end
start,A,c,A,c,A,b,d,b,end
start,A,c,A,c,A,b,end
start,A,c,A,c,A,end
start,A,c,A,end
start,A,end
start,b,A,b,A,c,A,c,A,end
start,b,A,b,A,c,A,end
start,b,A,b,A,end
start,b,A,b,end
start,b,A,c,A,b,A,c,A,end
start,b,A,c,A,b,A,end
start,b,A,c,A,b,end
start,b,A,c,A,c,A,b,A,end
start,b,A,c,A,c,A,b,end
start,b,A,c,A,c,A,end
start,b,A,c,A,end
start,b,A,end
start,b,d,b,A,c,A,c,A,end
start,b,d,b,A,c,A,end
start,b,d,b,A,end
start,b,d,b,end
start,b,end

View File

@ -27,6 +27,7 @@ awk -c -f 01.awk inputfile
```
-------Part 1-------- -------Part 2--------
Day Time Rank Score Time Rank Score
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
9 00:12:52 2598 0 00:55:08 4504 0