interplane.Get Omega
Read in your language

omega-mv

Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.

Brought by drakestapleton

branch main Branches Tags History

omega-mv / si / rosetta / exercises / knapsack / .meta / example.om

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