Hey there all. I've got this assignment (due next Monday!) and I haven't made much headway into it. It's horrible becuase I usually have some idea about how to go about solving the assignments. (If you've read it through already) So far, all I've managed to do is create a list of all five digit primes with a particular sumOfDigits. (i.e. all valid primes to be used in the grid) I just dont know what to do with this now. I've tried using several equations, but that means 12 equations and 24 unknowns. I just can't seem to see any relation between the positions of the grid! Right now I'm even Googling "properties of five digit primes". Help!

~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Write a program to fill a 5 x 5 grid such that each row (from left to right), each column (from top to bottom) and each diagonal (from left to right) form a 5-digit prime number. The sum of the digits of each prime is the same. For example:


1 1 3 5 1
3 3 2 0 3
3 0 3 2 3
1 4 0 3 3
3 3 3 1 1

Here, the digits of each prime add up to 11. The diagonal primes are 13331 and 34301.

Data consists of two numbers, m and n. The digits of each prime must add up to m and n must be placed in the top-left position. In the example, m = 11 and n = 1.

You may use the same prime more than once in the grid. You must output all possible solutions.

In addition to the above, there are two other solutions for m = 11 and n = 1. They are:


1 1 3 5 1
1 3 3 1 3
1 4 0 3 3
1 3 0 4 3
3 0 3 2 3

and

3 2 3 0 3
5 3 2 0 1
5 0 2 3 1
1 3 3 1 3
1 3 3 3 1

Member Avatar for iamthwee

Hey there all. I've got this assignment (due next Monday!) and I haven't made much headway into it. It's horrible becuase I usually have some idea about how to go about solving the assignments. (If you've read it through already) So far, all I've managed to do is create a list of all five digit primes with a particular sumOfDigits. (i.e. all valid primes to be used in the grid) I just dont know what to do with this now. I've tried using several equations, but that means 12 equations and 24 unknowns. I just can't seem to see any relation between the positions of the grid! Right now I'm even Googling "properties of five digit primes". Help!

~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Write a program to fill a 5 x 5 grid such that each row (from left to right), each column (from top to bottom) and each diagonal (from left to right) form a 5-digit prime number. The sum of the digits of each prime is the same. For example:


1 1 3 5 1
3 3 2 0 3
3 0 3 2 3
1 4 0 3 3
3 3 3 1 1

Here, the digits of each prime add up to 11. The diagonal primes are 13331 and 34301.

Data consists of two numbers, m and n. The digits of each prime must add up to m and n must be placed in the top-left position. In the example, m = 11 and n = 1.

You may use the same prime more than once in the grid. You must output all possible solutions.

In addition to the above, there are two other solutions for m = 11 and n = 1. They are:


1 1 3 5 1
1 3 3 1 3
1 4 0 3 3
1 3 0 4 3
3 0 3 2 3

and

3 2 3 0 3
5 3 2 0 1
5 0 2 3 1
1 3 3 1 3
1 3 3 3 1

Read this kiddo...

http://olympiads.win.tue.nl/ioi/ioi94/contest/day1prb3/solution.html

Then when you're happy with that design a GUI for you application.

Oh my god! I feel like I'm dreaming.... is that really the solution in front of me? lol...
Wow, thank you soooo much iamthwee... I think i'm going to bookmark that olympiad site, just in case my lecturer decides to bring another of those as an assignment...

Thanks again!

Member Avatar for iamthwee

Oh my god! I feel like I'm dreaming.... is that really the solution in front of me? lol...
Wow, thank you soooo much iamthwee... I think i'm going to bookmark that olympiad site, just in case my lecturer decides to bring another of those as an assignment...

Thanks again!

If you have any further problems post them here. The solution should just be a a case of dynamic programming.

Don't forget to add to my rep if this was useful.

BTW, you're two other examples were wrong honey.

I've just ran it through a program I've written on the fly and the other two solutions for m=11 n =1 should be as follows:

1 1 3 5 1
3 3 2 0 3
3 0 3 2 3
1 4 0 3 3
3 3 3 1 1

1 3 3 1 3
1 3 0 4 3
3 2 3 0 3
5 0 2 3 1
1 3 3 3 1

;)

Yes... i realised afterwards that somehow I copied the other solutions badly. The ones that you gave are the correct ones as on my assignment sheet. I've started the coding and will let you know how it turned out. And i definitely will add to your rep :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.