Created
July 8, 2022 02:56
-
-
Save dwcoltri/99550f97c1266c178cb686922392928b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
def minimal_number_of_packages( | |
items, available_large_packages, available_small_packages | |
): | |
""" | |
Given a list of items and the number of large and small packages available, | |
return the minimum number of packages needed to fulfill the items. | |
large packages hold 5 items | |
small packages holds 1 item | |
""" | |
max_slots = (available_large_packages * 5) + available_small_packages | |
if items > max_slots: | |
return -1 | |
sets_of_5_items = int(items / 5) | |
extra_items = items % 5 | |
total_extra_items = 0 | |
if sets_of_5_items >= available_large_packages: | |
extra_sets_of_5_items = sets_of_5_items - available_large_packages | |
total_extra_items = extra_sets_of_5_items * 5 + extra_items | |
if sets_of_5_items < available_large_packages: | |
extra_sets_of_5_items = 0 | |
total_extra_items = extra_items | |
total_boxes = sets_of_5_items - extra_sets_of_5_items + total_extra_items | |
return total_boxes | |
print(minimal_number_of_packages(16, 2, 10)) | |
print(minimal_number_of_packages(1, 2, 10)) | |
print(minimal_number_of_packages(11, 0, 1)) | |
print(minimal_number_of_packages(5, 5, 5)) | |
print(minimal_number_of_packages(10, 0, 0)) | |
print(minimal_number_of_packages(3, 0, 10)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment