omega-rosetta
aien-dev/omega-rosetta
Brought by drakestapleton
omega-rosetta / exercises / resistor-color / .meta / example.om
| 1 | note Exercism-style exercise "resistor-color": https://exercism.org/tracks/python/exercises/resistor-color |
| 2 | note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 3 | note The band colors in value order are black brown red orange yellow green blue violet grey white |
| 4 | note (0 .. 9). colorcode is the value of color (10 when it is not a band color); colors writes all |
| 5 | note the band colors in value order, joined by commas, into o and returns the number of bytes written. |
| 6 | note Check it with: sh exercise.sh exercises/resistor-color |
| 7 | om2 |
| 8 | text rc0 "black" |
| 9 | text rc1 "brown" |
| 10 | text rc2 "red" |
| 11 | text rc3 "orange" |
| 12 | text rc4 "yellow" |
| 13 | text rc5 "green" |
| 14 | text rc6 "blue" |
| 15 | text rc7 "violet" |
| 16 | text rc8 "grey" |
| 17 | text rc9 "white" |
| 18 | fn same a view uchar * b view uchar * to bool |
| 19 | if ne len a len b |
| 20 | ret false |
| 21 | end |
| 22 | for i ulong len a |
| 23 | if ne get a i get b i |
| 24 | ret false |
| 25 | end |
| 26 | end |
| 27 | ret true |
| 28 | end |
| 29 | fn app o edit uchar * p ulong s view uchar * to ulong |
| 30 | q = p |
| 31 | for i ulong len s |
| 32 | put o q get s i |
| 33 | q = add q 1 |
| 34 | end |
| 35 | ret q |
| 36 | end |
| 37 | fn colorcode color view uchar * to ulong |
| 38 | if same color rc0 |
| 39 | ret 0 |
| 40 | end |
| 41 | if same color rc1 |
| 42 | ret 1 |
| 43 | end |
| 44 | if same color rc2 |
| 45 | ret 2 |
| 46 | end |
| 47 | if same color rc3 |
| 48 | ret 3 |
| 49 | end |
| 50 | if same color rc4 |
| 51 | ret 4 |
| 52 | end |
| 53 | if same color rc5 |
| 54 | ret 5 |
| 55 | end |
| 56 | if same color rc6 |
| 57 | ret 6 |
| 58 | end |
| 59 | if same color rc7 |
| 60 | ret 7 |
| 61 | end |
| 62 | if same color rc8 |
| 63 | ret 8 |
| 64 | end |
| 65 | if same color rc9 |
| 66 | ret 9 |
| 67 | end |
| 68 | ret 10 |
| 69 | end |
| 70 | fn colors o edit uchar * to ulong |
| 71 | p = app o 0 rc0 |
| 72 | put o p 44 |
| 73 | p = app o add p 1 rc1 |
| 74 | put o p 44 |
| 75 | p = app o add p 1 rc2 |
| 76 | put o p 44 |
| 77 | p = app o add p 1 rc3 |
| 78 | put o p 44 |
| 79 | p = app o add p 1 rc4 |
| 80 | put o p 44 |
| 81 | p = app o add p 1 rc5 |
| 82 | put o p 44 |
| 83 | p = app o add p 1 rc6 |
| 84 | put o p 44 |
| 85 | p = app o add p 1 rc7 |
| 86 | put o p 44 |
| 87 | p = app o add p 1 rc8 |
| 88 | put o p 44 |
| 89 | p = app o add p 1 rc9 |
| 90 | ret p |
| 91 | end |