Solve the no connection puzzle: Difference between revisions
Content deleted Content added
m added whitespace and highlighting, minimized the word "to", added two section header (;Objective: and ;Example:), used better glyphs for the two diagrams, |
|||
Line 1,291: | Line 1,291: | ||
=={{header|M2000 Interpreter}}== |
=={{header|M2000 Interpreter}}== |
||
Final Version, print all solutions (16 from 40320 permutations) |
|||
Addition a reducing algorithm for double connections, if A has D then from D we remove A unless D has only A so we remove D from A, unless A has only D. |
|||
Press space bar to see solutions so far. |
|||
<lang M2000 Interpreter> |
<lang M2000 Interpreter> |
||
Module no_connection_puzzle { |
Module no_connection_puzzle { |
||
Line 1,297: | Line 1,299: | ||
Inventory Connections="A":="CDE","B":="DEF","C":="ADG", "D":="ABCEGH" |
Inventory Connections="A":="CDE","B":="DEF","C":="ADG", "D":="ABCEGH" |
||
Append Connections, "E":="ABDFGH","F":="HEB", "G":="CDE","H":="DEF" |
Append Connections, "E":="ABDFGH","F":="HEB", "G":="CDE","H":="DEF" |
||
Inventory ToDelete, Solutions |
|||
⚫ | |||
\\ eliminate double |
\\ eliminate double connnections |
||
con=each(Connections) |
|||
While con { |
While con { |
||
m$=eval$(con, con^) |
m$=eval$(con, con^) |
||
c$=eval$(con) |
c$=eval$(con) |
||
⚫ | |||
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 { |
|||
Return connections, d$:=r$ |
|||
} else { |
|||
if m$=connections$(d$) then { |
|||
Return connections, d$:= |
Return connections, d$:="*" : if not exist(todelete, d$) then Append todelete, d$ |
||
} |
|||
} |
} |
||
} |
} |
||
⚫ | |||
con=each(todelete) |
|||
While con { |
|||
Delete Connections, eval$(con) |
|||
} |
} |
||
Inventory Holes |
Inventory Holes |
||
Line 1,324: | Line 1,334: | ||
=res |
=res |
||
} |
} |
||
a=(1 |
a=(1,2,3,4,5,6,7,8) |
||
h=(,) |
h=(,) |
||
solution=(,) |
solution=(,) |
||
done=false |
done=false |
||
counter=0 |
|||
Print "Waut..." |
Print "Waut..." |
||
P(h, a) |
P(h, a) |
||
sol=Each(Solutions) |
|||
While sol { |
|||
Print "Solution:";sol^+1 |
|||
Disp(Eval(Solutions)) |
|||
aa$=key$ |
|||
} |
|||
Sub P(h, a) |
Sub P(h, a) |
||
if done then exit sub |
|||
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) |
||
Line 1,338: | Line 1,353: | ||
b=cons(cdr(b),car(b)) |
b=cons(cdr(b),car(b)) |
||
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++ |
|||
Print counter |
|||
if keypress(32) then { |
|||
local sol=Each(Solutions) |
|||
While sol { |
|||
Print "Solution:";sol^+1 |
|||
Disp(Eval(Solutions)) |
|||
aa$=key$ |
|||
} |
|||
} |
|||
hole=each(Connections) |
|||
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 |
if done then Append Solutions, Len(Solutions):=a : Print a |
||
end sub |
end sub |
||
Sub Disp(a) |
Sub Disp(a) |
||
Line 1,363: | Line 1,386: | ||
} |
} |
||
no_connection_puzzle |
no_connection_puzzle |
||
</lang> |
</lang> |
||
{{out}} |
{{out}} |