omega-rosetta
aien-dev/omega-rosetta
Brought by drakestapleton
omega-rosetta / drafts / rosettacode / wireworld.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 | text sp " " |
| 8 | text minus "-" |
| 9 | text tstart "tH.........|. . | ... |. . |Ht.. ......" |
| 10 | text tgen "generation " |
| 11 | global cur uchar 55 |
| 12 | global nxt uchar 55 |
| 13 | note emit writes every byte of a to stdout; a short write is retried, an error exits 1 |
| 14 | fn emit a view uchar * to void |
| 15 | o = ulong 0 |
| 16 | while lt o len a bound 4096 |
| 17 | k = write 1 a o sub len a o |
| 18 | if le k 0 |
| 19 | exit 1 |
| 20 | end |
| 21 | o = add o ulong k |
| 22 | end |
| 23 | end |
| 24 | note emitu writes n in decimal; 20 digits hold every ulong |
| 25 | fn emitu n ulong to void |
| 26 | d = new uchar 20 0 |
| 27 | i = ulong 20 |
| 28 | v = n |
| 29 | while true bound 20 |
| 30 | i = sub i 1 |
| 31 | put d i uchar add rem v 10 48 |
| 32 | v = div v 10 |
| 33 | if eq v 0 |
| 34 | break |
| 35 | end |
| 36 | end |
| 37 | emit part d i sub 20 i |
| 38 | end |
| 39 | note emitb writes the single byte c |
| 40 | fn emitb c ulong to void |
| 41 | d = new uchar 1 0 |
| 42 | put d 0 uchar c |
| 43 | emit d |
| 44 | end |
| 45 | note the 5 x 11 board from the task: H electron head, t tail, . conductor, space empty; a head becomes a |
| 46 | note tail, a tail a conductor, and a conductor a head when 1 or 2 of its 8 neighbours are heads |
| 47 | fn heads r long c long to ulong |
| 48 | n = ulong 0 |
| 49 | for a ulong 3 |
| 50 | for b ulong 3 |
| 51 | y = sub add r long a 1 |
| 52 | x = sub add c long b 1 |
| 53 | if and and ge y 0 lt y 5 and ge x 0 lt x 11 |
| 54 | if eq get cur add mul ulong y 11 ulong x 72 |
| 55 | n = add n 1 |
| 56 | end |
| 57 | end |
| 58 | end |
| 59 | end |
| 60 | ret n |
| 61 | end |
| 62 | fn rule k ulong n ulong to uchar |
| 63 | v = get cur k |
| 64 | if eq v 72 |
| 65 | ret 116 |
| 66 | end |
| 67 | if eq v 116 |
| 68 | ret 46 |
| 69 | end |
| 70 | if and eq v 46 or eq n 1 eq n 2 |
| 71 | ret 72 |
| 72 | end |
| 73 | ret v |
| 74 | end |
| 75 | fn step to void |
| 76 | for r ulong 5 |
| 77 | for c ulong 11 |
| 78 | k = add mul r 11 c |
| 79 | put nxt k rule k heads long r long c |
| 80 | end |
| 81 | end |
| 82 | for i ulong 55 |
| 83 | put cur i get nxt i |
| 84 | end |
| 85 | end |
| 86 | fn main to int |
| 87 | for r ulong 5 |
| 88 | for c ulong 11 |
| 89 | put cur add mul r 11 c get tstart add mul r 12 c |
| 90 | end |
| 91 | end |
| 92 | for g ulong 10 |
| 93 | emit tgen |
| 94 | emitu g |
| 95 | emit nl |
| 96 | for i ulong 55 |
| 97 | emitb ulong get cur i |
| 98 | if eq rem i 11 10 |
| 99 | emit nl |
| 100 | end |
| 101 | end |
| 102 | step |
| 103 | end |
| 104 | ret 0 |
| 105 | end |
| 106 | </syntaxhighlight> |
| 107 | {{out}} |
| 108 | <pre> |
| 109 | generation 0 |
| 110 | tH......... |
| 111 | . . |
| 112 | ... |
| 113 | . . |
| 114 | Ht.. ...... |
| 115 | generation 1 |
| 116 | .tH........ |
| 117 | H . |
| 118 | ... |
| 119 | H . |
| 120 | t... ...... |
| 121 | generation 2 |
| 122 | H.tH....... |
| 123 | t . |
| 124 | ... |
| 125 | t . |
| 126 | .H.t ...... |
| 127 | generation 9 |
| 128 | tH.tH.tH.tH |
| 129 | . H |
| 130 | ... |
| 131 | . . |
| 132 | HtH. ...... |
| 133 | </pre> |