Skip to content

Instantly share code, notes, and snippets.

@TypeA2
Created July 13, 2025 08:52
Show Gist options
  • Select an option

  • Save TypeA2/d8af5c0edf867bcaa86094bda3bfa8f0 to your computer and use it in GitHub Desktop.

Select an option

Save TypeA2/d8af5c0edf867bcaa86094bda3bfa8f0 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
BDS = 3
ALBUMS = 6
CDS = 9
options: list[dict] = []
for bds in range(BDS + 1):
for albums in range(ALBUMS + 1):
for cds in range(CDS + 1):
total = (bds * 9900) + (albums * 3850) + (cds * 1540)
options.append({
"bds": bds,
"albums": albums,
"cds": cds,
"total": total,
"mod": total % 8000
})
assert options[0]["total"] == 0
options = options[1:]
options.sort(key=lambda k: k["mod"])
possible = 0
possible_list: list[list[int]] = []
def find_options(start: int, bds: int, albums: int, cds: int, indices: list[int]):
global possible, possible_list, options
res: list[dict] = []
for i in range(start, len(options)):
cur = options[i]
new_bds = bds + cur["bds"]
new_albums = albums + cur["albums"]
new_cds = cds + cur["cds"]
if new_bds > BDS or new_albums > ALBUMS or new_cds > CDS:
continue
if new_bds == BDS and new_albums == ALBUMS and new_cds == CDS:
possible += 1
possible_list.append(indices + [i])
continue
find_options(i + 1, new_bds, new_albums, new_cds, indices + [i])
return res
find_options(0, 0, 0, 0, [])
print(possible, "options")
excess_map: dict[int, list[list[int]]] = {}
for option in possible_list:
excess = 0
for idx in option:
excess += options[idx]["mod"]
if excess not in excess_map:
excess_map[excess] = [ option ]
else:
excess_map[excess].append(option)
print("Possible mod8000 values:", list(excess_map.keys()))
chosen = sorted(excess_map.keys())[0]
print(f"{len(excess_map[chosen])} options with an excess of {chosen}")
for combo in sorted(excess_map[chosen], key=lambda v: len(v)):
print("\nbds,albums,cds,total,waste")
for idx in combo:
bds = options[idx]["bds"]
albums = options[idx]["albums"]
cds = options[idx]["cds"]
total = options[idx]["total"]
waste = options[idx]["mod"]
print(f"{bds},{albums},{cds},{total},{waste}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment