How to resolve the algorithm 4-rings or 4-squares puzzle step by step in the BASIC256 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 BASIC256 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 BASIC256 programming language

Source code in the basic256 programming language

call four_square(1, 7,  TRUE,  TRUE)
call four_square(3, 9,  TRUE,  TRUE)
call four_square(0, 9, FALSE, FALSE)
end

subroutine four_square(low, high, unique, show)
	total = 0

	if show then print " a b c d e f g" + chr(10) + " ============="

	for a = low to high
		for b = low to high
			if unique and b = a then continue for
			t = a + b
			for c = low to high
				if unique then
					if c = a or c = b then continue for
				end if
				for d = low to high
					if unique then
						if d = a or d = b or d = c then continue for
					end if
					if b + c + d = t then
						for e = low to high
							if unique then
								if e = a or e = b or e = c or e = d then continue for
							end if
							for f = low to high
								if unique then
									if f = a or f = b or f = c or f = d or f = e then continue for
								end if
								if d + e + f = t then
									for g = low to high
										if unique then
											if g = a or g = b or g = c or g = d or g = e or g = f then continue for
										end if
										if f + g = t then
											total += 1
											if show then print " ";a;" ";b;" ";c;" ";d;" ";e;" ";f;" ";g
										end if
									next g
								end if
							next f
						next e
					end if
				next d
			next c
		next b
	next a

	print
	if unique then
		print "There are ";total;" unique solutions in [";string(low);", ";string(high);"]"
	else
		print "There are ";total;" non-unique solutions in [";string(low);", ";string(high);"]"
	end if
	print
end subroutine

  

You may also check:How to resolve the algorithm Generic swap step by step in the Perl programming language
You may also check:How to resolve the algorithm Arithmetic/Integer step by step in the Raven programming language
You may also check:How to resolve the algorithm Object serialization step by step in the Erlang programming language
You may also check:How to resolve the algorithm Haversine formula step by step in the Teradata Stored Procedure programming language
You may also check:How to resolve the algorithm Doubly-linked list/Element definition step by step in the ARM Assembly programming language