Anonymous user
Solve the no connection puzzle: Difference between revisions
m
→unannotated solutions: added/changed comments, whitespace, and indentations.
m (→unannotated solutions: added/changed comments and whitespace.) |
m (→unannotated solutions: added/changed comments, whitespace, and indentations.) |
||
Line 1,454:
===annotated solutions===
<lang rexx>/*REXX program solves the "no-connection" puzzle (
@abc='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
parse arg limit .
if limit=='' | limit=="." then limit=1 /* ║ A B ║ */
oLimit=limit; limit=abs(limit) /* ║ /│\ /│\ ║ */
@. = /* ║ / │ \/ │ \ ║ */
@.1 = 'A C D E' /* ║ / │ /\ │ \ ║ */
@.2 = 'B D E F' /* ║ / │/ \│ \ ║ */
@.3 = 'C A D G' /* ║ C────D────E────F ║ */
@.4 = 'D A B C E G' /* ║ \ │\ /│ / ║ */
@.5 = 'E A B D F H' /* ║ \ │ \/ │ / ║ */
@.6 = 'F B E G' /* ║ \ │ /\ │ / ║ */
@.7 = 'G C D E' /* ║ \│/ \│/ ║ */
@.8 = 'H D E F' /* ║ G H ║ */
cnt=0 /* ╚═══════════════════════════╝ */
pegs=nodes-1 /*the number of pegs to be seated. */
_=' '
do
do
do
do
do
do
do
do h=1 for pegs;
call
cnt=cnt+1;
/*──────────────────────────────────────────────────────────────────────────────────────*/
?:
nH=nn+1
▲ /* [↑] see if any are duplicates*/
nL=nn-1
if nL==fn | nH==fn then return 1 /*if ≡ ±1, then it can't be used.*/▼
/*──────────────────────────────────────────────────────────────────────────────────────*/
showNodes: _=' ' /*_ is used for padding the output. */
do box=1 for sourceline() while oLimit<0 /*Negative? Then show it*/▼
show=0
xt=xb
do jx=1 for pegs /*do a substitution for all the pegs. */
say _ xb _ _ xt /*display one line of the graph. */
end /*box*/▼
if pos('╝', xw)\==0 then
▲ end /*box*/
say _ 'a='a _ 'b='||b _ 'c='c _ 'd='d _ ' e='e _ 'f='f _ 'g='g _ 'h='h
'''output''' when the input is: <tt> -1 </tt>▼
return</lang>
▲'''output''' when the input used is: <tt> -1 </tt>
<pre>
╔═══════════════════════════╗ ╔═══════════════════════════╗
|