473,322 Members | 1,347 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

magic square - topographical model ...

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(nextc)
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 3890
JosAH
11,448 Expert 8TB
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
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...
1
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...
4
by: jyck91 | last post by:
can any one tell me?? what should i do before i strating wirtitng the magic square programe
8
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...
2
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
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...
1
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 *...
4
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...
1
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
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.