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 |
\\ 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 c$="*" Then continue |
|||
For i=1 to len(C$) { |
|||
d$=mid$(c$,i,1) |
|||
r$=Filter$(Connections$(d$), m$) |
|||
r$ |
If r$<>"" Then { |
||
⚫ | |||
Return connections, d$:=r$ |
Return connections, d$:=r$ |
||
} else { |
} else { |
||
If m$=connections$(d$) Then { |
|||
Return connections, 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= |
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 |
|||
} |
} |
||
=res |
=res |
||
Line 1,337: | Line 1,336: | ||
h=(,) |
h=(,) |
||
solution=(,) |
solution=(,) |
||
done= |
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$= |
aa$=Key$ |
||
} |
} |
||
Sub P(h, a) |
Sub P(h, a) |
||
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 |
End Sub |
||
Sub Process(a) |
Sub Process(a) |
||
counter++ |
counter++ |
||
Print counter |
Print counter |
||
If keypress(32) Then { |
|||
local sol=Each(Solutions) |
local sol=Each(Solutions) |
||
⚫ | |||
While sol { |
While sol { |
||
Print "Solution:";sol^+1 |
Print "Solution:";sol^+1 |
||
Disp(Eval(Solutions)) |
Disp(Eval(Solutions)) |
||
aa$= |
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 done Then Append Solutions, Len(Solutions):=a : Print a |
|||
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 |
End Sub |
||
} |
} |
||
no_connection_puzzle |
no_connection_puzzle |