← Back to challenges

The Centrifuge Problem

PythonHardalgorithmsmathnumbersvalidation

Instructions

A centrifuge, as you probably know, is a laboratory device used to separate fluids based on density. The separation is achieved through centripetal force by spinning a collection of test tubes at high speeds. This means, the configuration needs to be in balance.

Create a function that takes two numbers as arguments n and k and returns True if the configuration is balanced and False if it's not.

The Centrifuge Problem with 6 Holes, n=6

Here are the valid configurations for n = 6, k = 2, 3, 4 and 6.

Examples

c_fuge(6, 4) ➞ True

c_fuge(2, 1) ➞ False

c_fuge(3, 3) ➞ True

Notes

  • One test tube k = 1 is never in balance.
  • One hole n = 1 is never in balance, even empty.
python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.