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/drafts/rosettacode/greatest-common-divisor.wiki # 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 / drafts / rosettacode / greatest-common-divisor.wiki` 74 lines ยท 1395 bytes Raw Blame History 1 =={{header|Omegese}}== 2 {{works with|omc|sha256 `2c824805`, aien-dev/omega-mv `e5b32567`, Linux AArch64}} 3 Omega has no imports, so the small output helpers (emit and friends) are part of the program. 4 5 om2 6 text nl "\n" 7 text pre "gcd(" 8 text cm ", " 9 text post ") = " 10 note emit writes every byte of a to stdout; a short write is retried, an error exits 1 11 fn emit a view uchar * to void 12 o = ulong 0 13 while lt o len a bound 4096 14 k = write 1 a o sub len a o 15 if le k 0 16 exit 1 17 end 18 o = add o ulong k 19 end 20 end 21 note emitu writes n in decimal; 20 digits hold every ulong 22 fn emitu n ulong to void 23 d = new uchar 20 0 24 i = ulong 20 25 v = n 26 while true bound 20 27 i = sub i 1 28 put d i uchar add rem v 10 48 29 v = div v 10 30 if eq v 0 31 break 32 end 33 end 34 emit part d i sub 20 i 35 end 36 note Euclid; by Lame's theorem two 64-bit numbers need fewer than 100 steps 37 fn gcd a ulong b ulong to ulong 38 x = a 39 y = b 40 while ne y 0 bound 100 41 t = rem x y 42 x = y 43 y = t 44 end 45 ret x 46 end 47 fn show a ulong b ulong to void 48 emit pre 49 emitu a 50 emit cm 51 emitu b 52 emit post 53 emitu gcd a b 54 emit nl 55 end 56 fn main to int 57 show 1071 1029 58 show 40902 24140 59 show 12 18 60 show 17 5 61 show 0 5 62 show `18446744073709551615` `6148914691236517205` 63 ret 0 64 end 65 66 {{out}} 67

68 gcd(1071, 1029) = 21

69 gcd(40902, 24140) = 34

70 gcd(12, 18) = 6

71 gcd(17, 5) = 1

72 gcd(0, 5) = 5

73 gcd(`18446744073709551615`, `6148914691236517205`) = `6148914691236517205`

74