interplane.Get Omega
Read in your language

omega-rosetta

aien-dev/omega-rosetta

Brought by drakestapleton

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