(12C) Maximum Size of Square Area in a Rectangle
07-11-2018, 05:00 AM (This post was last modified: 07-11-2018 05:07 AM by Gamo.)
Post: #1
 Gamo Senior Member Posts: 548 Joined: Dec 2016
(12C) Maximum Size of Square Area in a Rectangle
This program calculate the exact "Maximum Size of the Square Area" and
how many Squares fit inside a Rectangle.

Procedure:
Given size of the Rectangle is

Length = 6
Width = 4

6 ENTER 4 // This input can be switch around (4 ENTER 6)
R/S --> 2 // Answer for the maximum square size
R/S --> 6 // Answer for how many square fit inside a rectangle

Program: Maximum Square Area inside a Rectangle
Quote:01 STO 1
02 X<>Y
03 STO 2
04 x
05 STO 3
06 RCL 1
07 RCL 2
08 X≤Y?
09 X<>Y
10 X<>Y
11 - // Subtraction or minus sign
12 LSTx
13 X<>Y
14 X=0?
15 GTO 17
16 GTO 08
17 X<>Y
18 R/S
19 ENTER
20 x
21 RCL 3
22 X<>Y
23 ÷
24 GTO 00

Gamo
07-11-2018, 06:59 AM (This post was last modified: 07-11-2018 07:09 AM by Dieter.)
Post: #2
 Dieter Senior Member Posts: 2,397 Joined: Dec 2013
RE: (12C) Maximum Size of Square Area in a Rectangle
(07-11-2018 05:00 AM)Gamo Wrote:  This program calculate the exact "Maximum Size of the Square Area" and
how many Squares fit inside a Rectangle.

I am not sure if you have realized it, but this maximum square size simply is the Greatest Common Divisor (GCD) of the two numbers. So you can use the GCD program posted some time ago instead.

On the other hand the current program can be improved. Take a closer look: you store the input in R1 and R2 but then these two registers are only used once to recall the original input before the loop starts.

He is another version:

Code:
01 STO 0 02 X<>Y 03 STOx0   // store a*b in R0 while the input in X and Y is preserved 04 X≤Y? 05 X<>Y 06 X<>Y 07  - 08 X=0? 09 GTO 13 10 LSTx 11 X<>Y 12 GTO 04 13 LSTx 14 STO÷0   // divide a*b by (square size)^2 15 ST0÷0   // and keep the result in R0 16 RCL 0 17 X<>Y 18 GTO 00

Example:

4 [ENTER] 6
[R/S]   => 2
[X<>Y] => 6

Dieter
 « Next Oldest | Next Newest »

User(s) browsing this thread: 1 Guest(s)