Skip to content

Instantly share code, notes, and snippets.

@roman-on
Created April 9, 2020 01:04
Show Gist options
  • Save roman-on/98d8f8ddb0bc7506835b5d42d66353cb to your computer and use it in GitHub Desktop.
Save roman-on/98d8f8ddb0bc7506835b5d42d66353cb to your computer and use it in GitHub Desktop.
# We would like to connect chocolate cubes to a row x cm long. We have -
# - small chocolate cubes 1 cm long and 5 cm large chocolate cubes.
# The function receives the number of small cubes (small), the number of large cubes (big), -
# - and the desired line length (x). The function returns true -
# - if it is possible to create an x-length row using the number of all or part of the chocolate cubes received.
>>> chocolate_maker(3, 1, 8)
True
>>> chocolate_maker(3, 1, 9)
False
>>> chocolate_maker(3, 2, 10)
True
# gil gave to try:
chocolate_maker(0, 3, 13)
False
def chocolate_maker(small, big, x):
small_cube = 1 * small
big_cube = 5 * big
if (small_cube + big_cube) >= x and x % 5 <= small_cube:
return True
else:
return False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment