How to resolve the algorithm 4-rings or 4-squares puzzle step by step in the Action! programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm 4-rings or 4-squares puzzle step by step in the Action! programming language
Table of Contents
Problem Statement
Replace a, b, c, d, e, f, and g with the decimal digits LOW ───► HIGH such that the sum of the letters inside of each of the four large squares add up to the same sum. Show all output here.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm 4-rings or 4-squares puzzle step by step in the Action! programming language
Source code in the action! programming language
;;; solve the 4 rings or 4 squares puzzle
DEFINE TRUE = "1", FALSE = "0"
;;; finds solutions to the equations:
;;; a + b = b + c + d = d + e + f = f + g
;;; 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 fourRings( INT lo, hi BYTE allowDuplicates, show )
INT solutions, t, a, b, c, d, e, f, g, uniqueOrNot
solutions = 0
FOR a = lo TO hi DO
FOR b = lo TO hi DO
IF allowDuplicates OR a <> b THEN
t = a + b
FOR c = lo TO hi DO
IF allowDuplicates OR ( a <> c AND b <> c ) THEN
d = t - ( b + c )
IF d >= lo AND d <= hi
AND ( allowDuplicates OR ( a <> d AND b <> d AND c <> d ) )
THEN
FOR e = lo TO hi DO
IF allowDuplicates
OR ( a <> e AND b <> e AND c <> e AND d <> e )
THEN
g = d + e
f = t - g
IF f >= lo AND f <= hi
AND g >= lo AND g <= hi
AND ( allowDuplicates
OR ( a <> f AND b <> f AND c <> f
AND d <> f AND e <> f
AND a <> g AND b <> g AND c <> g
AND d <> g AND e <> g AND f <> g
)
)
THEN
solutions ==+ 1
IF show THEN
PrintF( " %U %U %U %U", a, b, c, d )
PrintF( " %U %U %U%E", e, f, g )
FI
FI
FI
OD
FI
FI
OD
FI
OD
OD
IF allowDuplicates
THEN uniqueOrNot = "non-unique"
ELSE uniqueOrNot = "unique"
FI
PrintF( "%U %S solutions in %U to %U%E%E", solutions, uniqueOrNot, lo, hi )
RETURN
;;; find the solutions as required for the task
PROC Main()
fourRings( 1, 7, FALSE, TRUE )
fourRings( 3, 9, FALSE, TRUE )
fourRings( 0, 9, TRUE, FALSE )
RETURN
You may also check:How to resolve the algorithm Respond to an unknown method call step by step in the Go programming language
You may also check:How to resolve the algorithm Pick random element step by step in the Fortran programming language
You may also check:How to resolve the algorithm Find palindromic numbers in both binary and ternary bases step by step in the Scheme programming language
You may also check:How to resolve the algorithm Isqrt (integer square root) of X step by step in the Prolog programming language
You may also check:How to resolve the algorithm Anti-primes step by step in the Fortran programming language