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/isbn13-check-digit.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 / isbn13-check-digit.wiki` 63 lines ยท 1216 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 tgood ": good\n" 8 text tbad ": bad\n" 9 text i1 "978-`0596528126`" 10 text i2 "978-`0596528120`" 11 text i3 "978-`1788399081`" 12 text i4 "978-`1788399083`" 13 note emit writes every byte of a to stdout; a short write is retried, an error exits 1 14 fn emit a view uchar * to void 15 o = ulong 0 16 while lt o len a bound 4096 17 k = write 1 a o sub len a o 18 if le k 0 19 exit 1 20 end 21 o = add o ulong k 22 end 23 end 24 note digits weigh 1, 3, 1, 3, ... skipping hyphens; valid when there are 13 and the sum is 0 mod 10 25 fn isbn a view uchar * to bool 26 s = ulong 0 27 k = ulong 0 28 for i ulong len a 29 c = get a i 30 if and ge c 48 le c 57 31 d = ulong sub c 48 32 if eq rem k 2 1 33 d = mul d 3 34 end 35 s = add s d 36 k = add k 1 37 end 38 end 39 ret and eq k 13 eq rem s 10 0 40 end 41 fn show a view uchar * to void 42 emit a 43 if isbn a 44 emit tgood 45 else 46 emit tbad 47 end 48 end 49 fn main to int 50 show i1 51 show i2 52 show i3 53 show i4 54 ret 0 55 end 56 57 {{out}} 58

59 978-`0596528126`: good

60 978-`0596528120`: bad

61 978-`1788399081`: good

62 978-`1788399083`: bad

63