6 kyu

Rectangle into Squares

10,148 of 33,331g964

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).

alternative text

Can you translate this drawing into an algorithm?

You will be given two dimensions

  1. a positive integer length
  2. 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 with lng != 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, return None/nil/null/Nothing or return {} with C++, [] with Perl, Raku.

  • In that case the returned structure of C will have its sz component equal to 0.

  • Return the string "nil" with Bash, PowerShell, Pascal and Fortran.

Fundamentals
Geometry
Puzzles

More By Author:

Check out these other kata created by g964

Stats:

CreatedMay 3, 2015
PublishedMay 3, 2015
Warriors Trained94358
Total Skips21990
Total Code Submissions140614
Total Times Completed33331
Python Completions10148
Ruby Completions680
Java Completions4087
C# Completions1987
Clojure Completions248
JavaScript Completions6024
Haskell Completions506
CoffeeScript Completions34
C++ Completions3026
Elixir Completions280
TypeScript Completions1111
PHP Completions1330
Crystal Completions19
F# Completions96
C Completions740
Rust Completions901
Swift Completions604
R Completions165
Shell Completions126
OCaml Completions75
Fortran Completions16
Julia Completions68
Scala Completions219
PowerShell Completions64
Go Completions1000
Nim Completions19
Kotlin Completions681
Racket Completions51
Reason Completions6
Pascal Completions12
Factor Completions11
Raku Completions8
Perl Completions27
Elm Completions7
D Completions9
COBOL Completions6
Erlang Completions13
Prolog Completions17
Total Stars1401
% of votes with a positive feedback rating90% of 3848
Total "Very Satisfied" Votes3128
Total "Somewhat Satisfied" Votes638
Total "Not Satisfied" Votes82
Ad
Contributors
  • g964 Avatar
  • bkaes Avatar
  • GiacomoSorbi Avatar
  • ParanoidUser Avatar
  • kazk Avatar
  • Blind4Basics Avatar
  • Voile Avatar
  • Bubbler Avatar
  • monadius Avatar
  • hobovsky Avatar
  • trashy_incel Avatar
  • user8436785 Avatar
  • akar-0 Avatar
  • Kacarott Avatar
  • KayleighWasTaken Avatar
Ad