Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-rosetta/blob/main/tasks/knapsack-problem-unbounded/oracle.py # omega-rosetta aien-dev/omega-rosetta Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-rosetta / tasks / knapsack-problem-unbounded / oracle.py` 16 lines ยท 868 bytes Raw Blame History 1 # Independent reference for "Knapsack problem/Unbounded" (Python 3, standard library only). 2 # expected.txt is this program's stdout; omc never produced it. 3 from fractions import Fraction as F 4 from itertools import product 5 items = [("panacea", 3000, F("0.3"), F("0.025")), ("ichor", 1800, F("0.2"), F("0.015")), ("gold", 2500, F("2.0"), F("0.002"))] 6 W, V = F(25), F("0.25") 7 fits = [] 8 for n in product(*(range(int(min(W / w, V / v)) + 1) for _, _, w, v in items)): 9 w = sum(k * it[2] for k, it in zip(n, items)) 10 v = sum(k * it[3] for k, it in zip(n, items)) 11 if w <= W and v <= V: 12 fits.append((sum(k * it[1] for k, it in zip(n, items)), n, w, v)) 13 best = max(f[0] for f in fits) 14 print("panacea ichor gold value weight volume") 15 for val, n, w, v in sorted(f for f in fits if f[0] == best): 16 print(*n, val, f"{int(w * 10)}/10", f"{int(v * 1000)}/1000")