Skip to content

Instantly share code, notes, and snippets.

@mrdoornbos
Created March 21, 2024 14:07
Show Gist options
  • Save mrdoornbos/8fb7bbb52ea592e84700257e513aa044 to your computer and use it in GitHub Desktop.
Save mrdoornbos/8fb7bbb52ea592e84700257e513aa044 to your computer and use it in GitHub Desktop.
pack_sizes = [4, 6, 10, 20, 40]
max_search_range = max(pack_sizes) * 3 # Heuristic to ensure we cover enough range
possible_totals = set([0]) # Initialize with 0, as we can always buy 0 McNuggets
# Iteratively find all possible totals that can be made with given pack sizes
for pack_size in pack_sizes:
new_totals = set()
for total in possible_totals:
new_total = total
while new_total <= max_search_range:
new_total += pack_size
new_totals.add(new_total)
possible_totals.update(new_totals)
# Now find the largest number that cannot be formed
all_numbers = set(range(1, max_search_range + 1))
impossible_numbers = all_numbers - possible_totals
max_non_mcnuggets_number = max(impossible_numbers)
print("Maximum non-McNuggets number is:", max_non_mcnuggets_number)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment