C problems validating a credit card

Rated 4.16/5 based on 765 customer reviews

PRINT IIF$(Luhn Check Passed("49927398716"), "passed", "failed") ' this test is expected to fail: CON.

#define ORDER_PP_DEF_8luhn_wk ORDER_PP_FN( fn(8N, \ 8lets((8P, 8unzip(8N, 8nil, 8nil, 8true)) \ (8O, 8seq_fold(8plus, 0, 8tuple_at_0(8P))) \ (8E, 8seq_fold(8plus, 0, \ 8seq_map(8dig_map, 8tuple_at_1(8P)))), \ 8is_0(8remainder(8plus(8O, 8E), 10)))) )#define ORDER_PP_DEF_8unzip ORDER_PP_FN( fn(8S, 8L, 8R, 8O, \ 8if(8is_nil(8S), \ 8pair(8L, 8R), \ 8if(8O, \ 8unzip(8seq_tail(8S), 8seq_push_back(8seq_head(8S), 8L), \ 8R, 8false), \ 8unzip(8seq_tail(8S), 8L, \ 8seq_push_back(8seq_head(8S), 8R), 8true)))) )#COMPILE EXE#DIM ALL#COMPILER PBCC 6 FUNCTION Luhn Check Passed(BYVAL dgts AS STRING) AS INTEGERLOCAL i, s, s1 AS DWORD dgts = STRREVERSE$(dgts) FOR i = 1 TO LEN(dgts) STEP 2 s = VAL(MID$(dgts, i, 1)) NEXT i FOR i = 2 TO LEN(dgts) STEP 2 s1 = 2 * VAL(MID$(dgts, i, 1)) IF s1 = 10 THEN s -= 9 END IF s = s1 NEXT i FUNCTION = NOT ISTRUE (s MOD 10)END FUNCTION FUNCTION PBMAIN () AS LONG ' this test is expected to pass: CON.

Complete("[Math Jax]/extensions/Te X/AMScd.js"), Math Jax.

arg&true|false)) )& test927398716& test927398717& test34567812345678& test34567812345670& ; Note that the original implementation, which follows, is flawed because it assumes that n is a number which, when represented as a string, has an even number of characters.

Startup Hook("Te X mathchoice Ready",function()), Math Jax.

PRINT IIF$(Luhn Check Passed("1234567812345678"), "passed", "failed") ' this test is expected to pass: CON. (modulo s 10)) (let*-values ([(q r) (quotient/remainder n 10)] [(rq rr) (quotient/remainder (* (if odd? ) ( s rq rr)))))) (map luhn-test '(49927398716 49927398717 1234567812345678 1234567812345670));; - flunked the Luhn test, credit card number: 49927398716 passed the Luhn test, credit card number: 49927398717 passed the Luhn test, credit card number: 1234567812345678 flunked the Luhn test, credit card number: 1234567812345670 /* Rexx **************************************************** Walter Pachl* Implements the task's description in a rather concise way* Instead of reverting the ccn work it backwards**********************************************************/ " cardtest(test[n]) nlnext func cardtest(numstr) revstring = revstr(numstr) s1 = revodd(revstring) s2 = reveven(revstring) s3 =right(string(s1 s2), 1) if s3 = "0" return "Valid" else return "Invalid" ok func revstr(str) strnew = "" for nr = len(str) to 1 step -1 strnew = strnew str[nr] next return strnew func revodd(str) strnew = "" for nr = 1 to len(str) step 2 strnew = strnew str[nr] next sumodd = 0 for p = 1 to len(strnew) sumodd = sumodd number(strnew[p]) next return sumodd func reveven(str) strnew = "" for nr = 2 to len(str) step 2 strnew = strnew str[nr] next lsteven = [] for p = 1 to len(strnew) add(lsteven, string(2*number(strnew[p]))) next arreven = list(len(lsteven)) for q = 1 to len(lsteven) sum = 0 for w = 1 to len(lsteven[q]) sum = sum lsteven[q][w] next arreven[q] = sum next sumarr = 0 for x = 1 to len(arreven) sumarr = sumarr arreven[x] next return sumarr card$(1) = "49927398716"card$(2) = "49927398717"card$(3) = "1234567812345678"card$(4) = "1234567812345670" for i = 1 to 4print card$(i);" ";luhn$(card$(i))next i FUNCTION luhn$(card$) lc = len(card$) for i = lc to 1 step -1 digit = val(mid$(card$,i,1)) if ((lc -i) mod 2) = 0 then chk Sum = chk Sum digit else chk Sum = chk Sum int(digit * 2.2) next i if chk Sum mod 10 = 0 then luhn$ = "True" else luhn$ = "False"end function# Split number into double evens and oddss/.*/&: /: splits/\([0-4]\)\([0-9]\):\(.*\) /:

Complete("[Math Jax]/extensions/Te X/AMScd.js"), Math Jax.

arg&true|false)) )& test$49927398716& test$49927398717& test$1234567812345678& test$1234567812345670& ; Note that the original implementation, which follows, is flawed because it assumes that n is a number which, when represented as a string, has an even number of characters.

Startup Hook("Te X mathchoice Ready",function()), Math Jax.

PRINT IIF$(Luhn Check Passed("1234567812345678"), "passed", "failed") ' this test is expected to pass: CON. (modulo s 10)) (let*-values ([(q r) (quotient/remainder n 10)] [(rq rr) (quotient/remainder (* (if odd? ) ( s rq rr)))))) (map luhn-test '(49927398716 49927398717 1234567812345678 1234567812345670));; - flunked the Luhn test, credit card number: 49927398716 passed the Luhn test, credit card number: 49927398717 passed the Luhn test, credit card number: 1234567812345678 flunked the Luhn test, credit card number: 1234567812345670 /* Rexx **************************************************** Walter Pachl* Implements the task's description in a rather concise way* Instead of reverting the ccn work it backwards**********************************************************/ " cardtest(test[n]) nlnext func cardtest(numstr) revstring = revstr(numstr) s1 = revodd(revstring) s2 = reveven(revstring) s3 =right(string(s1 s2), 1) if s3 = "0" return "Valid" else return "Invalid" ok func revstr(str) strnew = "" for nr = len(str) to 1 step -1 strnew = strnew str[nr] next return strnew func revodd(str) strnew = "" for nr = 1 to len(str) step 2 strnew = strnew str[nr] next sumodd = 0 for p = 1 to len(strnew) sumodd = sumodd number(strnew[p]) next return sumodd func reveven(str) strnew = "" for nr = 2 to len(str) step 2 strnew = strnew str[nr] next lsteven = [] for p = 1 to len(strnew) add(lsteven, string(2*number(strnew[p]))) next arreven = list(len(lsteven)) for q = 1 to len(lsteven) sum = 0 for w = 1 to len(lsteven[q]) sum = sum lsteven[q][w] next arreven[q] = sum next sumarr = 0 for x = 1 to len(arreven) sumarr = sumarr arreven[x] next return sumarr card$(1) = "49927398716"card$(2) = "49927398717"card$(3) = "1234567812345678"card$(4) = "1234567812345670" for i = 1 to 4print card$(i);" ";luhn$(card$(i))next i FUNCTION luhn$(card$) lc = len(card$) for i = lc to 1 step -1 digit = val(mid$(card$,i,1)) if ((lc -i) mod 2) = 0 then chk Sum = chk Sum digit else chk Sum = chk Sum int(digit * 2.2) next i if chk Sum mod 10 = 0 then luhn$ = "True" else luhn$ = "False"end function# Split number into double evens and oddss/.*/&: /: splits/\([0-4]\)\([0-9]\):\(.*\) /:\1\1\3 \2/s/\([5-9]\)\([0-9]\):\(.*\) /:1\1\1\3 \2/t split # Set up addition lookup tables/\([0-9]\)*:\(.*\) \(.*\)/\1\2\23456789012345678/ : adds/\([0-9]\)0:/\1:/s/\([0-9]\)1:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)2:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)3:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)4:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)5:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)6:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)7:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)8:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)9:\(.*\1.\\([0-9]\).*\)/\3:\2/t add /0:/a\Pass/0:/!

PRINT IIF$(Luhn Check Passed("49927398717"), "passed", "failed") ' this test is expected to fail: CON.

||

Complete("[Math Jax]/extensions/Te X/AMScd.js"), Math Jax. arg&true|false)) )& test$49927398716& test$49927398717& test$1234567812345678& test$1234567812345670& ; Note that the original implementation, which follows, is flawed because it assumes that n is a number which, when represented as a string, has an even number of characters. Startup Hook("Te X mathchoice Ready",function()), Math Jax. PRINT IIF$(Luhn Check Passed("1234567812345678"), "passed", "failed") ' this test is expected to pass: CON. (modulo s 10)) (let*-values ([(q r) (quotient/remainder n 10)] [(rq rr) (quotient/remainder (* (if odd? ) ( s rq rr)))))) (map luhn-test '(49927398716 49927398717 1234567812345678 1234567812345670));; - flunked the Luhn test, credit card number: 49927398716 passed the Luhn test, credit card number: 49927398717 passed the Luhn test, credit card number: 1234567812345678 flunked the Luhn test, credit card number: 1234567812345670 /* Rexx **************************************************** Walter Pachl* Implements the task's description in a rather concise way* Instead of reverting the ccn work it backwards**********************************************************/ " cardtest(test[n]) nlnext func cardtest(numstr) revstring = revstr(numstr) s1 = revodd(revstring) s2 = reveven(revstring) s3 =right(string(s1 s2), 1) if s3 = "0" return "Valid" else return "Invalid" ok func revstr(str) strnew = "" for nr = len(str) to 1 step -1 strnew = strnew str[nr] next return strnew func revodd(str) strnew = "" for nr = 1 to len(str) step 2 strnew = strnew str[nr] next sumodd = 0 for p = 1 to len(strnew) sumodd = sumodd number(strnew[p]) next return sumodd func reveven(str) strnew = "" for nr = 2 to len(str) step 2 strnew = strnew str[nr] next lsteven = [] for p = 1 to len(strnew) add(lsteven, string(2*number(strnew[p]))) next arreven = list(len(lsteven)) for q = 1 to len(lsteven) sum = 0 for w = 1 to len(lsteven[q]) sum = sum lsteven[q][w] next arreven[q] = sum next sumarr = 0 for x = 1 to len(arreven) sumarr = sumarr arreven[x] next return sumarr card$(1) = "49927398716"card$(2) = "49927398717"card$(3) = "1234567812345678"card$(4) = "1234567812345670" for i = 1 to 4print card$(i);" ";luhn$(card$(i))next i FUNCTION luhn$(card$) lc = len(card$) for i = lc to 1 step -1 digit = val(mid$(card$,i,1)) if ((lc -i) mod 2) = 0 then chk Sum = chk Sum digit else chk Sum = chk Sum int(digit * 2.2) next i if chk Sum mod 10 = 0 then luhn$ = "True" else luhn$ = "False"end function# Split number into double evens and oddss/.*/&: /: splits/\([0-4]\)\([0-9]\):\(.*\) /:\1\1\3 \2/s/\([5-9]\)\([0-9]\):\(.*\) /:1\1\1\3 \2/t split # Set up addition lookup tables/\([0-9]\)*:\(.*\) \(.*\)/\1\2\23456789012345678/ : adds/\([0-9]\)0:/\1:/s/\([0-9]\)1:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)2:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)3:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)4:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)5:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)6:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)7:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)8:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)9:\(.*\1.\\([0-9]\).*\)/\3:\2/t add /0:/a\Pass/0:/! PRINT IIF$(Luhn Check Passed("49927398717"), "passed", "failed") ' this test is expected to fail: CON.

Complete("[Math Jax]/extensions/Te X/AMScd.js"), Math Jax.

arg&true|false)) )& test$49927398716& test$49927398717& test$1234567812345678& test$1234567812345670& ; Note that the original implementation, which follows, is flawed because it assumes that n is a number which, when represented as a string, has an even number of characters.

Startup Hook("Te X mathchoice Ready",function()), Math Jax.

PRINT IIF$(Luhn Check Passed("1234567812345678"), "passed", "failed") ' this test is expected to pass: CON. (modulo s 10)) (let*-values ([(q r) (quotient/remainder n 10)] [(rq rr) (quotient/remainder (* (if odd? ) ( s rq rr)))))) (map luhn-test '(49927398716 49927398717 1234567812345678 1234567812345670));; - flunked the Luhn test, credit card number: 49927398716 passed the Luhn test, credit card number: 49927398717 passed the Luhn test, credit card number: 1234567812345678 flunked the Luhn test, credit card number: 1234567812345670 /* Rexx **************************************************** Walter Pachl* Implements the task's description in a rather concise way* Instead of reverting the ccn work it backwards**********************************************************/ " cardtest(test[n]) nlnext func cardtest(numstr) revstring = revstr(numstr) s1 = revodd(revstring) s2 = reveven(revstring) s3 =right(string(s1 s2), 1) if s3 = "0" return "Valid" else return "Invalid" ok func revstr(str) strnew = "" for nr = len(str) to 1 step -1 strnew = strnew str[nr] next return strnew func revodd(str) strnew = "" for nr = 1 to len(str) step 2 strnew = strnew str[nr] next sumodd = 0 for p = 1 to len(strnew) sumodd = sumodd number(strnew[p]) next return sumodd func reveven(str) strnew = "" for nr = 2 to len(str) step 2 strnew = strnew str[nr] next lsteven = [] for p = 1 to len(strnew) add(lsteven, string(2*number(strnew[p]))) next arreven = list(len(lsteven)) for q = 1 to len(lsteven) sum = 0 for w = 1 to len(lsteven[q]) sum = sum lsteven[q][w] next arreven[q] = sum next sumarr = 0 for x = 1 to len(arreven) sumarr = sumarr arreven[x] next return sumarr card$(1) = "49927398716"card$(2) = "49927398717"card$(3) = "1234567812345678"card$(4) = "1234567812345670" for i = 1 to 4print card$(i);" ";luhn$(card$(i))next i FUNCTION luhn$(card$) lc = len(card$) for i = lc to 1 step -1 digit = val(mid$(card$,i,1)) if ((lc -i) mod 2) = 0 then chk Sum = chk Sum digit else chk Sum = chk Sum int(digit * 2.2) next i if chk Sum mod 10 = 0 then luhn$ = "True" else luhn$ = "False"end function# Split number into double evens and oddss/.*/&: /: splits/\([0-4]\)\([0-9]\):\(.*\) /:\1\1\3 \2/s/\([5-9]\)\([0-9]\):\(.*\) /:1\1\1\3 \2/t split # Set up addition lookup tables/\([0-9]\)*:\(.*\) \(.*\)/\1\2\23456789012345678/ : adds/\([0-9]\)0:/\1:/s/\([0-9]\)1:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)2:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)3:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)4:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)5:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)6:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)7:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)8:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)9:\(.*\1.\\([0-9]\).*\)/\3:\2/t add /0:/a\Pass/0:/!

