Anonymous user
Solve the no connection puzzle: Difference between revisions
→{{header|M2000 Interpreter}}
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:
=={{header|M2000 Interpreter}}==
Final Version, print all solutions (16 from 40320 permutations)
Press space bar to see solutions so far.
<lang M2000 Interpreter>
Module no_connection_puzzle {
Line 1,297 ⟶ 1,299:
Inventory Connections="A":="CDE","B":="DEF","C":="ADG", "D":="ABCEGH"
Append Connections, "E":="ABDFGH","F":="HEB", "G":="CDE","H":="DEF"
Inventory ToDelete, Solutions
\\ eliminate double
con=each(Connections)
While con {
m$=eval$(con, con^)
c$=eval$(con)
for i=1 to len(C$) {
d$=mid$(c$,i,1)
if d$="*" then continue
r$=Filter$(Connections$(d$), m$)
} else
Return connections, d$:=
}
}
}
▲ }
con=each(todelete)
While con {
Delete Connections, eval$(con)
}
Inventory Holes
Line 1,324 ⟶ 1,334:
=res
}
a=(1
h=(,)
solution=(,)
done=false
counter=0
Print "Waut..."
P(h, a)
While sol {
Print "Solution:";sol^+1
Disp(Eval(Solutions))
aa$=key$
}
Sub P(h, a)
if len(a)<=1 then process(cons(h, a)) : exit sub
local b=cons(a)
Line 1,338 ⟶ 1,353:
b=cons(cdr(b),car(b))
P(cons(h,car(b)), cdr(b))
▲ if done then exit
}
End sub
Sub Process(a)
if keypress(32) then {
local sol=Each(Solutions)
While sol {
Print "Solution:";sol^+1
Disp(Eval(Solutions))
aa$=key$
}
}
hole=each(Connections)
done=True
While hole {
if not CheckValid(Eval$(hole, hole^), a) then done=false : exit
}
if done then
end sub
Sub Disp(a)
Line 1,363 ⟶ 1,386:
}
no_connection_puzzle
</lang>
{{out}}
|