Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Computer Engineering Expert

Your assignment will be to determine all of the magic squares when given an n, display permutations that match the magic squares to the screen AND prepare it to a file.

You will only test when n == 3!!! But code it for n of ANY number!!
It turns out that finding the magic squares for n >= 4 takes too long for us to run it on the shared machines (linux1, 2 & 3)
Since if n == 1, the square is 1 (too easy!!)
and since for n == 2 there is no answer!!
Your program must come up with every possible arrangement (permutation) of numbers within the square. These are known as the permutations of that list of numbers. Each permutation needs to be checked to see if it has formed a magic square.

Program Requirements

Your program must:
use command line arguments. At the command line the user must enter (in this order):
the name of the executable file,
n (which will ALWAYS be 3, but again could be run with other numbers)
and the name of the output file in which to prepare the squares.
use a recursive permute to give all of the permutations of the square.
In other words, your function called "permute", must be a recursive function.
So for each permutation, you should check to see if it is a magic square, display it and prepare it to the file
prepare only the unique magic squares to the SCREEN and FILE. No duplicates allowed.
HINT: Let your program produce duplicates first, then see how you can refrain from writing the duplicates. 
Then modify your code.
use a list of size n2.
The code for the recursive permute function will be much easier to prepare if you store the numbers in a list
rather than a two-dimensional list (or array) of size n x n. How you print the data is not related.
[6, 2, 7, 5, 4, 8, 3, 9, 1, ....] (size to n2)
[4, 2, 7, 6, 5, 8, 3, 9, 1, ....]
[7, 4, 2, 6, 5, 8, 3, 9, 1, ....]
...
close any files that you have opened as soon as you have finished using them.
Time how long your program takes to find the magic square and print that time at the end of the SAME file.


Sample Run


Here is a sample of output of this program. Please note that the sample output only shows what is expected from your program if the user is actually entering everything as instructed. This is not a test of the program at all, but just a sample for your clarification.
2 7 6
9 5 1
4 3 8

2 9 4
7 5 3
6 1 8

4 3 8
9 5 1
2 7 6

4 9 2
3 5 7
8 1 6

6 1 8
7 5 3
2 9 4

6 7 2
1 5 9
8 3 4

8 1 6
3 5 7
4 9 2

8 3 4
1 5 9
6 7 2

Total running time: 4.76 seconds. 

Computer Engineering, Engineering

  • Category:- Computer Engineering
  • Reference No.:- M9116913

Have any Question?


Related Questions in Computer Engineering

Select one of the discussion topics and respond begin your

Select one of the discussion topics and respond. Begin your response by indicating which question you chose. Discussion topics: Section 1 Should the government set a maximum wage? Why or why not? Section 2 Most people be ...

Jason who is very knowledgeable regarding computers agrees

Jason, who is very knowledgeable regarding computers, agrees to purchase computers for Nick's business. Jason is retained for that purpose only, he is paid a set rate for the job, and Nick exercised no control over the m ...

Assume you have been selected to build a system for

Assume you have been selected to build a system for Oil&Gas company. Do you prefer to build a win-based system or a web-based system? Why?

How much of the opposing side should you share in a

How much of the opposing side should you share in a presentation to a multiple-perspective audience, and what techniques would you use?

Question a small computer on a smart card has four page

Question : A small computer on a smart card has four page frames. At the first clock tick, the R bits are 0111 (page 0 is 0, the rest 1). At subsequent clock ticks, the values are 1011, 1010, 0101, 1010, 0010, 1100, and ...

Qion leadership paradox and inter-team relationsa

Question: Leadership Paradox and Inter-team Relations A. What is the leadership paradox? Give some reasons why a leader can encounter difficulty in newly formed teams or groups using a participative management system. Su ...

What type of economic system does norway have explain some

What type of economic system does Norway have? Explain some of the benefits of this system to the country and some of the drawbacks

Suppose kelvin has seven controls listed as the top tier of

Suppose Kelvin has seven controls listed as the top tier of project initiatives. At his next meeting with Charlie, he provides a rank-ordered list of these controls with projected losses over the next 10 years for each i ...

Mary kate is a project manager in the it department for a

Mary Kate is a project manager in the IT department for a university. She has been asked to manage a project to create faculty intranet. The university has multiple campuses in various locations, and professors and other ...

Why the ytms of bond and zero coupon yields are different

Why the YTMs of bond and Zero coupon yields are different for the same term.

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As