PRINT IIF$(Luhn Check Passed("49927398717"), "passed", "failed") ' this test is expected to fail: CON.

||

Complete("[Math Jax]/extensions/Te X/AMScd.js"), Math Jax. arg&true|false)) )& test$49927398716& test$49927398717& test$1234567812345678& test$1234567812345670& ; Note that the original implementation, which follows, is flawed because it assumes that n is a number which, when represented as a string, has an even number of characters. Startup Hook("Te X mathchoice Ready",function()), Math Jax. PRINT IIF$(Luhn Check Passed("1234567812345678"), "passed", "failed") ' this test is expected to pass: CON. (modulo s 10)) (let*-values ([(q r) (quotient/remainder n 10)] [(rq rr) (quotient/remainder (* (if odd? ) ( s rq rr)))))) (map luhn-test '(49927398716 49927398717 1234567812345678 1234567812345670));; - flunked the Luhn test, credit card number: 49927398716 passed the Luhn test, credit card number: 49927398717 passed the Luhn test, credit card number: 1234567812345678 flunked the Luhn test, credit card number: 1234567812345670 /* Rexx **************************************************** Walter Pachl* Implements the task's description in a rather concise way* Instead of reverting the ccn work it backwards**********************************************************/ " cardtest(test[n]) nlnext func cardtest(numstr) revstring = revstr(numstr) s1 = revodd(revstring) s2 = reveven(revstring) s3 =right(string(s1 s2), 1) if s3 = "0" return "Valid" else return "Invalid" ok func revstr(str) strnew = "" for nr = len(str) to 1 step -1 strnew = strnew str[nr] next return strnew func revodd(str) strnew = "" for nr = 1 to len(str) step 2 strnew = strnew str[nr] next sumodd = 0 for p = 1 to len(strnew) sumodd = sumodd number(strnew[p]) next return sumodd func reveven(str) strnew = "" for nr = 2 to len(str) step 2 strnew = strnew str[nr] next lsteven = [] for p = 1 to len(strnew) add(lsteven, string(2*number(strnew[p]))) next arreven = list(len(lsteven)) for q = 1 to len(lsteven) sum = 0 for w = 1 to len(lsteven[q]) sum = sum lsteven[q][w] next arreven[q] = sum next sumarr = 0 for x = 1 to len(arreven) sumarr = sumarr arreven[x] next return sumarr card$(1) = "49927398716"card$(2) = "49927398717"card$(3) = "1234567812345678"card$(4) = "1234567812345670" for i = 1 to 4print card$(i);" ";luhn$(card$(i))next i FUNCTION luhn$(card$) lc = len(card$) for i = lc to 1 step -1 digit = val(mid$(card$,i,1)) if ((lc -i) mod 2) = 0 then chk Sum = chk Sum digit else chk Sum = chk Sum int(digit * 2.2) next i if chk Sum mod 10 = 0 then luhn$ = "True" else luhn$ = "False"end function# Split number into double evens and oddss/.*/&: /: splits/\([0-4]\)\([0-9]\):\(.*\) /:\1\1\3 \2/s/\([5-9]\)\([0-9]\):\(.*\) /:1\1\1\3 \2/t split # Set up addition lookup tables/\([0-9]\)*:\(.*\) \(.*\)/\1\2\23456789012345678/ : adds/\([0-9]\)0:/\1:/s/\([0-9]\)1:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)2:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)3:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)4:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)5:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)6:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)7:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)8:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)9:\(.*\1.\\([0-9]\).*\)/\3:\2/t add /0:/a\Pass/0:/! PRINT IIF$(Luhn Check Passed("49927398717"), "passed", "failed") ' this test is expected to fail: CON.

/s/\([5-9]\)\([0-9]\):\(.*\) /:1

Complete("[Math Jax]/extensions/Te X/AMScd.js"), Math Jax.

arg&true|false)) )& test$49927398716& test$49927398717& test$1234567812345678& test$1234567812345670& ; Note that the original implementation, which follows, is flawed because it assumes that n is a number which, when represented as a string, has an even number of characters.

Startup Hook("Te X mathchoice Ready",function()), Math Jax.

PRINT IIF$(Luhn Check Passed("1234567812345678"), "passed", "failed") ' this test is expected to pass: CON. (modulo s 10)) (let*-values ([(q r) (quotient/remainder n 10)] [(rq rr) (quotient/remainder (* (if odd? ) ( s rq rr)))))) (map luhn-test '(49927398716 49927398717 1234567812345678 1234567812345670));; - flunked the Luhn test, credit card number: 49927398716 passed the Luhn test, credit card number: 49927398717 passed the Luhn test, credit card number: 1234567812345678 flunked the Luhn test, credit card number: 1234567812345670 /* Rexx **************************************************** Walter Pachl* Implements the task's description in a rather concise way* Instead of reverting the ccn work it backwards**********************************************************/ " cardtest(test[n]) nlnext func cardtest(numstr) revstring = revstr(numstr) s1 = revodd(revstring) s2 = reveven(revstring) s3 =right(string(s1 s2), 1) if s3 = "0" return "Valid" else return "Invalid" ok func revstr(str) strnew = "" for nr = len(str) to 1 step -1 strnew = strnew str[nr] next return strnew func revodd(str) strnew = "" for nr = 1 to len(str) step 2 strnew = strnew str[nr] next sumodd = 0 for p = 1 to len(strnew) sumodd = sumodd number(strnew[p]) next return sumodd func reveven(str) strnew = "" for nr = 2 to len(str) step 2 strnew = strnew str[nr] next lsteven = [] for p = 1 to len(strnew) add(lsteven, string(2*number(strnew[p]))) next arreven = list(len(lsteven)) for q = 1 to len(lsteven) sum = 0 for w = 1 to len(lsteven[q]) sum = sum lsteven[q][w] next arreven[q] = sum next sumarr = 0 for x = 1 to len(arreven) sumarr = sumarr arreven[x] next return sumarr card$(1) = "49927398716"card$(2) = "49927398717"card$(3) = "1234567812345678"card$(4) = "1234567812345670" for i = 1 to 4print card$(i);" ";luhn$(card$(i))next i FUNCTION luhn$(card$) lc = len(card$) for i = lc to 1 step -1 digit = val(mid$(card$,i,1)) if ((lc -i) mod 2) = 0 then chk Sum = chk Sum digit else chk Sum = chk Sum int(digit * 2.2) next i if chk Sum mod 10 = 0 then luhn$ = "True" else luhn$ = "False"end function# Split number into double evens and oddss/.*/&: /: splits/\([0-4]\)\([0-9]\):\(.*\) /:\1\1\3 \2/s/\([5-9]\)\([0-9]\):\(.*\) /:1\1\1\3 \2/t split # Set up addition lookup tables/\([0-9]\)*:\(.*\) \(.*\)/\1\2\23456789012345678/ : adds/\([0-9]\)0:/\1:/s/\([0-9]\)1:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)2:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)3:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)4:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)5:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)6:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)7:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)8:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)9:\(.*\1.\\([0-9]\).*\)/\3:\2/t add /0:/a\Pass/0:/!

PRINT IIF$(Luhn Check Passed("49927398717"), "passed", "failed") ' this test is expected to fail: CON.

||

Complete("[Math Jax]/extensions/Te X/AMScd.js"), Math Jax. arg&true|false)) )& test$49927398716& test$49927398717& test$1234567812345678& test$1234567812345670& ; Note that the original implementation, which follows, is flawed because it assumes that n is a number which, when represented as a string, has an even number of characters. Startup Hook("Te X mathchoice Ready",function()), Math Jax. PRINT IIF$(Luhn Check Passed("1234567812345678"), "passed", "failed") ' this test is expected to pass: CON. (modulo s 10)) (let*-values ([(q r) (quotient/remainder n 10)] [(rq rr) (quotient/remainder (* (if odd? ) ( s rq rr)))))) (map luhn-test '(49927398716 49927398717 1234567812345678 1234567812345670));; - flunked the Luhn test, credit card number: 49927398716 passed the Luhn test, credit card number: 49927398717 passed the Luhn test, credit card number: 1234567812345678 flunked the Luhn test, credit card number: 1234567812345670 /* Rexx **************************************************** Walter Pachl* Implements the task's description in a rather concise way* Instead of reverting the ccn work it backwards**********************************************************/ " cardtest(test[n]) nlnext func cardtest(numstr) revstring = revstr(numstr) s1 = revodd(revstring) s2 = reveven(revstring) s3 =right(string(s1 s2), 1) if s3 = "0" return "Valid" else return "Invalid" ok func revstr(str) strnew = "" for nr = len(str) to 1 step -1 strnew = strnew str[nr] next return strnew func revodd(str) strnew = "" for nr = 1 to len(str) step 2 strnew = strnew str[nr] next sumodd = 0 for p = 1 to len(strnew) sumodd = sumodd number(strnew[p]) next return sumodd func reveven(str) strnew = "" for nr = 2 to len(str) step 2 strnew = strnew str[nr] next lsteven = [] for p = 1 to len(strnew) add(lsteven, string(2*number(strnew[p]))) next arreven = list(len(lsteven)) for q = 1 to len(lsteven) sum = 0 for w = 1 to len(lsteven[q]) sum = sum lsteven[q][w] next arreven[q] = sum next sumarr = 0 for x = 1 to len(arreven) sumarr = sumarr arreven[x] next return sumarr card$(1) = "49927398716"card$(2) = "49927398717"card$(3) = "1234567812345678"card$(4) = "1234567812345670" for i = 1 to 4print card$(i);" ";luhn$(card$(i))next i FUNCTION luhn$(card$) lc = len(card$) for i = lc to 1 step -1 digit = val(mid$(card$,i,1)) if ((lc -i) mod 2) = 0 then chk Sum = chk Sum digit else chk Sum = chk Sum int(digit * 2.2) next i if chk Sum mod 10 = 0 then luhn$ = "True" else luhn$ = "False"end function# Split number into double evens and oddss/.*/&: /: splits/\([0-4]\)\([0-9]\):\(.*\) /:\1\1\3 \2/s/\([5-9]\)\([0-9]\):\(.*\) /:1\1\1\3 \2/t split # Set up addition lookup tables/\([0-9]\)*:\(.*\) \(.*\)/\1\2\23456789012345678/ : adds/\([0-9]\)0:/\1:/s/\([0-9]\)1:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)2:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)3:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)4:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)5:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)6:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)7:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)8:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)9:\(.*\1.\\([0-9]\).*\)/\3:\2/t add /0:/a\Pass/0:/! PRINT IIF$(Luhn Check Passed("49927398717"), "passed", "failed") ' this test is expected to fail: CON.

Complete("[Math Jax]/extensions/Te X/AMScd.js"), Math Jax.

arg&true|false)) )& test$49927398716& test$49927398717& test$1234567812345678& test$1234567812345670& ; Note that the original implementation, which follows, is flawed because it assumes that n is a number which, when represented as a string, has an even number of characters.

Startup Hook("Te X mathchoice Ready",function()), Math Jax.

PRINT IIF$(Luhn Check Passed("1234567812345678"), "passed", "failed") ' this test is expected to pass: CON. (modulo s 10)) (let*-values ([(q r) (quotient/remainder n 10)] [(rq rr) (quotient/remainder (* (if odd? ) ( s rq rr)))))) (map luhn-test '(49927398716 49927398717 1234567812345678 1234567812345670));; - flunked the Luhn test, credit card number: 49927398716 passed the Luhn test, credit card number: 49927398717 passed the Luhn test, credit card number: 1234567812345678 flunked the Luhn test, credit card number: 1234567812345670 /* Rexx **************************************************** Walter Pachl* Implements the task's description in a rather concise way* Instead of reverting the ccn work it backwards**********************************************************/ " cardtest(test[n]) nlnext func cardtest(numstr) revstring = revstr(numstr) s1 = revodd(revstring) s2 = reveven(revstring) s3 =right(string(s1 s2), 1) if s3 = "0" return "Valid" else return "Invalid" ok func revstr(str) strnew = "" for nr = len(str) to 1 step -1 strnew = strnew str[nr] next return strnew func revodd(str) strnew = "" for nr = 1 to len(str) step 2 strnew = strnew str[nr] next sumodd = 0 for p = 1 to len(strnew) sumodd = sumodd number(strnew[p]) next return sumodd func reveven(str) strnew = "" for nr = 2 to len(str) step 2 strnew = strnew str[nr] next lsteven = [] for p = 1 to len(strnew) add(lsteven, string(2*number(strnew[p]))) next arreven = list(len(lsteven)) for q = 1 to len(lsteven) sum = 0 for w = 1 to len(lsteven[q]) sum = sum lsteven[q][w] next arreven[q] = sum next sumarr = 0 for x = 1 to len(arreven) sumarr = sumarr arreven[x] next return sumarr card$(1) = "49927398716"card$(2) = "49927398717"card$(3) = "1234567812345678"card$(4) = "1234567812345670" for i = 1 to 4print card$(i);" ";luhn$(card$(i))next i FUNCTION luhn$(card$) lc = len(card$) for i = lc to 1 step -1 digit = val(mid$(card$,i,1)) if ((lc -i) mod 2) = 0 then chk Sum = chk Sum digit else chk Sum = chk Sum int(digit * 2.2) next i if chk Sum mod 10 = 0 then luhn$ = "True" else luhn$ = "False"end function# Split number into double evens and oddss/.*/&: /: splits/\([0-4]\)\([0-9]\):\(.*\) /:\1\1\3 \2/s/\([5-9]\)\([0-9]\):\(.*\) /:1\1\1\3 \2/t split # Set up addition lookup tables/\([0-9]\)*:\(.*\) \(.*\)/\1\2\23456789012345678/ : adds/\([0-9]\)0:/\1:/s/\([0-9]\)1:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)2:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)3:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)4:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)5:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)6:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)7:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)8:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)9:\(.*\1.\\([0-9]\).*\)/\3:\2/t add /0:/a\Pass/0:/!

