interplane.Get Omega
Read in your language

omega-rosetta

aien-dev/omega-rosetta

Brought by drakestapleton

branch main Branches Tags History

omega-rosetta / exercises / secret-handshake / .meta / example.om

49 lines · 1043 bytes Raw Blame History
1note Exercism-style exercise "secret-handshake": https://exercism.org/tracks/python/exercises/secret-handshake
2note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3note commands writes the handshake of the low five bits of n into o, joined by commas: 1 wink,
4note 2 double blink, 4 close your eyes, 8 jump, in that order, reversed when bit 16 is set; returns
5note the number of bytes written.
6note Check it with: sh exercise.sh exercises/secret-handshake
7om2
8text hs0 "wink"
9text hs1 "double blink"
10text hs2 "close your eyes"
11text hs3 "jump"
12fn app o edit uchar * p ulong s view uchar * to ulong
13q = p
14for i ulong len s
15put o q get s i
16q = add q 1
17end
18ret q
19end
20fn appcmd o edit uchar * p ulong k ulong to ulong
21if eq k 0
22ret app o p hs0
23end
24if eq k 1
25ret app o p hs1
26end
27if eq k 2
28ret app o p hs2
29end
30ret app o p hs3
31end
32fn commands n ulong o edit uchar * to ulong
33p = ulong 0
34rev = ne and n 16 0
35for i ulong 4
36k = i
37if rev
38k = sub 3 i
39end
40if ne and shr n k 1 0
41if gt p 0
42put o p 44
43p = add p 1
44end
45p = appcmd o p k
46end
47end
48ret p
49end