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

91 lines · 1660 bytes Raw Blame History
1note Exercism-style exercise "resistor-color": https://exercism.org/tracks/python/exercises/resistor-color
2note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3note The band colors in value order are black brown red orange yellow green blue violet grey white
4note (0 .. 9). colorcode is the value of color (10 when it is not a band color); colors writes all
5note the band colors in value order, joined by commas, into o and returns the number of bytes written.
6note Check it with: sh exercise.sh exercises/resistor-color
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 app o edit uchar * p ulong s view uchar * to ulong
30q = p
31for i ulong len s
32put o q get s i
33q = add q 1
34end
35ret q
36end
37fn colorcode color view uchar * to ulong
38if same color rc0
39ret 0
40end
41if same color rc1
42ret 1
43end
44if same color rc2
45ret 2
46end
47if same color rc3
48ret 3
49end
50if same color rc4
51ret 4
52end
53if same color rc5
54ret 5
55end
56if same color rc6
57ret 6
58end
59if same color rc7
60ret 7
61end
62if same color rc8
63ret 8
64end
65if same color rc9
66ret 9
67end
68ret 10
69end
70fn colors o edit uchar * to ulong
71p = app o 0 rc0
72put o p 44
73p = app o add p 1 rc1
74put o p 44
75p = app o add p 1 rc2
76put o p 44
77p = app o add p 1 rc3
78put o p 44
79p = app o add p 1 rc4
80put o p 44
81p = app o add p 1 rc5
82put o p 44
83p = app o add p 1 rc6
84put o p 44
85p = app o add p 1 rc7
86put o p 44
87p = app o add p 1 rc8
88put o p 44
89p = app o add p 1 rc9
90ret p
91end