PRINT IIF$(Luhn Check Passed("49927398717"), "passed", "failed") ' this test is expected to fail: CON.

||

Complete("[Math Jax]/extensions/Te X/AMScd.js"), Math Jax. arg&true|false)) )& test$49927398716& test$49927398717& test$1234567812345678& test$1234567812345670& ; Note that the original implementation, which follows, is flawed because it assumes that n is a number which, when represented as a string, has an even number of characters. Startup Hook("Te X mathchoice Ready",function()), Math Jax. PRINT IIF$(Luhn Check Passed("1234567812345678"), "passed", "failed") ' this test is expected to pass: CON. (modulo s 10)) (let*-values ([(q r) (quotient/remainder n 10)] [(rq rr) (quotient/remainder (* (if odd? ) ( s rq rr)))))) (map luhn-test '(49927398716 49927398717 1234567812345678 1234567812345670));; - flunked the Luhn test, credit card number: 49927398716 passed the Luhn test, credit card number: 49927398717 passed the Luhn test, credit card number: 1234567812345678 flunked the Luhn test, credit card number: 1234567812345670 /* Rexx **************************************************** Walter Pachl* Implements the task's description in a rather concise way* Instead of reverting the ccn work it backwards**********************************************************/ " cardtest(test[n]) nlnext func cardtest(numstr) revstring = revstr(numstr) s1 = revodd(revstring) s2 = reveven(revstring) s3 =right(string(s1 s2), 1) if s3 = "0" return "Valid" else return "Invalid" ok func revstr(str) strnew = "" for nr = len(str) to 1 step -1 strnew = strnew str[nr] next return strnew func revodd(str) strnew = "" for nr = 1 to len(str) step 2 strnew = strnew str[nr] next sumodd = 0 for p = 1 to len(strnew) sumodd = sumodd number(strnew[p]) next return sumodd func reveven(str) strnew = "" for nr = 2 to len(str) step 2 strnew = strnew str[nr] next lsteven = [] for p = 1 to len(strnew) add(lsteven, string(2*number(strnew[p]))) next arreven = list(len(lsteven)) for q = 1 to len(lsteven) sum = 0 for w = 1 to len(lsteven[q]) sum = sum lsteven[q][w] next arreven[q] = sum next sumarr = 0 for x = 1 to len(arreven) sumarr = sumarr arreven[x] next return sumarr card$(1) = "49927398716"card$(2) = "49927398717"card$(3) = "1234567812345678"card$(4) = "1234567812345670" for i = 1 to 4print card$(i);" ";luhn$(card$(i))next i FUNCTION luhn$(card$) lc = len(card$) for i = lc to 1 step -1 digit = val(mid$(card$,i,1)) if ((lc -i) mod 2) = 0 then chk Sum = chk Sum digit else chk Sum = chk Sum int(digit * 2.2) next i if chk Sum mod 10 = 0 then luhn$ = "True" else luhn$ = "False"end function# Split number into double evens and oddss/.*/&: /: splits/\([0-4]\)\([0-9]\):\(.*\) /:\1\1\3 \2/s/\([5-9]\)\([0-9]\):\(.*\) /:1\1\1\3 \2/t split # Set up addition lookup tables/\([0-9]\)*:\(.*\) \(.*\)/\1\2\23456789012345678/ : adds/\([0-9]\)0:/\1:/s/\([0-9]\)1:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)2:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)3:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)4:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)5:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)6:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)7:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)8:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)9:\(.*\1.\\([0-9]\).*\)/\3:\2/t add /0:/a\Pass/0:/! PRINT IIF$(Luhn Check Passed("49927398717"), "passed", "failed") ' this test is expected to fail: CON.

/t split # Set up addition lookup tables/\([0-9]\)*:\(.*\) \(.*\)/

Complete("[Math Jax]/extensions/Te X/AMScd.js"), Math Jax.

arg&true|false)) )& test$49927398716& test$49927398717& test$1234567812345678& test$1234567812345670& ; Note that the original implementation, which follows, is flawed because it assumes that n is a number which, when represented as a string, has an even number of characters.

Startup Hook("Te X mathchoice Ready",function()), Math Jax.

PRINT IIF$(Luhn Check Passed("1234567812345678"), "passed", "failed") ' this test is expected to pass: CON. (modulo s 10)) (let*-values ([(q r) (quotient/remainder n 10)] [(rq rr) (quotient/remainder (* (if odd? ) ( s rq rr)))))) (map luhn-test '(49927398716 49927398717 1234567812345678 1234567812345670));; - flunked the Luhn test, credit card number: 49927398716 passed the Luhn test, credit card number: 49927398717 passed the Luhn test, credit card number: 1234567812345678 flunked the Luhn test, credit card number: 1234567812345670 /* Rexx **************************************************** Walter Pachl* Implements the task's description in a rather concise way* Instead of reverting the ccn work it backwards**********************************************************/ " cardtest(test[n]) nlnext func cardtest(numstr) revstring = revstr(numstr) s1 = revodd(revstring) s2 = reveven(revstring) s3 =right(string(s1 s2), 1) if s3 = "0" return "Valid" else return "Invalid" ok func revstr(str) strnew = "" for nr = len(str) to 1 step -1 strnew = strnew str[nr] next return strnew func revodd(str) strnew = "" for nr = 1 to len(str) step 2 strnew = strnew str[nr] next sumodd = 0 for p = 1 to len(strnew) sumodd = sumodd number(strnew[p]) next return sumodd func reveven(str) strnew = "" for nr = 2 to len(str) step 2 strnew = strnew str[nr] next lsteven = [] for p = 1 to len(strnew) add(lsteven, string(2*number(strnew[p]))) next arreven = list(len(lsteven)) for q = 1 to len(lsteven) sum = 0 for w = 1 to len(lsteven[q]) sum = sum lsteven[q][w] next arreven[q] = sum next sumarr = 0 for x = 1 to len(arreven) sumarr = sumarr arreven[x] next return sumarr card$(1) = "49927398716"card$(2) = "49927398717"card$(3) = "1234567812345678"card$(4) = "1234567812345670" for i = 1 to 4print card$(i);" ";luhn$(card$(i))next i FUNCTION luhn$(card$) lc = len(card$) for i = lc to 1 step -1 digit = val(mid$(card$,i,1)) if ((lc -i) mod 2) = 0 then chk Sum = chk Sum digit else chk Sum = chk Sum int(digit * 2.2) next i if chk Sum mod 10 = 0 then luhn$ = "True" else luhn$ = "False"end function# Split number into double evens and oddss/.*/&: /: splits/\([0-4]\)\([0-9]\):\(.*\) /:\1\1\3 \2/s/\([5-9]\)\([0-9]\):\(.*\) /:1\1\1\3 \2/t split # Set up addition lookup tables/\([0-9]\)*:\(.*\) \(.*\)/\1\2\23456789012345678/ : adds/\([0-9]\)0:/\1:/s/\([0-9]\)1:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)2:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)3:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)4:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)5:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)6:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)7:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)8:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)9:\(.*\1.\\([0-9]\).*\)/\3:\2/t add /0:/a\Pass/0:/!

PRINT IIF$(Luhn Check Passed("49927398717"), "passed", "failed") ' this test is expected to fail: CON.

||

Complete("[Math Jax]/extensions/Te X/AMScd.js"), Math Jax. arg&true|false)) )& test$49927398716& test$49927398717& test$1234567812345678& test$1234567812345670& ; Note that the original implementation, which follows, is flawed because it assumes that n is a number which, when represented as a string, has an even number of characters. Startup Hook("Te X mathchoice Ready",function()), Math Jax. PRINT IIF$(Luhn Check Passed("1234567812345678"), "passed", "failed") ' this test is expected to pass: CON. (modulo s 10)) (let*-values ([(q r) (quotient/remainder n 10)] [(rq rr) (quotient/remainder (* (if odd? ) ( s rq rr)))))) (map luhn-test '(49927398716 49927398717 1234567812345678 1234567812345670));; - flunked the Luhn test, credit card number: 49927398716 passed the Luhn test, credit card number: 49927398717 passed the Luhn test, credit card number: 1234567812345678 flunked the Luhn test, credit card number: 1234567812345670 /* Rexx **************************************************** Walter Pachl* Implements the task's description in a rather concise way* Instead of reverting the ccn work it backwards**********************************************************/ " cardtest(test[n]) nlnext func cardtest(numstr) revstring = revstr(numstr) s1 = revodd(revstring) s2 = reveven(revstring) s3 =right(string(s1 s2), 1) if s3 = "0" return "Valid" else return "Invalid" ok func revstr(str) strnew = "" for nr = len(str) to 1 step -1 strnew = strnew str[nr] next return strnew func revodd(str) strnew = "" for nr = 1 to len(str) step 2 strnew = strnew str[nr] next sumodd = 0 for p = 1 to len(strnew) sumodd = sumodd number(strnew[p]) next return sumodd func reveven(str) strnew = "" for nr = 2 to len(str) step 2 strnew = strnew str[nr] next lsteven = [] for p = 1 to len(strnew) add(lsteven, string(2*number(strnew[p]))) next arreven = list(len(lsteven)) for q = 1 to len(lsteven) sum = 0 for w = 1 to len(lsteven[q]) sum = sum lsteven[q][w] next arreven[q] = sum next sumarr = 0 for x = 1 to len(arreven) sumarr = sumarr arreven[x] next return sumarr card$(1) = "49927398716"card$(2) = "49927398717"card$(3) = "1234567812345678"card$(4) = "1234567812345670" for i = 1 to 4print card$(i);" ";luhn$(card$(i))next i FUNCTION luhn$(card$) lc = len(card$) for i = lc to 1 step -1 digit = val(mid$(card$,i,1)) if ((lc -i) mod 2) = 0 then chk Sum = chk Sum digit else chk Sum = chk Sum int(digit * 2.2) next i if chk Sum mod 10 = 0 then luhn$ = "True" else luhn$ = "False"end function# Split number into double evens and oddss/.*/&: /: splits/\([0-4]\)\([0-9]\):\(.*\) /:\1\1\3 \2/s/\([5-9]\)\([0-9]\):\(.*\) /:1\1\1\3 \2/t split # Set up addition lookup tables/\([0-9]\)*:\(.*\) \(.*\)/\1\2\23456789012345678/ : adds/\([0-9]\)0:/\1:/s/\([0-9]\)1:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)2:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)3:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)4:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)5:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)6:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)7:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)8:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)9:\(.*\1.\\([0-9]\).*\)/\3:\2/t add /0:/a\Pass/0:/! PRINT IIF$(Luhn Check Passed("49927398717"), "passed", "failed") ' this test is expected to fail: CON.

456789012345678/ : adds/\([0-9]\)0:/

Complete("[Math Jax]/extensions/Te X/AMScd.js"), Math Jax.

arg&true|false)) )& test$49927398716& test$49927398717& test$1234567812345678& test$1234567812345670& ; Note that the original implementation, which follows, is flawed because it assumes that n is a number which, when represented as a string, has an even number of characters.

Startup Hook("Te X mathchoice Ready",function()), Math Jax.

