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/ludic-numbers/ludic-numbers.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 / ludic-numbers / ludic-numbers.om` 106 lines ยท 2042 bytes Raw Blame History 1 note Rosetta Code task "Ludic numbers": https://rosettacode.org/wiki/Ludic_numbers 2 note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 3 om2 4 text nl "\n" 5 text sp " " 6 text first "first 25 ludic numbers:" 7 text upto "ludic numbers <= 1000: " 8 text tfrom "2000th to 2005th ludic numbers:" 9 text trip "ludic triplets (x, x+2, x+6) below 250:" 10 text lp " (" 11 text cm ", " 12 text rp ")" 13 note the sieve runs on 2..21999; the 2005th ludic number, 21511, is below that limit, and every ludic number 14 note found is final because removing every k-th survivor never touches the survivors in front of it 15 global ls ulong 22000 16 global lu ulong 22000 17 global isl uchar 22000 18 note emit writes every byte of a to stdout; a short write is retried, an error exits 1 19 fn emit a view uchar * to void 20 o = ulong 0 21 while lt o len a bound 4096 22 k = write 1 a o sub len a o 23 if le k 0 24 exit 1 25 end 26 o = add o ulong k 27 end 28 end 29 note emitu writes n in decimal; 20 digits hold every ulong 30 fn emitu n ulong to void 31 d = new uchar 20 0 32 i = ulong 20 33 v = n 34 while true bound 20 35 i = sub i 1 36 put d i uchar add rem v 10 48 37 v = div v 10 38 if eq v 0 39 break 40 end 41 end 42 emit part d i sub 20 i 43 end 44 note round: the first survivor k is ludic; it and every k-th survivor after it (positions 0, k, 2k, ...) go 45 note bound: each round removes at least one survivor, so at most 21998 rounds over at most 21998 survivors 46 fn main to int 47 n = ulong 0 48 for i ulong 21998 49 put ls i add i 2 50 n = add n 1 51 end 52 put lu 0 1 53 put isl 1 1 54 c = ulong 1 55 while gt n 0 bound 22000 56 k = get ls 0 57 put lu c k 58 put isl k 1 59 c = add c 1 60 m = ulong 0 61 for i ulong n 62 if ne rem i k 0 63 put ls m get ls i 64 m = add m 1 65 end 66 end 67 n = m 68 end 69 emit first 70 for i ulong 25 71 emit sp 72 emitu get lu i 73 end 74 emit nl 75 emit upto 76 m = ulong 0 77 for i ulong c 78 if le get lu i 1000 79 m = add m 1 80 end 81 end 82 emitu m 83 emit nl 84 emit tfrom 85 for i ulong 6 86 emit sp 87 emitu get lu add 1999 i 88 end 89 emit nl 90 emit trip 91 for x ulong 244 92 if eq get isl x 1 93 if and eq get isl add x 2 1 eq get isl add x 6 1 94 emit lp 95 emitu x 96 emit cm 97 emitu add x 2 98 emit cm 99 emitu add x 6 100 emit rp 101 end 102 end 103 end 104 emit nl 105 ret 0 106 end