For those who enjoy spending time solving algorithmical problems, here's one:
Originally Posted by dontrememberauthor
Given a square having side a positive integer (n > 0, n belongs to N*), find the smallest number of squares having also positive integer side, in which can be devided.
Examples:
- n = 2, 4 squares of side 1;
- n = 3, 6 squares (1 of side 2 + 5 of side 1);
- n = 5, 8 squares (1 of side 3 + 3 of side 2 + 4 of side 1)...
I'm curious who's the first to find the solution for n = 13!
If you care to write the implementation of your algorithm, try as input n = 9973.
Do you have a proved solution (don't give one, just I wonder if there is).
Even if n=7 (8 squares) I can't figure out some (especially O(n^2) as I see n=9973!) heuristics...
"Programs must be written for people to read, and only incidentally for machines to execute."
Proved solution? I think so. Even that I didn't publish any complete mathematical study and proof of my implementation, doesn't mean that my solution is incorrect.
I can assure you of one thing: my post is not trying to waste your time, and strongly believe that there is a flawless solution to this problem.
So, find it if you can and enjoy doing this kind of activities.
Thanks for showing interest. Hope we'll soon discuss about possible solutions.
Hi Joe!
Considering the complexity of this problem, backtracking is more a theoretical solution, as it can be for most ever invented problems. As for knapsack style, there are no similarities with the coins problem, since coins doesn't have to be arranged in any way to fit the sum, so there, you can apply greedy. But in our square problem, there's no way to tell what relationship must exists in a set of squares, assuring us that they form a bigger square.
You see, we know that our solution set of squares must satisfy some mathematical conditions, for example the area formula:
sum(x[i]^2) = n^2, where n is the side of the input square and x[i] is the side of the i-th square in our solution; of course, sum() is a pseudo-function computing the sum.
But only this formula is not enough to ensure a valid solution, because not all such sets can form the square of side n. Take for example the pitagoric numbers 3^2+4^2 =5^2; they are respecting the above formula, but a square of side 5 cannot be made out of a square having side 3 and a square with side 4. The arrangement is not possible.
How else can you optimize a backtraking based algorithm? Maybe "Branch & Bound" by stoping the search at the last best solution, or "Divide & Conquer" by finding a way to reduce the problem to a smaller square?
As RoboTact already mentioned, did you try to figure out "some heuristics" that might work for this problem?
Originally Posted by Joe Nellis
Also 13! can't be represented by a 32bit integer I believe so this would be a hassle.
Why would you wanna represent the factorial of 13 to solve this problem? This ain't a permutation problem, and even if it would've been, why to store the number of permutations? For a square with side n, there's no reason to store or work with numbers bigger than n^2 (as you use for area testing).
Guys, yet nobody can give me the solution for n=13? It's a tiny little square that you can draw on a paper or a board... and divide it a few times, counting the number of squares required for a complete division.
It would be not an algotithmic solution it I just draw a square and try to figure out a solution... More of that: I even don't know a way to prove that some solution for n=13 is optimal. So, I think the only thing worth doing is to solve the general algorithmic problem. However, I just enjoing holidays before new term (writing my project ), from second of september I'll try to force the problem...
"Programs must be written for people to read, and only incidentally for machines to execute."
Even if n=7 (8 squares) I can't figure out some (especially O(n^2) as I see n=9973!) heuristics...
I must be missing something ... the only 8 squares decompositions of a 7x7 square are 4-3-2-2-2-2-2-2 and 3-3-3-3-2-2-2-1 ... and there is no arrangement possible with such ones
My best for 7x7 is 9 squares (one decomposition, many arrangements) ... but 8?
My brain is not what it used to be
Last edited by DeepButi; September 1st, 2004 at 07:01 AM.
Did it help? rate it.
The best conversation I had was over forty million years ago ... and that was with a coffee machine.
Congratulations Vasya!
You are the first to reply with the solution for n=13.
Indeed, this square can be devided in minimum 11 squares, as you've already proved in your post.
Have you tried your implementation with 9973 as input square?
If your implementation is finding a solution (don't display the map), please let me know in how much time was found and please send me your implementation, or at least post the algorithm as pseudocode.
Bookmarks