← Back to challenges

Does the Cargo Fit? (Part 1)

PythonHardlogicmathstrings

Instructions

A ship has to transport cargo from one place to another, while picking up cargo along the way. Given the total amount of cargo and the types of cargo holds in the ship as lists, create a function that returns True if all the cargo can fit on the ship, and False if it can't.

  • "S" means 50 cargo space.
  • "M" means 100 cargo space.
  • "L" means 200 cargo space.

Examples

will_fit(["M", "L", "L", "M"], [56, 62, 84, 90]) ➞ True

will_fit(["S", "S", "S", "S", "L"], [40, 50, 60, 70, 80, 90, 200]) ➞ False

will_fit(["L", "L", "M"], [56, 62, 84, 90]) ➞ True

Notes

Calculate the cargo as a whole, and not for each separate cargo hold (see example #2).

python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.
Next: Rock, Paper, Scissors