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/exercises/knapsack/.meta/example.om # 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 / exercises / knapsack / .meta / example.om` 29 lines ยท 792 bytes Raw Blame History 1 note Exercism-style exercise "knapsack": https://exercism.org/tracks/python/exercises/knapsack 2 note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 3 note Item i weighs ws[i] and is worth vs[i]. maximumvalue is the largest total worth of items (each 4 note taken at most once) whose total weight is at most cap (cap at most 1000). 5 note Check it with: sh exercise.sh exercises/knapsack 6 om2 7 const KMAX ulong 1001 8 global kdp ulong KMAX 9 fn additem w ulong v ulong cap ulong to void 10 for k ulong add sub cap w 1 11 d = sub cap k 12 x = add get kdp sub d w v 13 if gt x get kdp d 14 put kdp d x 15 end 16 end 17 end 18 fn maximumvalue ws view ulong * vs view ulong * cap ulong to ulong 19 for c ulong add cap 1 20 put kdp c 0 21 end 22 for i ulong len ws 23 w = get ws i 24 if le w cap 25 additem w get vs i cap 26 end 27 end 28 ret get kdp cap 29 end