|
Post by bluatigro on Apr 1, 2020 11:32:22 GMT
puzzle : write a program that finds the smalest square filled whit all different squares
|
|
|
Post by bluatigro on Apr 1, 2020 12:16:49 GMT
pardon me
the puzzle is realy find for every near square the least number of differen sised what wil fit in it [ retangle must be totaly coverred ] no two squares wil overlap
input of code is width and height of retangle
i got this from a book [ 1980 ]
|
|
|
Post by B+ on Apr 2, 2020 3:27:50 GMT
Here is my solution:
'Min Squares That Fit Inside a Rectangle.txt for JB v2.0 b+ 2020-04-01 global INDEX do print "We are going to list all the squares that fill in a rectangle." Input "0 quits, Enter width of the rectangle with integer sides: ";w Input "0 quits, Enter height of the rectangle with integer sides: ";h print dim amts(100), sides(100), areas(100) INDEX = 0 : totalArea = 0 : totalAmts = 0 if w > 0 and h > 0 then Print "The squares that fit in a ";w;"X";h;" rectangle are:" call reduceRectangleByLargestSquare w, h for i = 1 to INDEX print amts(i);" Square(s) of size ";sides(i);"X";sides(i);" has area of ";areas(i) totalAmts = totalAmts + amts(i) : totalArea = totalArea + areas(i) next print "========================================================================" print "Total squares is ";totalAmts;", total of square areas is ";totalArea;"." print "Area of rectangle ";w;"X";h;" is ";w * h;"." print else print "That's not a rectangle." print end if print loop until w = 0 or h= 0 print "Bye!" end
sub reduceRectangleByLargestSquare w, h ' <<<< recursive sub if w <> 0 and h <> 0 then if w < h then INDEX = INDEX + 1 amts(INDEX) = int(h/w) : sides(INDEX) = w : areas(INDEX) = w * w * int(h/w) 'print int(h/w);" Square(s) of size ";w;"X";w nH = h - int(h/w) * w nW = w if nH = 0 then exit sub else call reduceRectangleByLargestSquare nH, nW end if else INDEX = INDEX + 1 amts(INDEX) = int(w/h) : sides(INDEX) = h : areas(INDEX) = h * h * int(w/h) 'print int(w/h);" Square(s) of size ";h;"X";h nW = w - int(w/h) * h nH = h if nW = 0 then exit sub else call reduceRectangleByLargestSquare nH, nW end if end if end if end sub
Sample Output:
|
|
|
Post by B+ on Apr 2, 2020 4:57:06 GMT
OK now I get it. Pick two sequential Fibonacci Numbers and you have a bunch of unique squares filling out the rectangle:
0 quits, Enter width of the rectangle with integer sides: 4181 0 quits, Enter height of the rectangle with integer sides: 2584
The squares that fit in a 4181X2584 rectangle are: 1 Square(s) of size 2584X2584 has area of 6677056 1 Square(s) of size 1597X1597 has area of 2550409 1 Square(s) of size 987X987 has area of 974169 1 Square(s) of size 610X610 has area of 372100 1 Square(s) of size 377X377 has area of 142129 1 Square(s) of size 233X233 has area of 54289 1 Square(s) of size 144X144 has area of 20736 1 Square(s) of size 89X89 has area of 7921 1 Square(s) of size 55X55 has area of 3025 1 Square(s) of size 34X34 has area of 1156 1 Square(s) of size 21X21 has area of 441 1 Square(s) of size 13X13 has area of 169 1 Square(s) of size 8X8 has area of 64 1 Square(s) of size 5X5 has area of 25 1 Square(s) of size 3X3 has area of 9 1 Square(s) of size 2X2 has area of 4 2 Square(s) of size 1X1 has area of 2 ======================================================================== Total squares is 18, total of square areas is 10803704. Area of rectangle 4181X2584 is 10803704.
Not only that but they are all Fibonacci Numbers!
|
|
|
Post by bluatigro on Apr 2, 2020 8:44:29 GMT
only 1 square of eatch size !!
|
|