omega-rosetta
aien-dev/omega-rosetta
Brought by drakestapleton
omega-rosetta / drafts / rosettacode / thue-morse.wiki
| 1 | =={{header|Omegese}}== |
| 2 | {{works with|omc|sha256 2c824805, aien-dev/omega-mv e5b32567, Linux AArch64}} |
| 3 | Omega has no imports, so the small output helpers (<code>emit</code> and friends) are part of the program. |
| 4 | <syntaxhighlight lang="text"> |
| 5 | om2 |
| 6 | text nl "\n" |
| 7 | note emit writes every byte of a to stdout; a short write is retried, an error exits 1 |
| 8 | fn emit a view uchar * to void |
| 9 | o = ulong 0 |
| 10 | while lt o len a bound 4096 |
| 11 | k = write 1 a o sub len a o |
| 12 | if le k 0 |
| 13 | exit 1 |
| 14 | end |
| 15 | o = add o ulong k |
| 16 | end |
| 17 | end |
| 18 | note emitc writes the single byte c |
| 19 | fn emitc c uchar to void |
| 20 | b = new uchar 1 c |
| 21 | emit b |
| 22 | end |
| 23 | note each step appends the bitwise complement of the sequence so far; 7 steps reach 64 terms |
| 24 | fn main to int |
| 25 | t = new uchar 64 0 |
| 26 | n = ulong 1 |
| 27 | for s ulong 7 |
| 28 | for i ulong n |
| 29 | emitc add get t i uchar 48 |
| 30 | end |
| 31 | emit nl |
| 32 | if lt n 64 |
| 33 | for i ulong n |
| 34 | put t add n i sub uchar 1 get t i |
| 35 | end |
| 36 | n = mul n 2 |
| 37 | end |
| 38 | end |
| 39 | ret 0 |
| 40 | end |
| 41 | </syntaxhighlight> |
| 42 | {{out}} |
| 43 | <pre> |
| 44 | 0 |
| 45 | 01 |
| 46 | 0110 |
| 47 | 01101001 |
| 48 | 0110100110010110 |
| 49 | 01101001100101101001011001101001 |
| 50 | 0110100110010110100101100110100110010110011010010110100110010110 |
| 51 | </pre> |