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-mv/blob/main/si/rosetta/tasks/pythagorean-triples/pythagorean-triples.om # omega-mv Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance. Brought by drakestapleton Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / si / rosetta / tasks / pythagorean-triples / pythagorean-triples.om` 85 lines ยท 1592 bytes Raw Blame History 1 note Rosetta Code task "Pythagorean triples": https://rosettacode.org/wiki/Pythagorean_triples 2 note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 3 om2 4 text nl "\n" 5 text pre "perimeter <= " 6 text col ": " 7 text tr " triples, " 8 text pr " primitive\n" 9 note emit writes every byte of a to stdout; a short write is retried, an error exits 1 10 fn emit a view uchar * to void 11 o = ulong 0 12 while lt o len a bound 4096 13 k = write 1 a o sub len a o 14 if le k 0 15 exit 1 16 end 17 o = add o ulong k 18 end 19 end 20 note emitu writes n in decimal; 20 digits hold every ulong 21 fn emitu n ulong to void 22 d = new uchar 20 0 23 i = ulong 20 24 v = n 25 while true bound 20 26 i = sub i 1 27 put d i uchar add rem v 10 48 28 v = div v 10 29 if eq v 0 30 break 31 end 32 end 33 emit part d i sub 20 i 34 end 35 fn gcd a ulong b ulong to ulong 36 x = a 37 y = b 38 while ne y 0 bound 128 39 t = rem x y 40 x = y 41 y = t 42 end 43 ret x 44 end 45 note Euclid: m > n > 0 coprime of opposite parity give each primitive triple once, with perimeter 2m(m+n); 46 note a primitive perimeter p counts for limit L once as primitive and L / p times among all triples 47 note bound: 2m(m+1) <= 10^7 needs m <= 2235 48 fn main to int 49 pc = new ulong 7 0 50 tc = new ulong 7 0 51 m = ulong 2 52 while le mul mul 2 m add m 1 `10000000` bound 2236 53 n = add rem m 2 1 54 while lt n m bound 2236 55 p = mul mul 2 m add m n 56 if gt p `10000000` 57 break 58 end 59 if eq gcd m n 1 60 l = ulong 100 61 for k ulong 6 62 if le p l 63 put pc k add get pc k 1 64 put tc k add get tc k div l p 65 end 66 l = mul l 10 67 end 68 end 69 n = add n 2 70 end 71 m = add m 1 72 end 73 l = ulong 100 74 for k ulong 6 75 emit pre 76 emitu l 77 emit col 78 emitu get tc k 79 emit tr 80 emitu get pc k 81 emit pr 82 l = mul l 10 83 end 84 ret 0 85 end