PRINT IIF$(Luhn Check Passed("1234567812345678"), "passed", "failed") ' this test is expected to pass: CON. (modulo s 10)) (let*-values ([(q r) (quotient/remainder n 10)] [(rq rr) (quotient/remainder (* (if odd? ) ( s rq rr)))))) (map luhn-test '(49927398716 49927398717 1234567812345678 1234567812345670));; - flunked the Luhn test, credit card number: 49927398716 passed the Luhn test, credit card number: 49927398717 passed the Luhn test, credit card number: 1234567812345678 flunked the Luhn test, credit card number: 1234567812345670 /* Rexx **************************************************** Walter Pachl* Implements the task's description in a rather concise way* Instead of reverting the ccn work it backwards**********************************************************/ " cardtest(test[n]) nlnext func cardtest(numstr) revstring = revstr(numstr) s1 = revodd(revstring) s2 = reveven(revstring) s3 =right(string(s1 s2), 1) if s3 = "0" return "Valid" else return "Invalid" ok func revstr(str) strnew = "" for nr = len(str) to 1 step -1 strnew = strnew str[nr] next return strnew func revodd(str) strnew = "" for nr = 1 to len(str) step 2 strnew = strnew str[nr] next sumodd = 0 for p = 1 to len(strnew) sumodd = sumodd number(strnew[p]) next return sumodd func reveven(str) strnew = "" for nr = 2 to len(str) step 2 strnew = strnew str[nr] next lsteven = [] for p = 1 to len(strnew) add(lsteven, string(2*number(strnew[p]))) next arreven = list(len(lsteven)) for q = 1 to len(lsteven) sum = 0 for w = 1 to len(lsteven[q]) sum = sum lsteven[q][w] next arreven[q] = sum next sumarr = 0 for x = 1 to len(arreven) sumarr = sumarr arreven[x] next return sumarr card$(1) = "49927398716"card$(2) = "49927398717"card$(3) = "1234567812345678"card$(4) = "1234567812345670" for i = 1 to 4print card$(i);" ";luhn$(card$(i))next i FUNCTION luhn$(card$) lc = len(card$) for i = lc to 1 step -1 digit = val(mid$(card$,i,1)) if ((lc -i) mod 2) = 0 then chk Sum = chk Sum digit else chk Sum = chk Sum int(digit * 2.2) next i if chk Sum mod 10 = 0 then luhn$ = "True" else luhn$ = "False"end function# Split number into double evens and oddss/.*/&: /: splits/\([0-4]\)\([0-9]\):\(.*\) /:\1\1\3 \2/s/\([5-9]\)\([0-9]\):\(.*\) /:1\1\1\3 \2/t split # Set up addition lookup tables/\([0-9]\)*:\(.*\) \(.*\)/\1\2\23456789012345678/ : adds/\([0-9]\)0:/\1:/s/\([0-9]\)1:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)2:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)3:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)4:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)5:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)6:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)7:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)8:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)9:\(.*\1.\\([0-9]\).*\)/\3:\2/t add /0:/a\Pass/0:/!

PRINT IIF$(Luhn Check Passed("49927398717"), "passed", "failed") ' this test is expected to fail: CON.

||

Complete("[Math Jax]/extensions/Te X/AMScd.js"), Math Jax. arg&true|false)) )& test$49927398716& test$49927398717& test$1234567812345678& test$1234567812345670& ; Note that the original implementation, which follows, is flawed because it assumes that n is a number which, when represented as a string, has an even number of characters. Startup Hook("Te X mathchoice Ready",function()), Math Jax. PRINT IIF$(Luhn Check Passed("1234567812345678"), "passed", "failed") ' this test is expected to pass: CON. (modulo s 10)) (let*-values ([(q r) (quotient/remainder n 10)] [(rq rr) (quotient/remainder (* (if odd? ) ( s rq rr)))))) (map luhn-test '(49927398716 49927398717 1234567812345678 1234567812345670));; - flunked the Luhn test, credit card number: 49927398716 passed the Luhn test, credit card number: 49927398717 passed the Luhn test, credit card number: 1234567812345678 flunked the Luhn test, credit card number: 1234567812345670 /* Rexx **************************************************** Walter Pachl* Implements the task's description in a rather concise way* Instead of reverting the ccn work it backwards**********************************************************/ " cardtest(test[n]) nlnext func cardtest(numstr) revstring = revstr(numstr) s1 = revodd(revstring) s2 = reveven(revstring) s3 =right(string(s1 s2), 1) if s3 = "0" return "Valid" else return "Invalid" ok func revstr(str) strnew = "" for nr = len(str) to 1 step -1 strnew = strnew str[nr] next return strnew func revodd(str) strnew = "" for nr = 1 to len(str) step 2 strnew = strnew str[nr] next sumodd = 0 for p = 1 to len(strnew) sumodd = sumodd number(strnew[p]) next return sumodd func reveven(str) strnew = "" for nr = 2 to len(str) step 2 strnew = strnew str[nr] next lsteven = [] for p = 1 to len(strnew) add(lsteven, string(2*number(strnew[p]))) next arreven = list(len(lsteven)) for q = 1 to len(lsteven) sum = 0 for w = 1 to len(lsteven[q]) sum = sum lsteven[q][w] next arreven[q] = sum next sumarr = 0 for x = 1 to len(arreven) sumarr = sumarr arreven[x] next return sumarr card$(1) = "49927398716"card$(2) = "49927398717"card$(3) = "1234567812345678"card$(4) = "1234567812345670" for i = 1 to 4print card$(i);" ";luhn$(card$(i))next i FUNCTION luhn$(card$) lc = len(card$) for i = lc to 1 step -1 digit = val(mid$(card$,i,1)) if ((lc -i) mod 2) = 0 then chk Sum = chk Sum digit else chk Sum = chk Sum int(digit * 2.2) next i if chk Sum mod 10 = 0 then luhn$ = "True" else luhn$ = "False"end function# Split number into double evens and oddss/.*/&: /: splits/\([0-4]\)\([0-9]\):\(.*\) /:\1\1\3 \2/s/\([5-9]\)\([0-9]\):\(.*\) /:1\1\1\3 \2/t split # Set up addition lookup tables/\([0-9]\)*:\(.*\) \(.*\)/\1\2\23456789012345678/ : adds/\([0-9]\)0:/\1:/s/\([0-9]\)1:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)2:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)3:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)4:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)5:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)6:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)7:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)8:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)9:\(.*\1.\\([0-9]\).*\)/\3:\2/t add /0:/a\Pass/0:/! PRINT IIF$(Luhn Check Passed("49927398717"), "passed", "failed") ' this test is expected to fail: CON.

:/s/\([0-9]\)1:\(.*

Complete("[Math Jax]/extensions/Te X/AMScd.js"), Math Jax.

arg&true|false)) )& test$49927398716& test$49927398717& test$1234567812345678& test$1234567812345670& ; Note that the original implementation, which follows, is flawed because it assumes that n is a number which, when represented as a string, has an even number of characters.

Startup Hook("Te X mathchoice Ready",function()), Math Jax.

PRINT IIF$(Luhn Check Passed("1234567812345678"), "passed", "failed") ' this test is expected to pass: CON. (modulo s 10)) (let*-values ([(q r) (quotient/remainder n 10)] [(rq rr) (quotient/remainder (* (if odd? ) ( s rq rr)))))) (map luhn-test '(49927398716 49927398717 1234567812345678 1234567812345670));; - flunked the Luhn test, credit card number: 49927398716 passed the Luhn test, credit card number: 49927398717 passed the Luhn test, credit card number: 1234567812345678 flunked the Luhn test, credit card number: 1234567812345670 /* Rexx **************************************************** Walter Pachl* Implements the task's description in a rather concise way* Instead of reverting the ccn work it backwards**********************************************************/ " cardtest(test[n]) nlnext func cardtest(numstr) revstring = revstr(numstr) s1 = revodd(revstring) s2 = reveven(revstring) s3 =right(string(s1 s2), 1) if s3 = "0" return "Valid" else return "Invalid" ok func revstr(str) strnew = "" for nr = len(str) to 1 step -1 strnew = strnew str[nr] next return strnew func revodd(str) strnew = "" for nr = 1 to len(str) step 2 strnew = strnew str[nr] next sumodd = 0 for p = 1 to len(strnew) sumodd = sumodd number(strnew[p]) next return sumodd func reveven(str) strnew = "" for nr = 2 to len(str) step 2 strnew = strnew str[nr] next lsteven = [] for p = 1 to len(strnew) add(lsteven, string(2*number(strnew[p]))) next arreven = list(len(lsteven)) for q = 1 to len(lsteven) sum = 0 for w = 1 to len(lsteven[q]) sum = sum lsteven[q][w] next arreven[q] = sum next sumarr = 0 for x = 1 to len(arreven) sumarr = sumarr arreven[x] next return sumarr card$(1) = "49927398716"card$(2) = "49927398717"card$(3) = "1234567812345678"card$(4) = "1234567812345670" for i = 1 to 4print card$(i);" ";luhn$(card$(i))next i FUNCTION luhn$(card$) lc = len(card$) for i = lc to 1 step -1 digit = val(mid$(card$,i,1)) if ((lc -i) mod 2) = 0 then chk Sum = chk Sum digit else chk Sum = chk Sum int(digit * 2.2) next i if chk Sum mod 10 = 0 then luhn$ = "True" else luhn$ = "False"end function# Split number into double evens and oddss/.*/&: /: splits/\([0-4]\)\([0-9]\):\(.*\) /:\1\1\3 \2/s/\([5-9]\)\([0-9]\):\(.*\) /:1\1\1\3 \2/t split # Set up addition lookup tables/\([0-9]\)*:\(.*\) \(.*\)/\1\2\23456789012345678/ : adds/\([0-9]\)0:/\1:/s/\([0-9]\)1:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)2:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)3:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)4:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)5:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)6:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)7:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)8:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)9:\(.*\1.\\([0-9]\).*\)/\3:\2/t add /0:/a\Pass/0:/!

PRINT IIF$(Luhn Check Passed("49927398717"), "passed", "failed") ' this test is expected to fail: CON.

||

Complete("[Math Jax]/extensions/Te X/AMScd.js"), Math Jax. arg&true|false)) )& test$49927398716& test$49927398717& test$1234567812345678& test$1234567812345670& ; Note that the original implementation, which follows, is flawed because it assumes that n is a number which, when represented as a string, has an even number of characters. Startup Hook("Te X mathchoice Ready",function()), Math Jax. PRINT IIF$(Luhn Check Passed("1234567812345678"), "passed", "failed") ' this test is expected to pass: CON. (modulo s 10)) (let*-values ([(q r) (quotient/remainder n 10)] [(rq rr) (quotient/remainder (* (if odd? ) ( s rq rr)))))) (map luhn-test '(49927398716 49927398717 1234567812345678 1234567812345670));; - flunked the Luhn test, credit card number: 49927398716 passed the Luhn test, credit card number: 49927398717 passed the Luhn test, credit card number: 1234567812345678 flunked the Luhn test, credit card number: 1234567812345670 /* Rexx **************************************************** Walter Pachl* Implements the task's description in a rather concise way* Instead of reverting the ccn work it backwards**********************************************************/ " cardtest(test[n]) nlnext func cardtest(numstr) revstring = revstr(numstr) s1 = revodd(revstring) s2 = reveven(revstring) s3 =right(string(s1 s2), 1) if s3 = "0" return "Valid" else return "Invalid" ok func revstr(str) strnew = "" for nr = len(str) to 1 step -1 strnew = strnew str[nr] next return strnew func revodd(str) strnew = "" for nr = 1 to len(str) step 2 strnew = strnew str[nr] next sumodd = 0 for p = 1 to len(strnew) sumodd = sumodd number(strnew[p]) next return sumodd func reveven(str) strnew = "" for nr = 2 to len(str) step 2 strnew = strnew str[nr] next lsteven = [] for p = 1 to len(strnew) add(lsteven, string(2*number(strnew[p]))) next arreven = list(len(lsteven)) for q = 1 to len(lsteven) sum = 0 for w = 1 to len(lsteven[q]) sum = sum lsteven[q][w] next arreven[q] = sum next sumarr = 0 for x = 1 to len(arreven) sumarr = sumarr arreven[x] next return sumarr card$(1) = "49927398716"card$(2) = "49927398717"card$(3) = "1234567812345678"card$(4) = "1234567812345670" for i = 1 to 4print card$(i);" ";luhn$(card$(i))next i FUNCTION luhn$(card$) lc = len(card$) for i = lc to 1 step -1 digit = val(mid$(card$,i,1)) if ((lc -i) mod 2) = 0 then chk Sum = chk Sum digit else chk Sum = chk Sum int(digit * 2.2) next i if chk Sum mod 10 = 0 then luhn$ = "True" else luhn$ = "False"end function# Split number into double evens and oddss/.*/&: /: splits/\([0-4]\)\([0-9]\):\(.*\) /:\1\1\3 \2/s/\([5-9]\)\([0-9]\):\(.*\) /:1\1\1\3 \2/t split # Set up addition lookup tables/\([0-9]\)*:\(.*\) \(.*\)/\1\2\23456789012345678/ : adds/\([0-9]\)0:/\1:/s/\([0-9]\)1:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)2:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)3:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)4:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)5:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)6:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)7:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)8:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)9:\(.*\1.\\([0-9]\).*\)/\3:\2/t add /0:/a\Pass/0:/! PRINT IIF$(Luhn Check Passed("49927398717"), "passed", "failed") ' this test is expected to fail: CON.

.\([0-9]\).*\)/:/s/\([0-9]\)2:\(.*

Complete("[Math Jax]/extensions/Te X/AMScd.js"), Math Jax.

arg&true|false)) )& test$49927398716& test$49927398717& test$1234567812345678& test$1234567812345670& ; Note that the original implementation, which follows, is flawed because it assumes that n is a number which, when represented as a string, has an even number of characters.

Startup Hook("Te X mathchoice Ready",function()), Math Jax.

