Solve the no connection puzzle: Difference between revisions

Content added Content deleted
Line 1,300: Line 1,300:
Append Connections, "E":="ABDFGH","F":="HEB", "G":="CDE","H":="DEF"
Append Connections, "E":="ABDFGH","F":="HEB", "G":="CDE","H":="DEF"
Inventory ToDelete, Solutions
Inventory ToDelete, Solutions
\\ eliminate double connections
\\ eliminate double connnections
con=each(Connections)
con=each(Connections)
While con {
While con {
m$=eval$(con, con^)
m$=eval$(con, con^)
c$=eval$(con)
c$=eval$(con)
if len(c$)=0 then continue
If c$="*" Then continue
for i=1 to len(C$) {
For i=1 to len(C$) {
d$=mid$(c$,i,1)
d$=mid$(c$,i,1)
if d$="*" then continue
r$=Filter$(Connections$(d$), m$)
r$=Filter$(Connections$(d$), m$)
If r$<>"" Then {
if r$<>"" then {
Return connections, d$:=r$
Return connections, d$:=r$
} else {
} else {
if m$=connections$(d$) then {
If m$=connections$(d$) Then {
Return connections, d$:="*" : if not exist(todelete, d$) then Append todelete, d$
Return connections, d$:="*" : If not exist(todelete, d$) Then Append todelete, d$
}
}
}
}
Line 1,328: Line 1,327:
val=Array(arr, Holes(a$))
val=Array(arr, Holes(a$))
con$=Connections$(a$)
con$=Connections$(a$)
res=true
res=True
For i=1 to Len(con$) {
For i=1 to Len(con$) {
if Abs(Array(Arr, Holes(mid$(con$,i,1)))-val)<2 then res=false: exit
If Abs(Array(Arr, Holes(mid$(con$,i,1)))-val)<2 Then res=False: Exit
}
}
=res
=res
Line 1,337: Line 1,336:
h=(,)
h=(,)
solution=(,)
solution=(,)
done=false
done=False
counter=0
counter=0
Print "Waut..."
Print "Waut..."
Line 1,345: Line 1,344:
Print "Solution:";sol^+1
Print "Solution:";sol^+1
Disp(Eval(Solutions))
Disp(Eval(Solutions))
aa$=key$
aa$=Key$
}
}
Sub P(h, a)
Sub P(h, a)
if len(a)<=1 then process(cons(h, a)) : exit sub
If len(a)<=1 Then process(cons(h, a)) : Exit Sub
local b=cons(a)
local b=cons(a)
For i=1 to len(b) {
For i=1 to len(b) {
Line 1,354: Line 1,353:
P(cons(h,car(b)), cdr(b))
P(cons(h,car(b)), cdr(b))
}
}
End sub
End Sub
Sub Process(a)
Sub Process(a)
counter++
counter++
Print counter
Print counter
if keypress(32) then {
If keypress(32) Then {
local sol=Each(Solutions)
local sol=Each(Solutions)
aa$=Key$
While sol {
While sol {
Print "Solution:";sol^+1
Print "Solution:";sol^+1
Disp(Eval(Solutions))
Disp(Eval(Solutions))
aa$=key$
aa$=Key$
}
}
}
}
Line 1,369: Line 1,369:
done=True
done=True
While hole {
While hole {
if not CheckValid(Eval$(hole, hole^), a) then done=false : exit
If not CheckValid(Eval$(hole, hole^), a) Then done=False : Exit
}
}
if done then Append Solutions, Len(Solutions):=a : Print a
If done Then Append Solutions, Len(Solutions):=a : Print a
end sub
End Sub
Sub Disp(a)
Sub Disp(a)
Print format$(" {0} {1}", array(a), array(a,1))
Print format$(" {0} {1}", array(a), array(a,1))
Line 1,383: Line 1,383:
Print " \|/ \|/"
Print " \|/ \|/"
Print Format$(" {0} {1}", array(a,6), array(a,7))
Print Format$(" {0} {1}", array(a,6), array(a,7))
End sub
End Sub
}
}
no_connection_puzzle
no_connection_puzzle