473,549 Members | 2,781 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

magic square - topographical model ...

4 New Member
I am 50 years old ...and am working physical models of the math structure called a magic square .. for my own interest.

My present problem is this. I have a topograhical model for the square ... where each cell in the square is a solid structure to the height specified by the value in that cell. Then conceptually I pour water on top of the square and see where the water collects ... in lakes as it were.

**** there are 880 different 4x4 magic squares

**** there are 3600 different pandiagonal 5x5 magic squares....


What I think I need is a program that will generate all possible paths from any given cell in the interior of the square ... to the exterior of the square .... restricted to movement on the x,y axis.

For the 5x5 square I have hand written 91 different paths from the x2y2 ... or first interior corner cell to the exterior ...

I would like a algorithm/code that would generate the paths for any order of square ... ie 6x6 , 7x7 etc ...


*******

A real nice guy gave me a example in pseudo code ...that he thought would be a step in the right direction .... I have never done any recursive routines ... and quite frankly don't even know how to right the string to keep adding the new value to the end of itself ... etc ...

*****

here is the idea he gave me ...


#1. you should first use a depth-first search algorithm ...
( I have no acquantaince with that)


#2. for each cell c in the interior
find every path from c to the exterior


define function "find and report every path from c to the exterior."
called FAREPFHTTE(c)

for each diretion up (+1 0), down (-1 0 ), left (0 +1), right (0-1)
nextc = c + direction
if next c is already in the path, skip it
if next c is exterior report path
otherwise call FAREPFHTTE (next c)

****** paths cannot take diagonals ****

We don't want the program to try up, down, up , downn over and over ..
So how can we mark that the cell is already in the path ? We'll keep a array of cells and mark each one as we take it ( and unmark each one as we leave it). So now it is



FAREPFHTTER(c)
A(c) = 1 # mark that c is in use
for each direction up (+1,0), down ((-10), left(0+1), right (0-1)
next c = c + direction
if A(nextc) is 1 , try next direction # it is already in the path skip it
if nextc is exterior, report path
otherwise call FAREPFHITTE(nex tc)
A(c) = 0 # mark that c is no longer used


the next problem is , how can we report the whole path? Well pass a string P with the path so far


Clear an array of cells A

FAREPFHTTE(c,P)
A(c) = 1 # mark that c is in use
for each direction up (+1,0), down (-1,0), left (0,+1, right (0 -1)
nextc = c + direction
if A(nextc) is 1 , try next direction #it is already in the path, skip it
if nextc is exterior, print P #print what we have
otherwise call FAREPFHTTE(next c,P."nextc")
A(c) = 0 #mark that c is no longer used


I feel embarrassed to ask someone else to do my work that I would enjoy doing ... but I am interested in the solution ... and for/next loops, some simple sorting .... reading and writing from a file is about the extent of my VB skills...

If any know the landscape and can be of help I would be greatful

Thanks

Craig
Aug 10 '07 #1
1 3902
JosAH
11,448 Recognized Expert MVP
I don't think I understand what your actual problem is or, in other words, what
exactly you want to solve. Can I assume that the magic square is in a horizontal
position and on top of every cell of the square are n cubes positioned where n is
the number in that cell of the square?

You wrote that you 'conceptually' pour water over those piles of cubes. At which
cell? The cell with the highest pile of cubes on it, i.e. the cell with the highest
number?

I assume, correct me if I'm wrong, that the water can only 'fall down' i.e. move
from a cell with a higher number to a cell with a lower number as long as those
cells are adjacent (not diagonal). Right?

What do you want to find? You wrote 'all paths' but 'all paths' starting from the
highest position and ending at a (local) minimum?

kind regards,

Jos
Aug 15 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
4726
by: winnerpl | last post by:
Hey guys I'm trying to get a magic square but I'm stuck with it printing out only 1's and 0's in random places. Hope you experts can can provide some input on what I'm doing wrong. #include <stdio.h> #define MAX 20 int x; int size_request(void); //asks the user to enter the size x size square.
1
10526
by: shaveta | last post by:
pls guide me to write a program in c to generate a magic square of size n*n , where n is odd A magic square is an n*n matrix of integer from 1 to n^2, where n is odd, such that the sum of every row, column and diagonal is same. The rule is - Start with 1 in the middle of the first row; then go up and left , assigning nos. in increasing...
4
1816
by: jyck91 | last post by:
can any one tell me?? what should i do before i strating wirtitng the magic square programe
8
3708
KoreyAusTex
by: KoreyAusTex | last post by:
I am pretty new at programming and need some feedback as to why this program is not working??? It was a pretty big undertaking for me but I can't seem to figure out what is wrong: import java.util.*; public class MagicSquare { public static void isMagic (int b) { int sum = 0;
2
2564
by: jyck91 | last post by:
i have done the magic square: #include <stdio.h> #include <stdlib.h> #include <string.h> #define SIZE 13 main() { FILE *fp; int i, j, n, row, column;
5
2206
by: magic man | last post by:
I need help ... I have very rudimentary VB skills. I am working on a topographical model of a magic square. I consider each cell in the square to be a solid structure to the height specified by the value in the square. Then conceptually I pour water on the structure and wish to see where the water collects in "lakes" on the structure. What...
1
4163
by: manju01 | last post by:
in the below program we can generate magic square of size 3-160 but i want to print the output like for magic size n ************************ * * * * * * 5 * 8 * 7 * 6 * ************************ that is in grid
4
3404
by: inferi9 | last post by:
Hi, I am working in a program caals magic square and it must be done only with loops and user definied funcations,I will tell you about my code and where my problem, the main is only calls the other funcations,The first funcation makes a squence which the user input where it begins and the differents between easch elements the size of this one...
1
3409
by: sanaanand2008 | last post by:
can u pls help me out write the prgm to check whether the entered matrix is a magic square or not?
0
7450
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
1
7470
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6043
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5088
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3500
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3481
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1941
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1059
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
763
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.