Anonymous user
Solve the no connection puzzle: Difference between revisions
m
→unannotated solutions: added/changed comments, whitespace, and indentations.
m (J: kibitz) |
m (→unannotated solutions: added/changed comments, whitespace, and indentations.) |
||
Line 1,367:
=={{header|REXX}}==
===unannotated solutions===
<lang rexx>/*REXX program solves the "no-connection" puzzle (
parse arg limit .
if limit=='' | lim=t''"." then limit=1 /* ║ A B ║ */
/* ║ /│\ /│\ ║ */
@. = /* ║ / │ \/ │ \ ║ */
@.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. */
_=' ' /*_ is used for
do a=1 for pegs;
do b=1 for pegs;
do c=1 for pegs;
do d=1 for pegs;
do e=1 for pegs; if ?('E') then iterate
do f=1 for pegs; if ?('F') then iterate
do g=1 for pegs; if ?('G') then iterate
do h=1 for pegs; if ?('H') then iterate
say _ 'a='a _ 'b='||b _ 'c='c _ 'd='d _ 'e='e _ 'f='f _ 'g='g _ 'h='h
cnt=cnt+1; if cnt==limit then leave a
end /*h*/
end /*g*/
Line 1,409:
end /*b*/
end /*a*/
say /*display a blank line to the screen. */
s=left('s',cnt\==1) /*handle the case of plurals (or not). */
say 'found ' cnt " solution"s'.' /*display the number of solutions found.*/
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
?:
nH=nn+1
do cn=c2d('A') to c2d(node)-1; if value( d2c(cn) )==nn then return 1
/* [↑] see if any are duplicates*/▼
nL=nn-1
'''output''' when using the default input:▼
return 0 /*the subroutine arg value passed is OK.*/</lang>
▲'''output''' when using the default input:
<pre>
a=3 b=4 c=7 d=1 e=8 f=2 g=5 h=6
Line 1,429 ⟶ 1,431:
</pre>
'''output''' when using the input of: <tt> 999 </tt>
<pre>
a=3 b=4 c=7 d=1 e=8 f=2 g=5 h=6
|