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