How to resolve the algorithm 4-rings or 4-squares puzzle step by step in the FreeBASIC 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 FreeBASIC 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 FreeBASIC programming language
Source code in the freebasic programming language
' version 18-03-2017
' compile with: fbc -s console
' TRUE/FALSE are built-in constants since FreeBASIC 1.04
' But we have to define them for older versions.
#Ifndef TRUE
#Define FALSE 0
#Define TRUE Not FALSE
#EndIf
Sub four_rings(low As Long, high As Long, unique As Long, show As Long)
Dim As Long a, b, c, d, e, f, g
Dim As ULong t, total
Dim As ULong l = Len(Str(high))
If l < Len(Str(low)) Then l = Len(Str(low))
If show = TRUE Then
For a = 97 To 103
Print Space(l); Chr(a);
Next
Print
Print String((l +1) * 7, "=");
Print
End If
For a = low To high
For b = low To high
If unique = TRUE Then
If b = a Then Continue For
End If
t = a + b
For c = low To high
If unique = TRUE Then
If c = a OrElse c = b Then Continue For
End If
For d = low To high
If unique = TRUE Then
If d = a OrElse d = b OrElse d = c Then Continue For
End If
If b + c + d = t Then
For e = low To high
If unique = TRUE Then
If e = a OrElse e = b OrElse e = c OrElse e = d Then Continue For
End If
For f = low To high
If unique = TRUE Then
If f = a OrElse f = b OrElse f = c OrElse f = d OrElse f = e Then Continue For
End If
If d + e + f = t Then
For g = low To high
If unique = TRUE Then
If g = a OrElse g = b OrElse g = c OrElse g = d OrElse g = e OrElse g = f Then Continue For
End If
If f + g = t Then
total += 1
If show = TRUE Then
Print Using String(l +1, "#"); a; b; c; d; e; f; g
End If
End If
Next
End If
Next
Next
End If
Next
Next
Next
Next
If unique = TRUE Then
Print
Print total; " Unique solutions for "; Str(low); " to "; Str(high)
Else
Print total; " Non unique solutions for "; Str(low); " to "; Str(high)
End If
Print String(40, "-") : Print
End Sub
' ------=< MAIN >=------
four_rings(1, 7, TRUE, TRUE)
four_rings(3, 9, TRUE, TRUE)
four_rings(0, 9, FALSE, FALSE)
' empty keyboard buffer
While InKey <> "" : Wend
Print : Print "hit any key to end program"
Sleep
End
You may also check:How to resolve the algorithm Stable marriage problem step by step in the zkl programming language
You may also check:How to resolve the algorithm N'th step by step in the F# programming language
You may also check:How to resolve the algorithm ABC problem step by step in the TUSCRIPT programming language
You may also check:How to resolve the algorithm Find limit of recursion step by step in the Bracmat programming language
You may also check:How to resolve the algorithm SHA-1 step by step in the Rust programming language