Compare commits
2 Commits
cd213c0eea
...
3a71c63507
Author | SHA1 | Date |
---|---|---|
sejo | 3a71c63507 | |
sejo | 23efe48a10 |
|
@ -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
|
||||
}
|
|
@ -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
|
||||
|
||||
}
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
Loading…
Reference in New Issue