Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-rosetta/blob/main/tasks/elementary-cellular-automaton/elementary-cellular-automaton.om # omega-rosetta aien-dev/omega-rosetta Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-rosetta / tasks / elementary-cellular-automaton / elementary-cellular-automaton.om` 81 lines ยท 1421 bytes Raw Blame History 1 note Rosetta Code task "Elementary cellular automaton": https://rosettacode.org/wiki/Elementary_cellular_automaton 2 note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 3 om2 4 text nl "\n" 5 text sp " " 6 text minus "-" 7 text trule "rule " 8 text tdot "." 9 text thash "#" 10 global cur uchar 32 11 global nxt uchar 32 12 note emit writes every byte of a to stdout; a short write is retried, an error exits 1 13 fn emit a view uchar * to void 14 o = ulong 0 15 while lt o len a bound 4096 16 k = write 1 a o sub len a o 17 if le k 0 18 exit 1 19 end 20 o = add o ulong k 21 end 22 end 23 note emitu writes n in decimal; 20 digits hold every ulong 24 fn emitu n ulong to void 25 d = new uchar 20 0 26 i = ulong 20 27 v = n 28 while true bound 20 29 i = sub i 1 30 put d i uchar add rem v 10 48 31 v = div v 10 32 if eq v 0 33 break 34 end 35 end 36 emit part d i sub 20 i 37 end 38 note 31 cells on a ring; a cell's next state is bit (4*left + 2*self + right) of the rule number 39 fn line to void 40 for i ulong 31 41 if eq get cur i 1 42 emit thash 43 else 44 emit tdot 45 end 46 end 47 emit nl 48 end 49 fn step rule ulong to void 50 for i ulong 31 51 l = ulong get cur rem add i 30 31 52 c = ulong get cur i 53 r = ulong get cur rem add i 1 31 54 k = add add mul l 4 mul c 2 r 55 put nxt i uchar and shr rule k 1 56 end 57 for i ulong 31 58 put cur i get nxt i 59 end 60 end 61 fn run rule ulong to void 62 emit trule 63 emitu rule 64 emit nl 65 for i ulong 31 66 put cur i 0 67 end 68 put cur 15 1 69 for g ulong 16 70 line 71 step rule 72 end 73 end 74 fn main to int 75 run 90 76 emit nl 77 run 30 78 emit nl 79 run 110 80 ret 0 81 end