Click here to Skip to main content
15,887,267 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi!
So i would like to ask if you have any idea how to make a diagonal latin square (i mean a square that has combination of 1..n not only in row and column but also on both diagonal and antidiagonal). I've tried a lot of things but it just doesnt want to work. The worst thing is that i found some code in the internet but its in python and i have to use Pascal for mine one. BTW im a beginner so i dont even totally get whats happening in other languages 😀
Thank you!

What I have tried:

I ve tried coding a program which takes a random number from 1..n and checkes it if its right if yes its going on another spot IF not everythings repeat. But i unfortunately made too many mistakes in it .
Posted
Updated 4-Jan-18 23:43pm
Comments
Richard MacCutchan 5-Jan-18 5:34am    
Draw the square on paper and try adding the numbers manually. Think about what decision you need to make at each point and write down the steps as you do it. When you have completed the square you just need to convert those logical steps into Pascal statements.
Member 13608224 5-Jan-18 6:23am    
^ i tried it but theres no pattern unless its a prime number i mean square 7x7,5x5 and so on. In other situations you have to start from diagonal and antidiagonal but even though in every space you can write 2 numbers and only one is correct so its not helpful, at least for me
Richard MacCutchan 5-Jan-18 6:29am    
Exactly so. The problem is one of logic and it is up to you to figure out that logic. Converting the logic into code is the easy part.
Member 13608224 5-Jan-18 6:59am    
Probably for someone who can easily program anything its easy, but as for someone totally new its not. I have 2 ideas for algorithm but i was counting that someone here will be able to tell me if my idea should work and so on. Thats why i tried to explain one of them. Its not like im asking for ready solution just for some tips
Richard MacCutchan 5-Jan-18 8:33am    
But, as I already said, it is not a programming (i.e. Pascal) problem, so there is nothing much that we can suggest in those terms. The actual algorithm is referred to in Maciej's solution below, so that is where you should start. You cannot consider writing any code until you understand the actual problem and its solution.

1 solution

You can't expect that someone of us will write a programme to you.

Start here: Latin Square -- from Wolfram MathWorld[^]. A diagram which may help you to write programme, you'll find here (pdf)[^]
 
Share this answer
 
Comments
Member 13608224 5-Jan-18 6:10am    
Well i dont expect you to make program instead of me just to explain how to do it in Pascal. I know that in Python you can do it more easily but i just dont know it. And the links you share are not exactly what i mean, because there on the diagonal you have 0 always and i have to have there a combination of [1,n] and that is the biggest problem to me. Making normal latin square is much simpler i guess

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900