PRINT IIF$(Luhn Check Passed("1234567812345678"), "passed", "failed") ' this test is expected to pass: CON. (modulo s 10)) (let*-values ([(q r) (quotient/remainder n 10)] [(rq rr) (quotient/remainder (* (if odd? ) ( s rq rr)))))) (map luhn-test '(49927398716 49927398717 1234567812345678 1234567812345670));; - flunked the Luhn test, credit card number: 49927398716 passed the Luhn test, credit card number: 49927398717 passed the Luhn test, credit card number: 1234567812345678 flunked the Luhn test, credit card number: 1234567812345670 /* Rexx **************************************************** Walter Pachl* Implements the task's description in a rather concise way* Instead of reverting the ccn work it backwards**********************************************************/ " cardtest(test[n]) nlnext func cardtest(numstr) revstring = revstr(numstr) s1 = revodd(revstring) s2 = reveven(revstring) s3 =right(string(s1 s2), 1) if s3 = "0" return "Valid" else return "Invalid" ok func revstr(str) strnew = "" for nr = len(str) to 1 step -1 strnew = strnew str[nr] next return strnew func revodd(str) strnew = "" for nr = 1 to len(str) step 2 strnew = strnew str[nr] next sumodd = 0 for p = 1 to len(strnew) sumodd = sumodd number(strnew[p]) next return sumodd func reveven(str) strnew = "" for nr = 2 to len(str) step 2 strnew = strnew str[nr] next lsteven = [] for p = 1 to len(strnew) add(lsteven, string(2*number(strnew[p]))) next arreven = list(len(lsteven)) for q = 1 to len(lsteven) sum = 0 for w = 1 to len(lsteven[q]) sum = sum lsteven[q][w] next arreven[q] = sum next sumarr = 0 for x = 1 to len(arreven) sumarr = sumarr arreven[x] next return sumarr card$(1) = "49927398716"card$(2) = "49927398717"card$(3) = "1234567812345678"card$(4) = "1234567812345670" for i = 1 to 4print card$(i);" ";luhn$(card$(i))next i FUNCTION luhn$(card$) lc = len(card$) for i = lc to 1 step -1 digit = val(mid$(card$,i,1)) if ((lc -i) mod 2) = 0 then chk Sum = chk Sum digit else chk Sum = chk Sum int(digit * 2.2) next i if chk Sum mod 10 = 0 then luhn$ = "True" else luhn$ = "False"end function# Split number into double evens and oddss/.*/&: /: splits/\([0-4]\)\([0-9]\):\(.*\) /:\1\1\3 \2/s/\([5-9]\)\([0-9]\):\(.*\) /:1\1\1\3 \2/t split # Set up addition lookup tables/\([0-9]\)*:\(.*\) \(.*\)/\1\2\23456789012345678/ : adds/\([0-9]\)0:/\1:/s/\([0-9]\)1:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)2:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)3:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)4:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)5:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)6:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)7:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)8:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)9:\(.*\1.\\([0-9]\).*\)/\3:\2/t add /0:/a\Pass/0:/!

PRINT IIF$(Luhn Check Passed("49927398717"), "passed", "failed") ' this test is expected to fail: CON.

||

Complete("[Math Jax]/extensions/Te X/AMScd.js"), Math Jax. arg&true|false)) )& test$49927398716& test$49927398717& test$1234567812345678& test$1234567812345670& ; Note that the original implementation, which follows, is flawed because it assumes that n is a number which, when represented as a string, has an even number of characters. Startup Hook("Te X mathchoice Ready",function()), Math Jax. PRINT IIF$(Luhn Check Passed("1234567812345678"), "passed", "failed") ' this test is expected to pass: CON. (modulo s 10)) (let*-values ([(q r) (quotient/remainder n 10)] [(rq rr) (quotient/remainder (* (if odd? ) ( s rq rr)))))) (map luhn-test '(49927398716 49927398717 1234567812345678 1234567812345670));; - flunked the Luhn test, credit card number: 49927398716 passed the Luhn test, credit card number: 49927398717 passed the Luhn test, credit card number: 1234567812345678 flunked the Luhn test, credit card number: 1234567812345670 /* Rexx **************************************************** Walter Pachl* Implements the task's description in a rather concise way* Instead of reverting the ccn work it backwards**********************************************************/ " cardtest(test[n]) nlnext func cardtest(numstr) revstring = revstr(numstr) s1 = revodd(revstring) s2 = reveven(revstring) s3 =right(string(s1 s2), 1) if s3 = "0" return "Valid" else return "Invalid" ok func revstr(str) strnew = "" for nr = len(str) to 1 step -1 strnew = strnew str[nr] next return strnew func revodd(str) strnew = "" for nr = 1 to len(str) step 2 strnew = strnew str[nr] next sumodd = 0 for p = 1 to len(strnew) sumodd = sumodd number(strnew[p]) next return sumodd func reveven(str) strnew = "" for nr = 2 to len(str) step 2 strnew = strnew str[nr] next lsteven = [] for p = 1 to len(strnew) add(lsteven, string(2*number(strnew[p]))) next arreven = list(len(lsteven)) for q = 1 to len(lsteven) sum = 0 for w = 1 to len(lsteven[q]) sum = sum lsteven[q][w] next arreven[q] = sum next sumarr = 0 for x = 1 to len(arreven) sumarr = sumarr arreven[x] next return sumarr card$(1) = "49927398716"card$(2) = "49927398717"card$(3) = "1234567812345678"card$(4) = "1234567812345670" for i = 1 to 4print card$(i);" ";luhn$(card$(i))next i FUNCTION luhn$(card$) lc = len(card$) for i = lc to 1 step -1 digit = val(mid$(card$,i,1)) if ((lc -i) mod 2) = 0 then chk Sum = chk Sum digit else chk Sum = chk Sum int(digit * 2.2) next i if chk Sum mod 10 = 0 then luhn$ = "True" else luhn$ = "False"end function# Split number into double evens and oddss/.*/&: /: splits/\([0-4]\)\([0-9]\):\(.*\) /:\1\1\3 \2/s/\([5-9]\)\([0-9]\):\(.*\) /:1\1\1\3 \2/t split # Set up addition lookup tables/\([0-9]\)*:\(.*\) \(.*\)/\1\2\23456789012345678/ : adds/\([0-9]\)0:/\1:/s/\([0-9]\)1:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)2:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)3:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)4:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)5:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)6:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)7:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)8:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)9:\(.*\1.\\([0-9]\).*\)/\3:\2/t add /0:/a\Pass/0:/! PRINT IIF$(Luhn Check Passed("49927398717"), "passed", "failed") ' this test is expected to fail: CON.

.\([0-9]\).*\)/:/s/\([0-9]\)3:\(.*

Complete("[Math Jax]/extensions/Te X/AMScd.js"), Math Jax.

arg&true|false)) )& test$49927398716& test$49927398717& test$1234567812345678& test$1234567812345670& ; Note that the original implementation, which follows, is flawed because it assumes that n is a number which, when represented as a string, has an even number of characters.

Startup Hook("Te X mathchoice Ready",function()), Math Jax.

PRINT IIF$(Luhn Check Passed("1234567812345678"), "passed", "failed") ' this test is expected to pass: CON. (modulo s 10)) (let*-values ([(q r) (quotient/remainder n 10)] [(rq rr) (quotient/remainder (* (if odd? ) ( s rq rr)))))) (map luhn-test '(49927398716 49927398717 1234567812345678 1234567812345670));; - flunked the Luhn test, credit card number: 49927398716 passed the Luhn test, credit card number: 49927398717 passed the Luhn test, credit card number: 1234567812345678 flunked the Luhn test, credit card number: 1234567812345670 /* Rexx **************************************************** Walter Pachl* Implements the task's description in a rather concise way* Instead of reverting the ccn work it backwards**********************************************************/ " cardtest(test[n]) nlnext func cardtest(numstr) revstring = revstr(numstr) s1 = revodd(revstring) s2 = reveven(revstring) s3 =right(string(s1 s2), 1) if s3 = "0" return "Valid" else return "Invalid" ok func revstr(str) strnew = "" for nr = len(str) to 1 step -1 strnew = strnew str[nr] next return strnew func revodd(str) strnew = "" for nr = 1 to len(str) step 2 strnew = strnew str[nr] next sumodd = 0 for p = 1 to len(strnew) sumodd = sumodd number(strnew[p]) next return sumodd func reveven(str) strnew = "" for nr = 2 to len(str) step 2 strnew = strnew str[nr] next lsteven = [] for p = 1 to len(strnew) add(lsteven, string(2*number(strnew[p]))) next arreven = list(len(lsteven)) for q = 1 to len(lsteven) sum = 0 for w = 1 to len(lsteven[q]) sum = sum lsteven[q][w] next arreven[q] = sum next sumarr = 0 for x = 1 to len(arreven) sumarr = sumarr arreven[x] next return sumarr card$(1) = "49927398716"card$(2) = "49927398717"card$(3) = "1234567812345678"card$(4) = "1234567812345670" for i = 1 to 4print card$(i);" ";luhn$(card$(i))next i FUNCTION luhn$(card$) lc = len(card$) for i = lc to 1 step -1 digit = val(mid$(card$,i,1)) if ((lc -i) mod 2) = 0 then chk Sum = chk Sum digit else chk Sum = chk Sum int(digit * 2.2) next i if chk Sum mod 10 = 0 then luhn$ = "True" else luhn$ = "False"end function# Split number into double evens and oddss/.*/&: /: splits/\([0-4]\)\([0-9]\):\(.*\) /:\1\1\3 \2/s/\([5-9]\)\([0-9]\):\(.*\) /:1\1\1\3 \2/t split # Set up addition lookup tables/\([0-9]\)*:\(.*\) \(.*\)/\1\2\23456789012345678/ : adds/\([0-9]\)0:/\1:/s/\([0-9]\)1:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)2:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)3:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)4:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)5:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)6:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)7:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)8:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)9:\(.*\1.\\([0-9]\).*\)/\3:\2/t add /0:/a\Pass/0:/!

PRINT IIF$(Luhn Check Passed("49927398717"), "passed", "failed") ' this test is expected to fail: CON.

||

Complete("[Math Jax]/extensions/Te X/AMScd.js"), Math Jax. arg&true|false)) )& test$49927398716& test$49927398717& test$1234567812345678& test$1234567812345670& ; Note that the original implementation, which follows, is flawed because it assumes that n is a number which, when represented as a string, has an even number of characters. Startup Hook("Te X mathchoice Ready",function()), Math Jax. PRINT IIF$(Luhn Check Passed("1234567812345678"), "passed", "failed") ' this test is expected to pass: CON. (modulo s 10)) (let*-values ([(q r) (quotient/remainder n 10)] [(rq rr) (quotient/remainder (* (if odd? ) ( s rq rr)))))) (map luhn-test '(49927398716 49927398717 1234567812345678 1234567812345670));; - flunked the Luhn test, credit card number: 49927398716 passed the Luhn test, credit card number: 49927398717 passed the Luhn test, credit card number: 1234567812345678 flunked the Luhn test, credit card number: 1234567812345670 /* Rexx **************************************************** Walter Pachl* Implements the task's description in a rather concise way* Instead of reverting the ccn work it backwards**********************************************************/ " cardtest(test[n]) nlnext func cardtest(numstr) revstring = revstr(numstr) s1 = revodd(revstring) s2 = reveven(revstring) s3 =right(string(s1 s2), 1) if s3 = "0" return "Valid" else return "Invalid" ok func revstr(str) strnew = "" for nr = len(str) to 1 step -1 strnew = strnew str[nr] next return strnew func revodd(str) strnew = "" for nr = 1 to len(str) step 2 strnew = strnew str[nr] next sumodd = 0 for p = 1 to len(strnew) sumodd = sumodd number(strnew[p]) next return sumodd func reveven(str) strnew = "" for nr = 2 to len(str) step 2 strnew = strnew str[nr] next lsteven = [] for p = 1 to len(strnew) add(lsteven, string(2*number(strnew[p]))) next arreven = list(len(lsteven)) for q = 1 to len(lsteven) sum = 0 for w = 1 to len(lsteven[q]) sum = sum lsteven[q][w] next arreven[q] = sum next sumarr = 0 for x = 1 to len(arreven) sumarr = sumarr arreven[x] next return sumarr card$(1) = "49927398716"card$(2) = "49927398717"card$(3) = "1234567812345678"card$(4) = "1234567812345670" for i = 1 to 4print card$(i);" ";luhn$(card$(i))next i FUNCTION luhn$(card$) lc = len(card$) for i = lc to 1 step -1 digit = val(mid$(card$,i,1)) if ((lc -i) mod 2) = 0 then chk Sum = chk Sum digit else chk Sum = chk Sum int(digit * 2.2) next i if chk Sum mod 10 = 0 then luhn$ = "True" else luhn$ = "False"end function# Split number into double evens and oddss/.*/&: /: splits/\([0-4]\)\([0-9]\):\(.*\) /:\1\1\3 \2/s/\([5-9]\)\([0-9]\):\(.*\) /:1\1\1\3 \2/t split # Set up addition lookup tables/\([0-9]\)*:\(.*\) \(.*\)/\1\2\23456789012345678/ : adds/\([0-9]\)0:/\1:/s/\([0-9]\)1:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)2:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)3:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)4:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)5:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)6:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)7:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)8:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)9:\(.*\1.\\([0-9]\).*\)/\3:\2/t add /0:/a\Pass/0:/! PRINT IIF$(Luhn Check Passed("49927398717"), "passed", "failed") ' this test is expected to fail: CON.

.\([0-9]\).*\)/:/s/\([0-9]\)4:\(.*

Complete("[Math Jax]/extensions/Te X/AMScd.js"), Math Jax.

arg&true|false)) )& test$49927398716& test$49927398717& test$1234567812345678& test$1234567812345670& ; Note that the original implementation, which follows, is flawed because it assumes that n is a number which, when represented as a string, has an even number of characters.

Startup Hook("Te X mathchoice Ready",function()), Math Jax.

