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
BEGIN
INT solutions := 0;
# 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
AND ( allow
OR ( a /=
IF allow
OR ( a /= e AND b /= e AND c /=
INT g
INT f = t -
IF f >= lo
AND g >= lo
AND (
OR (
AND d /= f AND e /=
AND a /= g AND b /= g AND c
AND d /= g AND e /= g AND f
solutions +:=
IF show
print( ( whole( a, width ), whole( b,
, whole( c, width ), whole( d,
, whole( e, width ), whole( f, width
, whole( g, width ),
FI
FI
FI
OD # c #
Line 699 ⟶ 695:
OD # a # ;
print( ( whole( solutions, 0 )
, IF
, " solutions in "
, whole( lo, 0 )
Line 711 ⟶ 707:
# find the solutions as required for the task #
four rings( 1, 7,
four rings( 3, 9,
four rings( 0, 9,
END</lang>
{{out}}
|