Skip to content

Instantly share code, notes, and snippets.

@kdeloach
Created September 19, 2019 13:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kdeloach/2050c7538000e267a5553d9e1ac18687 to your computer and use it in GitHub Desktop.
Save kdeloach/2050c7538000e267a5553d9e1ac18687 to your computer and use it in GitHub Desktop.
bar = 45
plates = [55, 45, 35, 25, 10, 10, 5, 5, 2.5]
min_weight = int(bar + min(plates) * 2)
max_weight = int(bar + sum(plates) * 2)
def greedy(goal):
goal -= bar
goal /= 2
out = []
for plate in plates:
if goal <= 0:
break
if plate > goal:
continue
goal -= plate
out.append(str(plate))
out = ', '.join(out)
return out
for weight in range(min_weight, max_weight + 1, 5):
plates_str = greedy(weight)
print(f'{weight}\t{plates_str}')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment