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/look-and-say-sequence/look-and-say-sequence.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 / look-and-say-sequence / look-and-say-sequence.om` 70 lines ยท 1339 bytes Raw Blame History 1 note Rosetta Code task "Look-and-say sequence": https://rosettacode.org/wiki/Look-and-say_sequence 2 note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 3 om2 4 text nl "\n" 5 note emit writes every byte of a to stdout; a short write is retried, an error exits 1 6 fn emit a view uchar * to void 7 o = ulong 0 8 while lt o len a bound 4096 9 k = write 1 a o sub len a o 10 if le k 0 11 exit 1 12 end 13 o = add o ulong k 14 end 15 end 16 note emitu writes n in decimal; 20 digits hold every ulong 17 fn emitu n ulong to void 18 d = new uchar 20 0 19 i = ulong 20 20 v = n 21 while true bound 20 22 i = sub i 1 23 put d i uchar add rem v 10 48 24 v = div v 10 25 if eq v 0 26 break 27 end 28 end 29 emit part d i sub 20 i 30 end 31 note emitc writes the single byte c 32 fn emitc c uchar to void 33 b = new uchar 1 c 34 emit b 35 end 36 note each term reads the previous one as runs of equal digits, writing run length then digit 37 note bound: the 15th term has 102 digits; 256-byte buffers hold every term here, and no run is longer than 3 38 fn main to int 39 a = new uchar 256 0 40 b = new uchar 256 0 41 put a 0 1 42 n = ulong 1 43 for t ulong 15 44 for i ulong n 45 emitc add get a i uchar 48 46 end 47 emit nl 48 m = ulong 0 49 i = ulong 0 50 while lt i n bound 256 51 d = get a i 52 j = i 53 while lt j n bound 256 54 if ne get a j d 55 break 56 end 57 j = add j 1 58 end 59 put b m uchar sub j i 60 put b add m 1 d 61 m = add m 2 62 i = j 63 end 64 for k ulong m 65 put a k get b k 66 end 67 n = m 68 end 69 ret 0 70 end