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/floyds-triangle/floyds-triangle.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 / floyds-triangle / floyds-triangle.om` 81 lines ยท 1485 bytes Raw Blame History 1 note Rosetta Code task "Floyd's triangle": https://rosettacode.org/wiki/Floyd's_triangle 2 note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 3 om2 4 text nl "\n" 5 text sp " " 6 text minus "-" 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 emitu writes n in decimal; 20 digits hold every ulong 19 fn emitu n ulong to void 20 d = new uchar 20 0 21 i = ulong 20 22 v = n 23 while true bound 20 24 i = sub i 1 25 put d i uchar add rem v 10 48 26 v = div v 10 27 if eq v 0 28 break 29 end 30 end 31 emit part d i sub 20 i 32 end 33 note emitw writes n right-aligned in w columns (w at most 20; a wider number is not cut) 34 fn emitw n ulong w ulong to void 35 d = new uchar 20 32 36 i = ulong 20 37 v = n 38 while true bound 20 39 i = sub i 1 40 put d i uchar add rem v 10 48 41 v = div v 10 42 if eq v 0 43 break 44 end 45 end 46 if gt w sub 20 i 47 i = sub 20 w 48 end 49 emit part d i sub 20 i 50 end 51 note row r (from 0) holds r+1 consecutive numbers; column j is as wide as the last row's entry in 52 note column j, which is the widest in that column 53 fn digits v ulong to ulong 54 d = ulong 1 55 while ge v 10 bound 20 56 v = div v 10 57 d = add d 1 58 end 59 ret d 60 end 61 fn floyd n ulong to void 62 last = add div mul sub n 1 n 2 1 63 k = ulong 1 64 for r ulong n 65 for j ulong add r 1 66 w = digits add last j 67 if gt j 0 68 emit sp 69 end 70 emitw k w 71 k = add k 1 72 end 73 emit nl 74 end 75 end 76 fn main to int 77 floyd 5 78 emit nl 79 floyd 14 80 ret 0 81 end