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 / allergies / .meta / example.om

106 lines · 1853 bytes Raw Blame History
1note Exercism-style exercise "allergies": https://exercism.org/tracks/python/exercises/allergies
2note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3note The allergens in score order are eggs 1, peanuts 2, shellfish 4, strawberries 8, tomatoes 16,
4note chocolate 32, pollen 64, cats 128; a score is the sum of the allergens (higher bits are ignored).
5note allergicto is true when score includes item; list writes the allergens of score, in that order,
6note joined by commas, into o and returns the number of bytes written.
7note Check it with: sh exercise.sh exercises/allergies
8om2
9text al0 "eggs"
10text al1 "peanuts"
11text al2 "shellfish"
12text al3 "strawberries"
13text al4 "tomatoes"
14text al5 "chocolate"
15text al6 "pollen"
16text al7 "cats"
17fn same a view uchar * b view uchar * to bool
18if ne len a len b
19ret false
20end
21for i ulong len a
22if ne get a i get b i
23ret false
24end
25end
26ret true
27end
28fn app o edit uchar * p ulong s view uchar * to ulong
29q = p
30for i ulong len s
31put o q get s i
32q = add q 1
33end
34ret q
35end
36fn itemidx item view uchar * to ulong
37if same item al0
38ret 0
39end
40if same item al1
41ret 1
42end
43if same item al2
44ret 2
45end
46if same item al3
47ret 3
48end
49if same item al4
50ret 4
51end
52if same item al5
53ret 5
54end
55if same item al6
56ret 6
57end
58if same item al7
59ret 7
60end
61ret 8
62end
63fn allergicto item view uchar * score ulong to bool
64k = itemidx item
65if eq k 8
66ret false
67end
68ret ne and shr score k 1 0
69end
70fn appitem o edit uchar * p ulong k ulong to ulong
71if eq k 0
72ret app o p al0
73end
74if eq k 1
75ret app o p al1
76end
77if eq k 2
78ret app o p al2
79end
80if eq k 3
81ret app o p al3
82end
83if eq k 4
84ret app o p al4
85end
86if eq k 5
87ret app o p al5
88end
89if eq k 6
90ret app o p al6
91end
92ret app o p al7
93end
94fn list score ulong o edit uchar * to ulong
95p = ulong 0
96for k ulong 8
97if ne and shr score k 1 0
98if gt p 0
99put o p 44
100p = add p 1
101end
102p = appitem o p k
103end
104end
105ret p
106end