We wish to design a jigsaw puzzle with square pieces, whose length/width ratio is as close as possible to 2 .
For a small puzzle, we could make the puzzle 1 7 × 1 2 , because ∣ ∣ ∣ ∣ ∣ ( 1 2 1 7 ) 2 − 2 ∣ ∣ ∣ ∣ ∣ = 1 4 4 1 is very small. Let us call a ℓ × w puzzle good if the difference ∣ ∣ ∣ ∣ ∣ ( w ℓ ) 2 − 2 ∣ ∣ ∣ ∣ ∣ is less than that same expression for any puzzle with fewer pieces.
How many pieces is the largest good puzzle with less than 10000 pieces?
This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try
refreshing the page, (b) enabling javascript if it is disabled on your browser and,
finally, (c)
loading the
non-javascript version of this page
. We're sorry about the hassle.
Explanation:
The variables
num
and
den
represent the length and width. (After all, we are studying the value of the
fraction
num/den
.)
1 |
|
For any given width of the puzzle (
den
) we must try two length (
num
): one with a ratio just below
2
, and one with a ratio just above
2
; you never know which one will give the better approximation! In my approach, the variable
num0
remembers the greatest length that resulted in a ratio less than
2
; it is the starting point for the search when we increase the width. The search continues until we have checked a ratio above
2
. When that happens, the
break;
statement in line 27 is executed, and we move on to the next width.
1 |
|
This calculates the fraction d n / d d = ( n u m / d e n ) 2 − 2 . Of course I could have simply calculated this as a floating-point variable, but integers are way cooler (and potentially more precise).
1 |
|
This is the same as checking whether ∣ d n / d d ∣ < ∣ b e s t _ d n / b e s t _ d d ∣ , in other words, if there is any improvement compared to an earlier puzzle.
My solution in python 3
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
|
```
It is possible to partially guess the correct solution, needless to say this is rather handwavy and should not be really considered as a solution but as motivation. Consider the Pell's equation x 2 − 2 y 2 = 1 and note that since y x = y 2 1 + 2 we have y x ≈ 2 when y is even somewhat large. Now lets consider natural number solutions to these equations. The solutions can be generated recursively by x k + 1 = x 1 x k + 2 y 1 y k y k + 1 = x 1 y k + y 1 x k Where ( x 1 , y 1 ) = ( 3 , 2 ) is the fundamental solution. Largest solution so that x n y n < 1 0 0 0 0 is x n = 9 9 , y n = 7 0 which "happens" to be the right solution, as may be intuitive.
Note also that we can easily generate pretty good solutions for jigsaws far greater than 10000 pieces without any difficulty, If I recall correctly it is actually provable that there is no better approximation y x t o : 2 where y ≤ y k than the k:th solution to pell's equation, but I am not sure. Next solutions are ( 5 7 7 , 4 0 8 ) and ( 3 3 6 3 , 2 3 7 8 )
The solutions you find this way all have x n / y n > 2 , but the problem clearly allows for solutions with x n / y n < 2 as well.
So, apart from your solutions x 3 1 7 9 9 5 7 7 3 3 6 3 y 2 1 2 7 0 4 0 8 2 3 7 8 x y 6 2 0 4 6 9 3 0 2 3 5 4 1 6 ⋮ ( x / y ) 2 2 . 2 5 2 . 0 0 6 9 4 4 2 . 0 0 0 2 0 4 2 . 0 0 0 0 0 6 > 2 x 2 − 2 y 2 1 1 1 1 1
there are also
x 4 7 2 4 4 1 1 4 0 y 3 5 1 7 2 9 9 9 x y 1 2 3 5 4 0 8 1 1 8 9 1 3 8 6 0 ⋮ ( x / y ) 2 1 . 7 7 7 7 7 8 1 . 9 6 1 . 9 9 3 0 8 1 . 9 9 8 8 1 1 1 . 9 9 9 7 9 6 < 2 x 2 − 2 y 2 − 2 − 1 − 2 − 1 − 2
Log in to reply
Gah! I missed that completely! Here is how to Intuit Your other solutions, we consider x 2 − 2 y 2 = − 1 now the recursion formula is x k + 1 = 3 x k + 4 y k and y k + 1 = 2 x k + 3 y k with fundamental solution ( x 1 , y 1 ) = ( 1 , 1 ) . The rest of the solutions are tweaked from the orginal solutions as ( x n , y n ) → ( 2 y n , x n ) for if y x > ≈ 2 then x 2 y < ≈ 2 where > ≈ denotes slightly greater and < ≈ denotes slightly lesser
Log in to reply
That seems about right... Now the questions I have are
Can you prove that all solutions are of this kind?
Why are there many solutions with x 2 − 2 y 2 = − 2 but not with x 2 − 2 y 2 = 2 ?
As for the last question, we could try the "tweak" with your second recursion formula, and get e.g. ( 7 , 5 ) ↦ ( 1 0 , 7 ) and 1 0 2 − 2 ⋅ 7 2 = 2 . This is not a good solution because it is no improvement over ( 7 , 5 ) -- but why this lack of symmetry?
My solution is a little bit ugly. Let $f_n$ be the best ratio with at most $n$ pieces and $g_n$ be the best ratio with exactly $n$ pieces, then: f 1 = 1 , f n = m i n { g n , f n − 1 } g n = l × w = n min { ∣ ∣ ∣ ( w l ) 2 − 2 ∣ ∣ ∣ } Now we just compute the greater $n$ which verify $g_n < f_ n - 1 $
To speedup the computation I used Dynamic Programming.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
|
Problem Loading...
Note Loading...
Set Loading...
Output:
The second-last line shows that the solution is 6 9 3 0 . The dimensions are 99x70; then ( 7 0 9 9 ) 2 − 2 = 4 9 0 0 9 8 0 1 − 9 8 0 0 = 4 9 0 0 1 , so that 9 9 : 7 0 is very close to 2 .