4-rings or 4-squares puzzle: Difference between revisions

→‎{{header|ALGOL 68}}: Simplify - once a, b and c are have values, there is only one possible value for d, similarly once e is decided, there f and g are known
(→‎JavaScript ES6: Updated primitives, tidied.)
(→‎{{header|ALGOL 68}}: Simplify - once a, b and c are have values, there is only one possible value for d, similarly once e is decided, there f and g are known)
Line 637:
# where a, b, c, d, e, f, g in lo : hi ( not necessarily unique ) #
# depending on show, the solutions will be printed or not #
PROC four rings = ( INT lo, hi, BOOL uniqueallow duplicates, show )VOID:
BEGIN
INT solutions := 0;
BOOL allow duplicates = NOT unique;
# calculate field width for printinhg solutions #
INT width := -1;
Line 655 ⟶ 654:
FOR c FROM lo TO hi DO
IF allow duplicates OR ( a /= c AND b /= c ) THEN
FORINT d FROM= lot TO- hi( DOb + c );
IF allow duplicatesd OR ( a />= dlo AND b /= d AND c /<= d )hi
AND ( allow THENduplicates
OR ( a /= IFd AND b +/= cd +AND dc /= td THEN)
FOR e FROM lo TO hi DO)
IF allow duplicatesTHEN
OR ( a /=FOR e ANDFROM blo /=TO e AND c /= e AND d /= ehi )DO
IF allow THENduplicates
OR ( a /= e AND b /= e AND c /= FORe fAND FROMd lo/= TOe hi DO)
IF allow duplicatesTHEN
INT g OR ( a /= f AND b /= f AND c /= f AND d /= f AND+ e /= f );
INT f = t - THENg;
IF f >= lo IF d + e +AND f <= t THENhi
AND g >= lo FORAND g FROM lo TO<= hi DO
AND ( IF allow duplicates
OR ( OR ( a /= gf AND b /= gf AND c /= g AND d /= g AND e /= g AND f /= g )
AND d /= f AND e /= THENf
AND a /= g AND b /= g AND c IF f +/= g = t THEN
AND d /= g AND e /= g AND f solutions +:/= 1;g
IF show THEN)
print( ( whole( a, width ), whole( b, width )
, whole( c, width ), whole( d, width )THEN
solutions +:= , whole( e, width ), whole( f, width )1;
IF show , whole( g, width ), newlineTHEN
print( ( whole( a, width ), whole( b, width )
, whole( c, width ), whole( d, width )
, whole( e, width ), whole( f, width FI)
, whole( g, width ), FInewline
FI)
OD # g #)
FI
FI
OD # f #
FI
OD # e #FI
FI
FIOD # e #
OD # d #FI
FI
OD # c #
Line 699 ⟶ 695:
OD # a # ;
print( ( whole( solutions, 0 )
, IF uniqueallow duplicates THEN " non-unique" ELSE " non-unique" FI
, " solutions in "
, whole( lo, 0 )
Line 711 ⟶ 707:
 
# find the solutions as required for the task #
four rings( 1, 7, TRUEFALSE, TRUE );
four rings( 3, 9, TRUEFALSE, TRUE );
four rings( 0, 9, FALSETRUE, FALSE )
END</lang>
{{out}}
3,037

edits