PRINT IIF$(Luhn Check Passed("1234567812345678"), "passed", "failed") ' this test is expected to pass: CON. (modulo s 10)) (let*-values ([(q r) (quotient/remainder n 10)] [(rq rr) (quotient/remainder (* (if odd? ) ( s rq rr)))))) (map luhn-test '(49927398716 49927398717 1234567812345678 1234567812345670));; - flunked the Luhn test, credit card number: 49927398716 passed the Luhn test, credit card number: 49927398717 passed the Luhn test, credit card number: 1234567812345678 flunked the Luhn test, credit card number: 1234567812345670 /* Rexx **************************************************** Walter Pachl* Implements the task's description in a rather concise way* Instead of reverting the ccn work it backwards**********************************************************/ " cardtest(test[n]) nlnext func cardtest(numstr) revstring = revstr(numstr) s1 = revodd(revstring) s2 = reveven(revstring) s3 =right(string(s1 s2), 1) if s3 = "0" return "Valid" else return "Invalid" ok func revstr(str) strnew = "" for nr = len(str) to 1 step -1 strnew = strnew str[nr] next return strnew func revodd(str) strnew = "" for nr = 1 to len(str) step 2 strnew = strnew str[nr] next sumodd = 0 for p = 1 to len(strnew) sumodd = sumodd number(strnew[p]) next return sumodd func reveven(str) strnew = "" for nr = 2 to len(str) step 2 strnew = strnew str[nr] next lsteven = [] for p = 1 to len(strnew) add(lsteven, string(2*number(strnew[p]))) next arreven = list(len(lsteven)) for q = 1 to len(lsteven) sum = 0 for w = 1 to len(lsteven[q]) sum = sum lsteven[q][w] next arreven[q] = sum next sumarr = 0 for x = 1 to len(arreven) sumarr = sumarr arreven[x] next return sumarr card$(1) = "49927398716"card$(2) = "49927398717"card$(3) = "1234567812345678"card$(4) = "1234567812345670" for i = 1 to 4print card$(i);" ";luhn$(card$(i))next i FUNCTION luhn$(card$) lc = len(card$) for i = lc to 1 step -1 digit = val(mid$(card$,i,1)) if ((lc -i) mod 2) = 0 then chk Sum = chk Sum digit else chk Sum = chk Sum int(digit * 2.2) next i if chk Sum mod 10 = 0 then luhn$ = "True" else luhn$ = "False"end function# Split number into double evens and oddss/.*/&: /: splits/\([0-4]\)\([0-9]\):\(.*\) /:\1\1\3 \2/s/\([5-9]\)\([0-9]\):\(.*\) /:1\1\1\3 \2/t split # Set up addition lookup tables/\([0-9]\)*:\(.*\) \(.*\)/\1\2\23456789012345678/ : adds/\([0-9]\)0:/\1:/s/\([0-9]\)1:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)2:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)3:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)4:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)5:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)6:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)7:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)8:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)9:\(.*\1.\\([0-9]\).*\)/\3:\2/t add /0:/a\Pass/0:/!

PRINT IIF$(Luhn Check Passed("49927398717"), "passed", "failed") ' this test is expected to fail: CON.

||

Complete("[Math Jax]/extensions/Te X/AMScd.js"), Math Jax. arg&true|false)) )& test$49927398716& test$49927398717& test$1234567812345678& test$1234567812345670& ; Note that the original implementation, which follows, is flawed because it assumes that n is a number which, when represented as a string, has an even number of characters. Startup Hook("Te X mathchoice Ready",function()), Math Jax. PRINT IIF$(Luhn Check Passed("1234567812345678"), "passed", "failed") ' this test is expected to pass: CON. (modulo s 10)) (let*-values ([(q r) (quotient/remainder n 10)] [(rq rr) (quotient/remainder (* (if odd? ) ( s rq rr)))))) (map luhn-test '(49927398716 49927398717 1234567812345678 1234567812345670));; - flunked the Luhn test, credit card number: 49927398716 passed the Luhn test, credit card number: 49927398717 passed the Luhn test, credit card number: 1234567812345678 flunked the Luhn test, credit card number: 1234567812345670 /* Rexx **************************************************** Walter Pachl* Implements the task's description in a rather concise way* Instead of reverting the ccn work it backwards**********************************************************/ " cardtest(test[n]) nlnext func cardtest(numstr) revstring = revstr(numstr) s1 = revodd(revstring) s2 = reveven(revstring) s3 =right(string(s1 s2), 1) if s3 = "0" return "Valid" else return "Invalid" ok func revstr(str) strnew = "" for nr = len(str) to 1 step -1 strnew = strnew str[nr] next return strnew func revodd(str) strnew = "" for nr = 1 to len(str) step 2 strnew = strnew str[nr] next sumodd = 0 for p = 1 to len(strnew) sumodd = sumodd number(strnew[p]) next return sumodd func reveven(str) strnew = "" for nr = 2 to len(str) step 2 strnew = strnew str[nr] next lsteven = [] for p = 1 to len(strnew) add(lsteven, string(2*number(strnew[p]))) next arreven = list(len(lsteven)) for q = 1 to len(lsteven) sum = 0 for w = 1 to len(lsteven[q]) sum = sum lsteven[q][w] next arreven[q] = sum next sumarr = 0 for x = 1 to len(arreven) sumarr = sumarr arreven[x] next return sumarr card$(1) = "49927398716"card$(2) = "49927398717"card$(3) = "1234567812345678"card$(4) = "1234567812345670" for i = 1 to 4print card$(i);" ";luhn$(card$(i))next i FUNCTION luhn$(card$) lc = len(card$) for i = lc to 1 step -1 digit = val(mid$(card$,i,1)) if ((lc -i) mod 2) = 0 then chk Sum = chk Sum digit else chk Sum = chk Sum int(digit * 2.2) next i if chk Sum mod 10 = 0 then luhn$ = "True" else luhn$ = "False"end function# Split number into double evens and oddss/.*/&: /: splits/\([0-4]\)\([0-9]\):\(.*\) /:\1\1\3 \2/s/\([5-9]\)\([0-9]\):\(.*\) /:1\1\1\3 \2/t split # Set up addition lookup tables/\([0-9]\)*:\(.*\) \(.*\)/\1\2\23456789012345678/ : adds/\([0-9]\)0:/\1:/s/\([0-9]\)1:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)2:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)3:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)4:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)5:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)6:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)7:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)8:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)9:\(.*\1.\\([0-9]\).*\)/\3:\2/t add /0:/a\Pass/0:/! PRINT IIF$(Luhn Check Passed("49927398717"), "passed", "failed") ' this test is expected to fail: CON.

.\([0-9]\).*\)/:/s/\([0-9]\)5:\(.*

Complete("[Math Jax]/extensions/Te X/AMScd.js"), Math Jax.

arg&true|false)) )& test$49927398716& test$49927398717& test$1234567812345678& test$1234567812345670& ; Note that the original implementation, which follows, is flawed because it assumes that n is a number which, when represented as a string, has an even number of characters.

Startup Hook("Te X mathchoice Ready",function()), Math Jax.

PRINT IIF$(Luhn Check Passed("1234567812345678"), "passed", "failed") ' this test is expected to pass: CON. (modulo s 10)) (let*-values ([(q r) (quotient/remainder n 10)] [(rq rr) (quotient/remainder (* (if odd? ) ( s rq rr)))))) (map luhn-test '(49927398716 49927398717 1234567812345678 1234567812345670));; - flunked the Luhn test, credit card number: 49927398716 passed the Luhn test, credit card number: 49927398717 passed the Luhn test, credit card number: 1234567812345678 flunked the Luhn test, credit card number: 1234567812345670 /* Rexx **************************************************** Walter Pachl* Implements the task's description in a rather concise way* Instead of reverting the ccn work it backwards**********************************************************/ " cardtest(test[n]) nlnext func cardtest(numstr) revstring = revstr(numstr) s1 = revodd(revstring) s2 = reveven(revstring) s3 =right(string(s1 s2), 1) if s3 = "0" return "Valid" else return "Invalid" ok func revstr(str) strnew = "" for nr = len(str) to 1 step -1 strnew = strnew str[nr] next return strnew func revodd(str) strnew = "" for nr = 1 to len(str) step 2 strnew = strnew str[nr] next sumodd = 0 for p = 1 to len(strnew) sumodd = sumodd number(strnew[p]) next return sumodd func reveven(str) strnew = "" for nr = 2 to len(str) step 2 strnew = strnew str[nr] next lsteven = [] for p = 1 to len(strnew) add(lsteven, string(2*number(strnew[p]))) next arreven = list(len(lsteven)) for q = 1 to len(lsteven) sum = 0 for w = 1 to len(lsteven[q]) sum = sum lsteven[q][w] next arreven[q] = sum next sumarr = 0 for x = 1 to len(arreven) sumarr = sumarr arreven[x] next return sumarr card$(1) = "49927398716"card$(2) = "49927398717"card$(3) = "1234567812345678"card$(4) = "1234567812345670" for i = 1 to 4print card$(i);" ";luhn$(card$(i))next i FUNCTION luhn$(card$) lc = len(card$) for i = lc to 1 step -1 digit = val(mid$(card$,i,1)) if ((lc -i) mod 2) = 0 then chk Sum = chk Sum digit else chk Sum = chk Sum int(digit * 2.2) next i if chk Sum mod 10 = 0 then luhn$ = "True" else luhn$ = "False"end function# Split number into double evens and oddss/.*/&: /: splits/\([0-4]\)\([0-9]\):\(.*\) /:\1\1\3 \2/s/\([5-9]\)\([0-9]\):\(.*\) /:1\1\1\3 \2/t split # Set up addition lookup tables/\([0-9]\)*:\(.*\) \(.*\)/\1\2\23456789012345678/ : adds/\([0-9]\)0:/\1:/s/\([0-9]\)1:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)2:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)3:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)4:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)5:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)6:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)7:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)8:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)9:\(.*\1.\\([0-9]\).*\)/\3:\2/t add /0:/a\Pass/0:/!

PRINT IIF$(Luhn Check Passed("49927398717"), "passed", "failed") ' this test is expected to fail: CON.

||

Complete("[Math Jax]/extensions/Te X/AMScd.js"), Math Jax. arg&true|false)) )& test$49927398716& test$49927398717& test$1234567812345678& test$1234567812345670& ; Note that the original implementation, which follows, is flawed because it assumes that n is a number which, when represented as a string, has an even number of characters. Startup Hook("Te X mathchoice Ready",function()), Math Jax. PRINT IIF$(Luhn Check Passed("1234567812345678"), "passed", "failed") ' this test is expected to pass: CON. (modulo s 10)) (let*-values ([(q r) (quotient/remainder n 10)] [(rq rr) (quotient/remainder (* (if odd? ) ( s rq rr)))))) (map luhn-test '(49927398716 49927398717 1234567812345678 1234567812345670));; - flunked the Luhn test, credit card number: 49927398716 passed the Luhn test, credit card number: 49927398717 passed the Luhn test, credit card number: 1234567812345678 flunked the Luhn test, credit card number: 1234567812345670 /* Rexx **************************************************** Walter Pachl* Implements the task's description in a rather concise way* Instead of reverting the ccn work it backwards**********************************************************/ " cardtest(test[n]) nlnext func cardtest(numstr) revstring = revstr(numstr) s1 = revodd(revstring) s2 = reveven(revstring) s3 =right(string(s1 s2), 1) if s3 = "0" return "Valid" else return "Invalid" ok func revstr(str) strnew = "" for nr = len(str) to 1 step -1 strnew = strnew str[nr] next return strnew func revodd(str) strnew = "" for nr = 1 to len(str) step 2 strnew = strnew str[nr] next sumodd = 0 for p = 1 to len(strnew) sumodd = sumodd number(strnew[p]) next return sumodd func reveven(str) strnew = "" for nr = 2 to len(str) step 2 strnew = strnew str[nr] next lsteven = [] for p = 1 to len(strnew) add(lsteven, string(2*number(strnew[p]))) next arreven = list(len(lsteven)) for q = 1 to len(lsteven) sum = 0 for w = 1 to len(lsteven[q]) sum = sum lsteven[q][w] next arreven[q] = sum next sumarr = 0 for x = 1 to len(arreven) sumarr = sumarr arreven[x] next return sumarr card$(1) = "49927398716"card$(2) = "49927398717"card$(3) = "1234567812345678"card$(4) = "1234567812345670" for i = 1 to 4print card$(i);" ";luhn$(card$(i))next i FUNCTION luhn$(card$) lc = len(card$) for i = lc to 1 step -1 digit = val(mid$(card$,i,1)) if ((lc -i) mod 2) = 0 then chk Sum = chk Sum digit else chk Sum = chk Sum int(digit * 2.2) next i if chk Sum mod 10 = 0 then luhn$ = "True" else luhn$ = "False"end function# Split number into double evens and oddss/.*/&: /: splits/\([0-4]\)\([0-9]\):\(.*\) /:\1\1\3 \2/s/\([5-9]\)\([0-9]\):\(.*\) /:1\1\1\3 \2/t split # Set up addition lookup tables/\([0-9]\)*:\(.*\) \(.*\)/\1\2\23456789012345678/ : adds/\([0-9]\)0:/\1:/s/\([0-9]\)1:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)2:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)3:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)4:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)5:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)6:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)7:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)8:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)9:\(.*\1.\\([0-9]\).*\)/\3:\2/t add /0:/a\Pass/0:/! PRINT IIF$(Luhn Check Passed("49927398717"), "passed", "failed") ' this test is expected to fail: CON.

.\([0-9]\).*\)/:/s/\([0-9]\)6:\(.*

Complete("[Math Jax]/extensions/Te X/AMScd.js"), Math Jax.

arg&true|false)) )& test$49927398716& test$49927398717& test$1234567812345678& test$1234567812345670& ; Note that the original implementation, which follows, is flawed because it assumes that n is a number which, when represented as a string, has an even number of characters.

Startup Hook("Te X mathchoice Ready",function()), Math Jax.

