Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-mv/blob/main/si/rosetta/tasks/luhn-test-of-credit-card-numbers/luhn-test-of-credit-card-numbers.om # 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 Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / si / rosetta / tasks / luhn-test-of-credit-card-numbers / luhn-test-of-credit-card-numbers.om` 52 lines ยท 1002 bytes Raw Blame History 1 note Rosetta Code task "Luhn test of credit card numbers": https://rosettacode.org/wiki/Luhn_test_of_credit_card_numbers 2 note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 3 om2 4 text nl "\n" 5 text tv " valid\n" 6 text ti " invalid\n" 7 text n1 "`49927398716`" 8 text n2 "`49927398717`" 9 text n3 "`1234567812345678`" 10 text n4 "`1234567812345670`" 11 note emit writes every byte of a to stdout; a short write is retried, an error exits 1 12 fn emit a view uchar * to void 13 o = ulong 0 14 while lt o len a bound 4096 15 k = write 1 a o sub len a o 16 if le k 0 17 exit 1 18 end 19 o = add o ulong k 20 end 21 end 22 note from the right, odd places add their digit, even places add the digit sum of twice the digit 23 fn luhn a view uchar * to bool 24 s = ulong 0 25 n = len a 26 for i ulong n 27 d = ulong sub get a sub sub n 1 i 48 28 if eq rem i 2 1 29 d = mul d 2 30 if gt d 9 31 d = sub d 9 32 end 33 end 34 s = add s d 35 end 36 ret eq rem s 10 0 37 end 38 fn show a view uchar * to void 39 emit a 40 if luhn a 41 emit tv 42 else 43 emit ti 44 end 45 end 46 fn main to int 47 show n1 48 show n2 49 show n3 50 show n4 51 ret 0 52 end