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 / luhn / .meta / example.om

29 lines · 636 bytes Raw Blame History
1note Exercism-style exercise "luhn": https://exercism.org/tracks/python/exercises/luhn
2note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3note valid is true when s, after removing spaces, is at least two decimal digits (and nothing else)
4note that pass the Luhn checksum.
5note Check it with: sh exercise.sh exercises/luhn
6om2
7fn valid s view uchar * to bool
8n = ulong 0
9t = ulong 0
10for i ulong len s
11c = get s sub sub len s 1 i
12if eq c 32
13continue
14end
15if or lt c 48 gt c 57
16ret false
17end
18d = ulong sub c 48
19if eq rem n 2 1
20d = mul d 2
21if gt d 9
22d = sub d 9
23end
24end
25t = add t d
26n = add n 1
27end
28ret and gt n 1 eq rem t 10 0
29end