interplane.Get Omega
Read in your language

omega-rosetta

aien-dev/omega-rosetta

Brought by drakestapleton

branch main Branches Tags History

omega-rosetta / exercises / bob / .meta / example.om

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