aboutsummaryrefslogtreecommitdiffhomepage
path: root/samples/rosetta/luhn_test_of_credit_card_numbers.bruijn
diff options
context:
space:
mode:
Diffstat (limited to 'samples/rosetta/luhn_test_of_credit_card_numbers.bruijn')
-rw-r--r--samples/rosetta/luhn_test_of_credit_card_numbers.bruijn14
1 files changed, 14 insertions, 0 deletions
diff --git a/samples/rosetta/luhn_test_of_credit_card_numbers.bruijn b/samples/rosetta/luhn_test_of_credit_card_numbers.bruijn
new file mode 100644
index 0000000..e52011e
--- /dev/null
+++ b/samples/rosetta/luhn_test_of_credit_card_numbers.bruijn
@@ -0,0 +1,14 @@
+:import std/Combinator .
+:import std/Math .
+:import std/List .
+
+luhn number→list → reverse → check → (\mod (+10)) → zero?
+ check y [[[[0 [[[6 \5 (4 + (5 odd even)) 1]]] 1]]]] k (+0)
+ odd 2
+ even digit-sum (2 ⋅ (+2))
+
+:test (luhn (+61789372994)) ([[1]])
+:test (luhn (+49927398716)) ([[1]])
+:test (luhn (+49927398717)) ([[0]])
+:test (luhn (+1234567812345678)) ([[0]])
+:test (luhn (+1234567812345670)) ([[1]])