PRINT IIF$(Luhn Check Passed("1234567812345678"), "passed", "failed") ' this test is expected to pass: CON. (modulo s 10)) (let*-values ([(q r) (quotient/remainder n 10)] [(rq rr) (quotient/remainder (* (if odd? ) ( s rq rr)))))) (map luhn-test '(49927398716 49927398717 1234567812345678 1234567812345670));; - flunked the Luhn test, credit card number: 49927398716 passed the Luhn test, credit card number: 49927398717 passed the Luhn test, credit card number: 1234567812345678 flunked the Luhn test, credit card number: 1234567812345670 /* Rexx **************************************************** Walter Pachl* Implements the task's description in a rather concise way* Instead of reverting the ccn work it backwards**********************************************************/ " cardtest(test[n]) nlnext func cardtest(numstr) revstring = revstr(numstr) s1 = revodd(revstring) s2 = reveven(revstring) s3 =right(string(s1 s2), 1) if s3 = "0" return "Valid" else return "Invalid" ok func revstr(str) strnew = "" for nr = len(str) to 1 step -1 strnew = strnew str[nr] next return strnew func revodd(str) strnew = "" for nr = 1 to len(str) step 2 strnew = strnew str[nr] next sumodd = 0 for p = 1 to len(strnew) sumodd = sumodd number(strnew[p]) next return sumodd func reveven(str) strnew = "" for nr = 2 to len(str) step 2 strnew = strnew str[nr] next lsteven = [] for p = 1 to len(strnew) add(lsteven, string(2*number(strnew[p]))) next arreven = list(len(lsteven)) for q = 1 to len(lsteven) sum = 0 for w = 1 to len(lsteven[q]) sum = sum lsteven[q][w] next arreven[q] = sum next sumarr = 0 for x = 1 to len(arreven) sumarr = sumarr arreven[x] next return sumarr card$(1) = "49927398716"card$(2) = "49927398717"card$(3) = "1234567812345678"card$(4) = "1234567812345670" for i = 1 to 4print card$(i);" ";luhn$(card$(i))next i FUNCTION luhn$(card$) lc = len(card$) for i = lc to 1 step -1 digit = val(mid$(card$,i,1)) if ((lc -i) mod 2) = 0 then chk Sum = chk Sum digit else chk Sum = chk Sum int(digit * 2.2) next i if chk Sum mod 10 = 0 then luhn$ = "True" else luhn$ = "False"end function# Split number into double evens and oddss/.*/&: /: splits/\([0-4]\)\([0-9]\):\(.*\) /:\1\1\3 \2/s/\([5-9]\)\([0-9]\):\(.*\) /:1\1\1\3 \2/t split # Set up addition lookup tables/\([0-9]\)*:\(.*\) \(.*\)/\1\2\23456789012345678/ : adds/\([0-9]\)0:/\1:/s/\([0-9]\)1:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)2:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)3:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)4:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)5:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)6:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)7:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)8:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)9:\(.*\1.\\([0-9]\).*\)/\3:\2/t add /0:/a\Pass/0:/!

PRINT IIF$(Luhn Check Passed("49927398717"), "passed", "failed") ' this test is expected to fail: CON.

||

Complete("[Math Jax]/extensions/Te X/AMScd.js"), Math Jax. arg&true|false)) )& test$49927398716& test$49927398717& test$1234567812345678& test$1234567812345670& ; Note that the original implementation, which follows, is flawed because it assumes that n is a number which, when represented as a string, has an even number of characters. Startup Hook("Te X mathchoice Ready",function()), Math Jax. PRINT IIF$(Luhn Check Passed("1234567812345678"), "passed", "failed") ' this test is expected to pass: CON. (modulo s 10)) (let*-values ([(q r) (quotient/remainder n 10)] [(rq rr) (quotient/remainder (* (if odd? ) ( s rq rr)))))) (map luhn-test '(49927398716 49927398717 1234567812345678 1234567812345670));; - flunked the Luhn test, credit card number: 49927398716 passed the Luhn test, credit card number: 49927398717 passed the Luhn test, credit card number: 1234567812345678 flunked the Luhn test, credit card number: 1234567812345670 /* Rexx **************************************************** Walter Pachl* Implements the task's description in a rather concise way* Instead of reverting the ccn work it backwards**********************************************************/ " cardtest(test[n]) nlnext func cardtest(numstr) revstring = revstr(numstr) s1 = revodd(revstring) s2 = reveven(revstring) s3 =right(string(s1 s2), 1) if s3 = "0" return "Valid" else return "Invalid" ok func revstr(str) strnew = "" for nr = len(str) to 1 step -1 strnew = strnew str[nr] next return strnew func revodd(str) strnew = "" for nr = 1 to len(str) step 2 strnew = strnew str[nr] next sumodd = 0 for p = 1 to len(strnew) sumodd = sumodd number(strnew[p]) next return sumodd func reveven(str) strnew = "" for nr = 2 to len(str) step 2 strnew = strnew str[nr] next lsteven = [] for p = 1 to len(strnew) add(lsteven, string(2*number(strnew[p]))) next arreven = list(len(lsteven)) for q = 1 to len(lsteven) sum = 0 for w = 1 to len(lsteven[q]) sum = sum lsteven[q][w] next arreven[q] = sum next sumarr = 0 for x = 1 to len(arreven) sumarr = sumarr arreven[x] next return sumarr card$(1) = "49927398716"card$(2) = "49927398717"card$(3) = "1234567812345678"card$(4) = "1234567812345670" for i = 1 to 4print card$(i);" ";luhn$(card$(i))next i FUNCTION luhn$(card$) lc = len(card$) for i = lc to 1 step -1 digit = val(mid$(card$,i,1)) if ((lc -i) mod 2) = 0 then chk Sum = chk Sum digit else chk Sum = chk Sum int(digit * 2.2) next i if chk Sum mod 10 = 0 then luhn$ = "True" else luhn$ = "False"end function# Split number into double evens and oddss/.*/&: /: splits/\([0-4]\)\([0-9]\):\(.*\) /:\1\1\3 \2/s/\([5-9]\)\([0-9]\):\(.*\) /:1\1\1\3 \2/t split # Set up addition lookup tables/\([0-9]\)*:\(.*\) \(.*\)/\1\2\23456789012345678/ : adds/\([0-9]\)0:/\1:/s/\([0-9]\)1:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)2:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)3:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)4:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)5:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)6:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)7:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)8:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)9:\(.*\1.\\([0-9]\).*\)/\3:\2/t add /0:/a\Pass/0:/! PRINT IIF$(Luhn Check Passed("49927398717"), "passed", "failed") ' this test is expected to fail: CON.

.\([0-9]\).*\)/:/s/\([0-9]\)7:\(.*

Complete("[Math Jax]/extensions/Te X/AMScd.js"), Math Jax.

arg&true|false)) )& test$49927398716& test$49927398717& test$1234567812345678& test$1234567812345670& ; Note that the original implementation, which follows, is flawed because it assumes that n is a number which, when represented as a string, has an even number of characters.

Startup Hook("Te X mathchoice Ready",function()), Math Jax.

PRINT IIF$(Luhn Check Passed("1234567812345678"), "passed", "failed") ' this test is expected to pass: CON. (modulo s 10)) (let*-values ([(q r) (quotient/remainder n 10)] [(rq rr) (quotient/remainder (* (if odd? ) ( s rq rr)))))) (map luhn-test '(49927398716 49927398717 1234567812345678 1234567812345670));; - flunked the Luhn test, credit card number: 49927398716 passed the Luhn test, credit card number: 49927398717 passed the Luhn test, credit card number: 1234567812345678 flunked the Luhn test, credit card number: 1234567812345670 /* Rexx **************************************************** Walter Pachl* Implements the task's description in a rather concise way* Instead of reverting the ccn work it backwards**********************************************************/ " cardtest(test[n]) nlnext func cardtest(numstr) revstring = revstr(numstr) s1 = revodd(revstring) s2 = reveven(revstring) s3 =right(string(s1 s2), 1) if s3 = "0" return "Valid" else return "Invalid" ok func revstr(str) strnew = "" for nr = len(str) to 1 step -1 strnew = strnew str[nr] next return strnew func revodd(str) strnew = "" for nr = 1 to len(str) step 2 strnew = strnew str[nr] next sumodd = 0 for p = 1 to len(strnew) sumodd = sumodd number(strnew[p]) next return sumodd func reveven(str) strnew = "" for nr = 2 to len(str) step 2 strnew = strnew str[nr] next lsteven = [] for p = 1 to len(strnew) add(lsteven, string(2*number(strnew[p]))) next arreven = list(len(lsteven)) for q = 1 to len(lsteven) sum = 0 for w = 1 to len(lsteven[q]) sum = sum lsteven[q][w] next arreven[q] = sum next sumarr = 0 for x = 1 to len(arreven) sumarr = sumarr arreven[x] next return sumarr card$(1) = "49927398716"card$(2) = "49927398717"card$(3) = "1234567812345678"card$(4) = "1234567812345670" for i = 1 to 4print card$(i);" ";luhn$(card$(i))next i FUNCTION luhn$(card$) lc = len(card$) for i = lc to 1 step -1 digit = val(mid$(card$,i,1)) if ((lc -i) mod 2) = 0 then chk Sum = chk Sum digit else chk Sum = chk Sum int(digit * 2.2) next i if chk Sum mod 10 = 0 then luhn$ = "True" else luhn$ = "False"end function# Split number into double evens and oddss/.*/&: /: splits/\([0-4]\)\([0-9]\):\(.*\) /:\1\1\3 \2/s/\([5-9]\)\([0-9]\):\(.*\) /:1\1\1\3 \2/t split # Set up addition lookup tables/\([0-9]\)*:\(.*\) \(.*\)/\1\2\23456789012345678/ : adds/\([0-9]\)0:/\1:/s/\([0-9]\)1:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)2:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)3:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)4:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)5:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)6:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)7:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)8:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)9:\(.*\1.\\([0-9]\).*\)/\3:\2/t add /0:/a\Pass/0:/!

PRINT IIF$(Luhn Check Passed("49927398717"), "passed", "failed") ' this test is expected to fail: CON.

||

Complete("[Math Jax]/extensions/Te X/AMScd.js"), Math Jax. arg&true|false)) )& test$49927398716& test$49927398717& test$1234567812345678& test$1234567812345670& ; Note that the original implementation, which follows, is flawed because it assumes that n is a number which, when represented as a string, has an even number of characters. Startup Hook("Te X mathchoice Ready",function()), Math Jax. PRINT IIF$(Luhn Check Passed("1234567812345678"), "passed", "failed") ' this test is expected to pass: CON. (modulo s 10)) (let*-values ([(q r) (quotient/remainder n 10)] [(rq rr) (quotient/remainder (* (if odd? ) ( s rq rr)))))) (map luhn-test '(49927398716 49927398717 1234567812345678 1234567812345670));; - flunked the Luhn test, credit card number: 49927398716 passed the Luhn test, credit card number: 49927398717 passed the Luhn test, credit card number: 1234567812345678 flunked the Luhn test, credit card number: 1234567812345670 /* Rexx **************************************************** Walter Pachl* Implements the task's description in a rather concise way* Instead of reverting the ccn work it backwards**********************************************************/ " cardtest(test[n]) nlnext func cardtest(numstr) revstring = revstr(numstr) s1 = revodd(revstring) s2 = reveven(revstring) s3 =right(string(s1 s2), 1) if s3 = "0" return "Valid" else return "Invalid" ok func revstr(str) strnew = "" for nr = len(str) to 1 step -1 strnew = strnew str[nr] next return strnew func revodd(str) strnew = "" for nr = 1 to len(str) step 2 strnew = strnew str[nr] next sumodd = 0 for p = 1 to len(strnew) sumodd = sumodd number(strnew[p]) next return sumodd func reveven(str) strnew = "" for nr = 2 to len(str) step 2 strnew = strnew str[nr] next lsteven = [] for p = 1 to len(strnew) add(lsteven, string(2*number(strnew[p]))) next arreven = list(len(lsteven)) for q = 1 to len(lsteven) sum = 0 for w = 1 to len(lsteven[q]) sum = sum lsteven[q][w] next arreven[q] = sum next sumarr = 0 for x = 1 to len(arreven) sumarr = sumarr arreven[x] next return sumarr card$(1) = "49927398716"card$(2) = "49927398717"card$(3) = "1234567812345678"card$(4) = "1234567812345670" for i = 1 to 4print card$(i);" ";luhn$(card$(i))next i FUNCTION luhn$(card$) lc = len(card$) for i = lc to 1 step -1 digit = val(mid$(card$,i,1)) if ((lc -i) mod 2) = 0 then chk Sum = chk Sum digit else chk Sum = chk Sum int(digit * 2.2) next i if chk Sum mod 10 = 0 then luhn$ = "True" else luhn$ = "False"end function# Split number into double evens and oddss/.*/&: /: splits/\([0-4]\)\([0-9]\):\(.*\) /:\1\1\3 \2/s/\([5-9]\)\([0-9]\):\(.*\) /:1\1\1\3 \2/t split # Set up addition lookup tables/\([0-9]\)*:\(.*\) \(.*\)/\1\2\23456789012345678/ : adds/\([0-9]\)0:/\1:/s/\([0-9]\)1:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)2:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)3:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)4:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)5:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)6:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)7:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)8:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)9:\(.*\1.\\([0-9]\).*\)/\3:\2/t add /0:/a\Pass/0:/! PRINT IIF$(Luhn Check Passed("49927398717"), "passed", "failed") ' this test is expected to fail: CON.

.\([0-9]\).*\)/:/s/\([0-9]\)8:\(.*

Complete("[Math Jax]/extensions/Te X/AMScd.js"), Math Jax.

arg&true|false)) )& test$49927398716& test$49927398717& test$1234567812345678& test$1234567812345670& ; Note that the original implementation, which follows, is flawed because it assumes that n is a number which, when represented as a string, has an even number of characters.

Startup Hook("Te X mathchoice Ready",function()), Math Jax.

