omega-rosetta
aien-dev/omega-rosetta
Brought by drakestapleton
omega-rosetta / exercises / bob / .meta / example.om
| 1 | note Exercism-style exercise "bob": https://exercism.org/tracks/python/exercises/bob |
| 2 | note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 3 | note response writes Bob's reply to s into o and returns its length. Silence (only spaces, tabs, |
| 4 | note CR, LF): "Fine. Be that way!". A yelled question: "Calm down, I know what I'm doing!". Yelling |
| 5 | note (some letter, no lower-case letter): "Whoa, chill out!". A question (last non-space byte is |
| 6 | note "?"): "Sure.". Anything else: "Whatever.". |
| 7 | note Check it with: sh exercise.sh exercises/bob |
| 8 | om2 |
| 9 | text bfine "Fine. Be that way!" |
| 10 | text bcalm "Calm down, I know what I'm doing!" |
| 11 | text bwhoa "Whoa, chill out!" |
| 12 | text bsure "Sure." |
| 13 | text bwhat "Whatever." |
| 14 | fn app o edit uchar * p ulong s view uchar * to ulong |
| 15 | q = p |
| 16 | for i ulong len s |
| 17 | put o q get s i |
| 18 | q = add q 1 |
| 19 | end |
| 20 | ret q |
| 21 | end |
| 22 | fn lastbyte s view uchar * to uchar |
| 23 | last = uchar 0 |
| 24 | for i ulong len s |
| 25 | c = get s i |
| 26 | if not or or or eq c 32 eq c 9 eq c 10 eq c 13 |
| 27 | last = c |
| 28 | end |
| 29 | end |
| 30 | ret last |
| 31 | end |
| 32 | fn hasrange s view uchar * lo uchar hi uchar to bool |
| 33 | for i ulong len s |
| 34 | c = get s i |
| 35 | if and ge c lo le c hi |
| 36 | ret true |
| 37 | end |
| 38 | end |
| 39 | ret false |
| 40 | end |
| 41 | fn response s view uchar * o edit uchar * to ulong |
| 42 | last = lastbyte s |
| 43 | up = hasrange s 65 90 |
| 44 | lo = hasrange s 97 122 |
| 45 | if eq last 0 |
| 46 | ret app o 0 bfine |
| 47 | end |
| 48 | yell = and up not lo |
| 49 | q = eq last 63 |
| 50 | if and yell q |
| 51 | ret app o 0 bcalm |
| 52 | end |
| 53 | if yell |
| 54 | ret app o 0 bwhoa |
| 55 | end |
| 56 | if q |
| 57 | ret app o 0 bsure |
| 58 | end |
| 59 | ret app o 0 bwhat |
| 60 | end |