Rectangle into Squares
Description:
The drawing below gives an idea of how to cut a given "true" rectangle into squares ("true" rectangle meaning that the two dimensions are different).
Can you translate this drawing into an algorithm?
You will be given two dimensions
- a positive integer length
- a positive integer width
You will return a collection or a string (depending on the language; Shell bash, PowerShell, Pascal and Fortran return a string) with the size of each of the squares.
Examples in general form:
(depending on the language)
sqInRect(5, 3) should return [3, 2, 1, 1]
sqInRect(3, 5) should return [3, 2, 1, 1]
You can see examples for your language in **"SAMPLE TESTS".**
Notes:
lng == wdth
as a starting case would be an entirely different problem and the drawing is planned to be interpreted withlng != wdth
. (See kata, Square into Squares. Protect trees! http://www.codewars.com/kata/54eb33e5bc1a25440d000891 for this problem).When the initial parameters are so that
lng
==wdth
, the solution[lng]
would be the most obvious but not in the spirit of this kata so, in that case, returnNone
/nil
/null
/Nothing
or return{}
with C++,[]
with Perl, Raku.In that case the returned structure of C will have its
sz
component equal to0
.Return the string
"nil"
with Bash, PowerShell, Pascal and Fortran.
Similar Kata:
Stats:
Created | May 3, 2015 |
Published | May 3, 2015 |
Warriors Trained | 94358 |
Total Skips | 21990 |
Total Code Submissions | 140614 |
Total Times Completed | 33331 |
Python Completions | 10148 |
Ruby Completions | 680 |
Java Completions | 4087 |
C# Completions | 1987 |
Clojure Completions | 248 |
JavaScript Completions | 6024 |
Haskell Completions | 506 |
CoffeeScript Completions | 34 |
C++ Completions | 3026 |
Elixir Completions | 280 |
TypeScript Completions | 1111 |
PHP Completions | 1330 |
Crystal Completions | 19 |
F# Completions | 96 |
C Completions | 740 |
Rust Completions | 901 |
Swift Completions | 604 |
R Completions | 165 |
Shell Completions | 126 |
OCaml Completions | 75 |
Fortran Completions | 16 |
Julia Completions | 68 |
Scala Completions | 219 |
PowerShell Completions | 64 |
Go Completions | 1000 |
Nim Completions | 19 |
Kotlin Completions | 681 |
Racket Completions | 51 |
Reason Completions | 6 |
Pascal Completions | 12 |
Factor Completions | 11 |
Raku Completions | 8 |
Perl Completions | 27 |
Elm Completions | 7 |
D Completions | 9 |
COBOL Completions | 6 |
Erlang Completions | 13 |
Prolog Completions | 17 |
Total Stars | 1401 |
% of votes with a positive feedback rating | 90% of 3848 |
Total "Very Satisfied" Votes | 3128 |
Total "Somewhat Satisfied" Votes | 638 |
Total "Not Satisfied" Votes | 82 |