PRINT IIF$(Luhn Check Passed("1234567812345678"), "passed", "failed") ' this test is expected to pass: CON. (modulo s 10)) (let*-values ([(q r) (quotient/remainder n 10)] [(rq rr) (quotient/remainder (* (if odd? ) ( s rq rr)))))) (map luhn-test '(49927398716 49927398717 1234567812345678 1234567812345670));; - flunked the Luhn test, credit card number: 49927398716 passed the Luhn test, credit card number: 49927398717 passed the Luhn test, credit card number: 1234567812345678 flunked the Luhn test, credit card number: 1234567812345670 /* Rexx **************************************************** Walter Pachl* Implements the task's description in a rather concise way* Instead of reverting the ccn work it backwards**********************************************************/ " cardtest(test[n]) nlnext func cardtest(numstr) revstring = revstr(numstr) s1 = revodd(revstring) s2 = reveven(revstring) s3 =right(string(s1 s2), 1) if s3 = "0" return "Valid" else return "Invalid" ok func revstr(str) strnew = "" for nr = len(str) to 1 step -1 strnew = strnew str[nr] next return strnew func revodd(str) strnew = "" for nr = 1 to len(str) step 2 strnew = strnew str[nr] next sumodd = 0 for p = 1 to len(strnew) sumodd = sumodd number(strnew[p]) next return sumodd func reveven(str) strnew = "" for nr = 2 to len(str) step 2 strnew = strnew str[nr] next lsteven = [] for p = 1 to len(strnew) add(lsteven, string(2*number(strnew[p]))) next arreven = list(len(lsteven)) for q = 1 to len(lsteven) sum = 0 for w = 1 to len(lsteven[q]) sum = sum lsteven[q][w] next arreven[q] = sum next sumarr = 0 for x = 1 to len(arreven) sumarr = sumarr arreven[x] next return sumarr card$(1) = "49927398716"card$(2) = "49927398717"card$(3) = "1234567812345678"card$(4) = "1234567812345670" for i = 1 to 4print card$(i);" ";luhn$(card$(i))next i FUNCTION luhn$(card$) lc = len(card$) for i = lc to 1 step -1 digit = val(mid$(card$,i,1)) if ((lc -i) mod 2) = 0 then chk Sum = chk Sum digit else chk Sum = chk Sum int(digit * 2.2) next i if chk Sum mod 10 = 0 then luhn$ = "True" else luhn$ = "False"end function# Split number into double evens and oddss/.*/&: /: splits/\([0-4]\)\([0-9]\):\(.*\) /:\1\1\3 \2/s/\([5-9]\)\([0-9]\):\(.*\) /:1\1\1\3 \2/t split # Set up addition lookup tables/\([0-9]\)*:\(.*\) \(.*\)/\1\2\23456789012345678/ : adds/\([0-9]\)0:/\1:/s/\([0-9]\)1:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)2:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)3:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)4:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)5:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)6:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)7:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)8:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)9:\(.*\1.\\([0-9]\).*\)/\3:\2/t add /0:/a\Pass/0:/!

PRINT IIF$(Luhn Check Passed("49927398717"), "passed", "failed") ' this test is expected to fail: CON.

||

Complete("[Math Jax]/extensions/Te X/AMScd.js"), Math Jax. arg&true|false)) )& test$49927398716& test$49927398717& test$1234567812345678& test$1234567812345670& ; Note that the original implementation, which follows, is flawed because it assumes that n is a number which, when represented as a string, has an even number of characters. Startup Hook("Te X mathchoice Ready",function()), Math Jax. PRINT IIF$(Luhn Check Passed("1234567812345678"), "passed", "failed") ' this test is expected to pass: CON. (modulo s 10)) (let*-values ([(q r) (quotient/remainder n 10)] [(rq rr) (quotient/remainder (* (if odd? ) ( s rq rr)))))) (map luhn-test '(49927398716 49927398717 1234567812345678 1234567812345670));; - flunked the Luhn test, credit card number: 49927398716 passed the Luhn test, credit card number: 49927398717 passed the Luhn test, credit card number: 1234567812345678 flunked the Luhn test, credit card number: 1234567812345670 /* Rexx **************************************************** Walter Pachl* Implements the task's description in a rather concise way* Instead of reverting the ccn work it backwards**********************************************************/ " cardtest(test[n]) nlnext func cardtest(numstr) revstring = revstr(numstr) s1 = revodd(revstring) s2 = reveven(revstring) s3 =right(string(s1 s2), 1) if s3 = "0" return "Valid" else return "Invalid" ok func revstr(str) strnew = "" for nr = len(str) to 1 step -1 strnew = strnew str[nr] next return strnew func revodd(str) strnew = "" for nr = 1 to len(str) step 2 strnew = strnew str[nr] next sumodd = 0 for p = 1 to len(strnew) sumodd = sumodd number(strnew[p]) next return sumodd func reveven(str) strnew = "" for nr = 2 to len(str) step 2 strnew = strnew str[nr] next lsteven = [] for p = 1 to len(strnew) add(lsteven, string(2*number(strnew[p]))) next arreven = list(len(lsteven)) for q = 1 to len(lsteven) sum = 0 for w = 1 to len(lsteven[q]) sum = sum lsteven[q][w] next arreven[q] = sum next sumarr = 0 for x = 1 to len(arreven) sumarr = sumarr arreven[x] next return sumarr card$(1) = "49927398716"card$(2) = "49927398717"card$(3) = "1234567812345678"card$(4) = "1234567812345670" for i = 1 to 4print card$(i);" ";luhn$(card$(i))next i FUNCTION luhn$(card$) lc = len(card$) for i = lc to 1 step -1 digit = val(mid$(card$,i,1)) if ((lc -i) mod 2) = 0 then chk Sum = chk Sum digit else chk Sum = chk Sum int(digit * 2.2) next i if chk Sum mod 10 = 0 then luhn$ = "True" else luhn$ = "False"end function# Split number into double evens and oddss/.*/&: /: splits/\([0-4]\)\([0-9]\):\(.*\) /:\1\1\3 \2/s/\([5-9]\)\([0-9]\):\(.*\) /:1\1\1\3 \2/t split # Set up addition lookup tables/\([0-9]\)*:\(.*\) \(.*\)/\1\2\23456789012345678/ : adds/\([0-9]\)0:/\1:/s/\([0-9]\)1:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)2:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)3:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)4:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)5:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)6:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)7:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)8:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)9:\(.*\1.\\([0-9]\).*\)/\3:\2/t add /0:/a\Pass/0:/! PRINT IIF$(Luhn Check Passed("49927398717"), "passed", "failed") ' this test is expected to fail: CON.

.\([0-9]\).*\)/:/s/\([0-9]\)9:\(.*

Complete("[Math Jax]/extensions/Te X/AMScd.js"), Math Jax.

arg&true|false)) )& test$49927398716& test$49927398717& test$1234567812345678& test$1234567812345670& ; Note that the original implementation, which follows, is flawed because it assumes that n is a number which, when represented as a string, has an even number of characters.

Startup Hook("Te X mathchoice Ready",function()), Math Jax.

PRINT IIF$(Luhn Check Passed("1234567812345678"), "passed", "failed") ' this test is expected to pass: CON. (modulo s 10)) (let*-values ([(q r) (quotient/remainder n 10)] [(rq rr) (quotient/remainder (* (if odd? ) ( s rq rr)))))) (map luhn-test '(49927398716 49927398717 1234567812345678 1234567812345670));; - flunked the Luhn test, credit card number: 49927398716 passed the Luhn test, credit card number: 49927398717 passed the Luhn test, credit card number: 1234567812345678 flunked the Luhn test, credit card number: 1234567812345670 /* Rexx **************************************************** Walter Pachl* Implements the task's description in a rather concise way* Instead of reverting the ccn work it backwards**********************************************************/ " cardtest(test[n]) nlnext func cardtest(numstr) revstring = revstr(numstr) s1 = revodd(revstring) s2 = reveven(revstring) s3 =right(string(s1 s2), 1) if s3 = "0" return "Valid" else return "Invalid" ok func revstr(str) strnew = "" for nr = len(str) to 1 step -1 strnew = strnew str[nr] next return strnew func revodd(str) strnew = "" for nr = 1 to len(str) step 2 strnew = strnew str[nr] next sumodd = 0 for p = 1 to len(strnew) sumodd = sumodd number(strnew[p]) next return sumodd func reveven(str) strnew = "" for nr = 2 to len(str) step 2 strnew = strnew str[nr] next lsteven = [] for p = 1 to len(strnew) add(lsteven, string(2*number(strnew[p]))) next arreven = list(len(lsteven)) for q = 1 to len(lsteven) sum = 0 for w = 1 to len(lsteven[q]) sum = sum lsteven[q][w] next arreven[q] = sum next sumarr = 0 for x = 1 to len(arreven) sumarr = sumarr arreven[x] next return sumarr card$(1) = "49927398716"card$(2) = "49927398717"card$(3) = "1234567812345678"card$(4) = "1234567812345670" for i = 1 to 4print card$(i);" ";luhn$(card$(i))next i FUNCTION luhn$(card$) lc = len(card$) for i = lc to 1 step -1 digit = val(mid$(card$,i,1)) if ((lc -i) mod 2) = 0 then chk Sum = chk Sum digit else chk Sum = chk Sum int(digit * 2.2) next i if chk Sum mod 10 = 0 then luhn$ = "True" else luhn$ = "False"end function# Split number into double evens and oddss/.*/&: /: splits/\([0-4]\)\([0-9]\):\(.*\) /:\1\1\3 \2/s/\([5-9]\)\([0-9]\):\(.*\) /:1\1\1\3 \2/t split # Set up addition lookup tables/\([0-9]\)*:\(.*\) \(.*\)/\1\2\23456789012345678/ : adds/\([0-9]\)0:/\1:/s/\([0-9]\)1:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)2:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)3:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)4:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)5:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)6:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)7:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)8:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)9:\(.*\1.\\([0-9]\).*\)/\3:\2/t add /0:/a\Pass/0:/!

PRINT IIF$(Luhn Check Passed("49927398717"), "passed", "failed") ' this test is expected to fail: CON.

||

Complete("[Math Jax]/extensions/Te X/AMScd.js"), Math Jax. arg&true|false)) )& test$49927398716& test$49927398717& test$1234567812345678& test$1234567812345670& ; Note that the original implementation, which follows, is flawed because it assumes that n is a number which, when represented as a string, has an even number of characters. Startup Hook("Te X mathchoice Ready",function()), Math Jax. PRINT IIF$(Luhn Check Passed("1234567812345678"), "passed", "failed") ' this test is expected to pass: CON. (modulo s 10)) (let*-values ([(q r) (quotient/remainder n 10)] [(rq rr) (quotient/remainder (* (if odd? ) ( s rq rr)))))) (map luhn-test '(49927398716 49927398717 1234567812345678 1234567812345670));; - flunked the Luhn test, credit card number: 49927398716 passed the Luhn test, credit card number: 49927398717 passed the Luhn test, credit card number: 1234567812345678 flunked the Luhn test, credit card number: 1234567812345670 /* Rexx **************************************************** Walter Pachl* Implements the task's description in a rather concise way* Instead of reverting the ccn work it backwards**********************************************************/ " cardtest(test[n]) nlnext func cardtest(numstr) revstring = revstr(numstr) s1 = revodd(revstring) s2 = reveven(revstring) s3 =right(string(s1 s2), 1) if s3 = "0" return "Valid" else return "Invalid" ok func revstr(str) strnew = "" for nr = len(str) to 1 step -1 strnew = strnew str[nr] next return strnew func revodd(str) strnew = "" for nr = 1 to len(str) step 2 strnew = strnew str[nr] next sumodd = 0 for p = 1 to len(strnew) sumodd = sumodd number(strnew[p]) next return sumodd func reveven(str) strnew = "" for nr = 2 to len(str) step 2 strnew = strnew str[nr] next lsteven = [] for p = 1 to len(strnew) add(lsteven, string(2*number(strnew[p]))) next arreven = list(len(lsteven)) for q = 1 to len(lsteven) sum = 0 for w = 1 to len(lsteven[q]) sum = sum lsteven[q][w] next arreven[q] = sum next sumarr = 0 for x = 1 to len(arreven) sumarr = sumarr arreven[x] next return sumarr card$(1) = "49927398716"card$(2) = "49927398717"card$(3) = "1234567812345678"card$(4) = "1234567812345670" for i = 1 to 4print card$(i);" ";luhn$(card$(i))next i FUNCTION luhn$(card$) lc = len(card$) for i = lc to 1 step -1 digit = val(mid$(card$,i,1)) if ((lc -i) mod 2) = 0 then chk Sum = chk Sum digit else chk Sum = chk Sum int(digit * 2.2) next i if chk Sum mod 10 = 0 then luhn$ = "True" else luhn$ = "False"end function# Split number into double evens and oddss/.*/&: /: splits/\([0-4]\)\([0-9]\):\(.*\) /:\1\1\3 \2/s/\([5-9]\)\([0-9]\):\(.*\) /:1\1\1\3 \2/t split # Set up addition lookup tables/\([0-9]\)*:\(.*\) \(.*\)/\1\2\23456789012345678/ : adds/\([0-9]\)0:/\1:/s/\([0-9]\)1:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)2:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)3:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)4:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)5:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)6:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)7:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)8:\(.*\1.\\([0-9]\).*\)/\3:\2/s/\([0-9]\)9:\(.*\1.\\([0-9]\).*\)/\3:\2/t add /0:/a\Pass/0:/! PRINT IIF$(Luhn Check Passed("49927398717"), "passed", "failed") ' this test is expected to fail: CON.

.\([0-9]\).*\)/:/t add /0:/a\Pass/0:/!

PRINT IIF$(Luhn Check Passed("49927398717"), "passed", "failed") ' this test is expected to fail: CON.

Leave a Reply