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 / exercises / isbn-verifier / .meta / example.om

32 lines · 748 bytes Raw Blame History
1note Exercism-style exercise "isbn-verifier": https://exercism.org/tracks/python/exercises/isbn-verifier
2note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3note isvalid is true when isbn, with its hyphens removed, is a valid ISBN-10: nine digits and a check
4note digit or X (10), such that d1*10 + d2*9 + ... + d10*1 is divisible by 11.
5note Check it with: sh exercise.sh exercises/isbn-verifier
6om2
7fn isvalid isbn view uchar * to bool
8k = ulong 0
9t = ulong 0
10for i ulong len isbn
11c = get isbn i
12if eq c 45
13continue
14end
15d = ulong 0
16if and ge c 48 le c 57
17d = ulong sub c 48
18else
19if and eq c 88 eq k 9
20d = ulong 10
21else
22ret false
23end
24end
25if ge k 10
26ret false
27end
28t = add t mul d sub 10 k
29k = add k 1
30end
31ret and eq k 10 eq rem t 11 0
32end