## DEV Community is a community of 749,631 amazing developers

We're a place where coders share, stay up-to-date and grow their careers.

# Daily Challenge #133 - Suitcase Packing

Mr. Square is going on holiday. He wants to bring 2 of his favorite squares with him, so he put them in his rectangle suitcase.

Write a function that, given the size of the squares and the suitcase, return whether the squares can fit inside the suitcase.

`fit_in(a,b,m,n)`
`a,b are the sizes of the squares`
`m,n are the sizes of the suitcase`

Example
`fit_in(1,2,3,2) should return True`
`fit_in(1,2,2,1) should return False`
`fit_in(3,2,3,2) should return False`
`fit_in(1,2,1,2) should return False`

This challenge comes from SADragonMaker on CodeWars. Thank you to CodeWars, who has licensed redistribution of this challenge under the 2-Clause BSD License!

Want to propose a challenge idea for a future post? Email yo+challenge@dev.to with your suggestions!

## Discussion (9) Andreas Jakof • Edited on

The long side is the obvious case, but what if

• Square A: 1x1
• Square B: 2x2
• Rectangle 3x1

=> FitIn(1,2,3,1)?

in C#

``````public bool FitIn(int a, int b, int m, int n)
{
//both squares (added) must fit into the long side of the rectangle AND
//the bigger single square must fit into the short side of the rectangle

int longSide = Math.Max(m,n);
int shortSide = Math.Min(m,n);
int addedSquareLengths = a + b;
int biggerSingleSquareSize = Math.Max(a,b);

//do they fit?
bool fitsLong = addedSquareLengths <= longSide;
bool fitsShort = biggerSingleSquareSize <= shortSide;

return fitsLong && fitsShort;
}
``````

I know, it's a bit verbose, but very self explanatory. A short version will look like this:

``````public bool FitIn(int a, int b, int m, int n) =>
(a + b <= Math.Max(m,n)) && //longSide
(Math.Max(a,b) <= Math.Min(m,n)); //shortSide
`````` Michael Kohl

You don't need to return `true` or `false` here explicitly, the comparison already has a boolean result.

``````
const fit_in = (a, b, m, n) => a + b <= Math.max(m, n)
`````` Andreas Jakof

`Assert.IsFalse(fit_in(1,2,3,1)` Nick Holmes

In F#.

``````let fit_in a b m n = a + b <= max m n
`````` Andreas Jakof
``````let actual = fit_in 1 2 3 1
Assert.That(actual, Is.False)
`````` Michael Kohl

Raku:

``````sub fit-in(\$a, \$b, \$m, \$n) { \$a + \$b <= max(\$m, \$n) }
``````