## square chalence

General FreeBASIC programming questions.
bluatigro
Posts: 655
Joined: Apr 25, 2012 10:35
Location: netherlands

### square chalence

puzzle from 1980 book :

1 :
write code that calculates the number of squares in any rectangle
the recangle is filled totaly
no squares overlap
input is width and height of the rectangle

2 :
find the smalest rectangle whit that
thebigh
Posts: 36
Joined: Dec 14, 2018 11:11

### Re: square chalence

I don't know if I understand the question.

Surely if w is a rational multiple of h we can cover the rectangle with many different square tesselations. And if not, no covering is possible without leaving gaps.

Suppose mw = nh where m and n are both positive integers. Then we can cover the rectangle with squares of side length s = w/n = h/m.

But we can also do it with squares of side length s/2, s/3, s/4 and so on.

The second part of your question is incomprehensible.
bluatigro
Posts: 655
Joined: Apr 25, 2012 10:35
Location: netherlands

### Re: square chalence

sizes are integers

find the smalles retangle that fits the puzle
thebigh
Posts: 36
Joined: Dec 14, 2018 11:11

### Re: square chalence

1. Smallest number of squares that will completely and nonoverlappingly cover a rectangle of given integer width and height

Code: Select all

`function gcd( w as uinteger, h as uinteger ) as uinteger    if h = 0 then        return w    else        return gcd(h, w mod h)    end ifend functiondim as uinteger w, h, ginput w, hg = gcd(w, h)print w*h/(g*g)`

edit: smallest number of squares of equal size

2. w=h=1 is the smallest rectangle with integer side lengths that can be totally covered by some number of squares. Again, I don't think this question makes sense.
Last edited by thebigh on Apr 02, 2020 16:13, edited 1 time in total.
bluatigro
Posts: 655
Joined: Apr 25, 2012 10:35
Location: netherlands

### Re: square chalence

more that 1 square is good