How to resolve the algorithm Magic squares of doubly even order step by step in the VBScript programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Magic squares of doubly even order step by step in the VBScript programming language
Table of Contents
Problem Statement
A magic square is an N×N square matrix whose numbers consist of consecutive numbers arranged so that the sum of each row and column, and both diagonals are equal to the same sum (which is called the magic number or magic constant).
A magic square of doubly even order has a size that is a multiple of four (e.g. 4, 8, 12).
This means that the subsquares also have an even size, which plays a role in the construction.
Create a magic square of 8 × 8.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Magic squares of doubly even order step by step in the VBScript programming language
Source code in the vbscript programming language
' Magic squares of doubly even order
n=8 'multiple of 4
pattern="1001011001101001"
size=n*n: w=len(size)
mult=n\4 'how many multiples of 4
wscript.echo "Magic square : " & n & " x " & n
i=0
For r=0 To n-1
l=""
For c=0 To n-1
bit=Mid(pattern, c\mult+(r\mult)*4+1, 1)
If bit="1" Then t=i+1 Else t=size-i
l=l & Right(Space(w) & t, w) & " "
i=i+1
Next 'c
wscript.echo l
Next 'r
wscript.echo "Magic constant=" & (n*n+1)*n/2
You may also check:How to resolve the algorithm Closures/Value capture step by step in the Factor programming language
You may also check:How to resolve the algorithm Integer sequence step by step in the EDSAC order code programming language
You may also check:How to resolve the algorithm 4-rings or 4-squares puzzle step by step in the Go programming language
You may also check:How to resolve the algorithm Real constants and functions step by step in the AWK programming language
You may also check:How to resolve the algorithm Empty program step by step in the PARI/GP programming language