aboutsummaryrefslogtreecommitdiffhomepage
path: root/samples/rosetta/validate_international_securities_identification_number.bruijn
diff options
context:
space:
mode:
authorMarvin Borner2024-03-25 18:59:03 +0100
committerMarvin Borner2024-03-25 18:59:48 +0100
commit14e38ce378236cf54924b58396168c1e94f8e6b2 (patch)
treeecbbb75517695de8897a2a9c58aa1a97ec2546f5 /samples/rosetta/validate_international_securities_identification_number.bruijn
parentf8398804d351667a7b887b89f6f70c7d5c407d22 (diff)
Improved samples by adding links to problems
Diffstat (limited to 'samples/rosetta/validate_international_securities_identification_number.bruijn')
-rw-r--r--samples/rosetta/validate_international_securities_identification_number.bruijn30
1 files changed, 30 insertions, 0 deletions
diff --git a/samples/rosetta/validate_international_securities_identification_number.bruijn b/samples/rosetta/validate_international_securities_identification_number.bruijn
new file mode 100644
index 0000000..7608ed5
--- /dev/null
+++ b/samples/rosetta/validate_international_securities_identification_number.bruijn
@@ -0,0 +1,30 @@
+:import luhn_test_of_credit_card_numbers .
+
+:import std/Number/Conversion .
+:import std/Combinator .
+:import std/String .
+:import std/Char .
+:import std/Logic .
+:import std/Number .
+
+# verifies ISIN format
+format? [len ⋀? country ⋀? security ⋀? checksum]
+ len (length 0) =? (+12)
+ country all? uppercase? (take (+2) 0)
+ security all? (φ or? uppercase? numeric?) (take (+9) (drop (+2) 0))
+ checksum numeric? _0
+
+# performs luhn test
+checksum? (map (from-base36 → number→string)) → concat → string→number → luhn
+ from-base36 binary→ternary → [(0 - (0 ≥? (+65) ((+65) - (+10)) (+48)))]
+
+# performs format and checksum test
+validate φ and? format? checksum?
+
+:test (validate "US0378331005") (true)
+:test (validate "US0373831005") (false)
+:test (validate "U50378331005") (false)
+:test (validate "US03378331005") (false)
+:test (validate "AU0000XVGZA3") (true)
+:test (validate "AU0000VXGZA3") (true)
+:test (validate "FR0000988040") (true)