interplane.Get Omega
Read in your language

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

branch main Branches Tags History

omega-mv / si / rosetta / tasks / isbn13-check-digit / isbn13-check-digit.om

53 lines · 1010 bytes Raw Blame History
1note Rosetta Code task "ISBN13 check digit": https://rosettacode.org/wiki/ISBN13_check_digit
2note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3om2
4text nl "\n"
5text tgood ": good\n"
6text tbad ": bad\n"
7text i1 "978-0596528126"
8text i2 "978-0596528120"
9text i3 "978-1788399081"
10text i4 "978-1788399083"
11note emit writes every byte of a to stdout; a short write is retried, an error exits 1
12fn emit a view uchar * to void
13o = ulong 0
14while lt o len a bound 4096
15k = write 1 a o sub len a o
16if le k 0
17exit 1
18end
19o = add o ulong k
20end
21end
22note digits weigh 1, 3, 1, 3, ... skipping hyphens; valid when there are 13 and the sum is 0 mod 10
23fn isbn a view uchar * to bool
24s = ulong 0
25k = ulong 0
26for i ulong len a
27c = get a i
28if and ge c 48 le c 57
29d = ulong sub c 48
30if eq rem k 2 1
31d = mul d 3
32end
33s = add s d
34k = add k 1
35end
36end
37ret and eq k 13 eq rem s 10 0
38end
39fn show a view uchar * to void
40emit a
41if isbn a
42emit tgood
43else
44emit tbad
45end
46end
47fn main to int
48show i1
49show i2
50show i3
51show i4
52ret 0
53end