interplane.Get Omega
Read in your language

omega-rosetta

aien-dev/omega-rosetta

Brought by drakestapleton

branch main Branches Tags History

omega-rosetta / exercises / resistor-color-duo / .meta / example.om

82 lines · 1453 bytes Raw Blame History
1note Exercism-style exercise "resistor-color-duo": https://exercism.org/tracks/python/exercises/resistor-color-duo
2note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3note colors holds band color names joined by commas. value is the two-digit number given by the
4note first two bands (black 0, brown 1, red 2, orange 3, yellow 4, green 5, blue 6, violet 7, grey 8,
5note white 9); further bands are ignored.
6note Check it with: sh exercise.sh exercises/resistor-color-duo
7om2
8text rc0 "black"
9text rc1 "brown"
10text rc2 "red"
11text rc3 "orange"
12text rc4 "yellow"
13text rc5 "green"
14text rc6 "blue"
15text rc7 "violet"
16text rc8 "grey"
17text rc9 "white"
18fn same a view uchar * b view uchar * to bool
19if ne len a len b
20ret false
21end
22for i ulong len a
23if ne get a i get b i
24ret false
25end
26end
27ret true
28end
29fn code color view uchar * to ulong
30if same color rc0
31ret 0
32end
33if same color rc1
34ret 1
35end
36if same color rc2
37ret 2
38end
39if same color rc3
40ret 3
41end
42if same color rc4
43ret 4
44end
45if same color rc5
46ret 5
47end
48if same color rc6
49ret 6
50end
51if same color rc7
52ret 7
53end
54if same color rc8
55ret 8
56end
57if same color rc9
58ret 9
59end
60ret 10
61end
62fn band cs view uchar * n ulong to ulong
63s = ulong 0
64f = ulong 0
65for i ulong add len cs 1
66stop = eq i len cs
67if not stop
68stop = eq get cs i 44
69end
70if stop
71if eq f n
72ret code part cs s sub i s
73end
74f = add f 1
75s = add i 1
76end
77end
78ret 10
79end
80fn value colors view uchar * to ulong
81ret add mul band colors 0 10 band colors 1
82end