# C problems validating a credit card

Hello everyone , i'm new to programming, and get often stuck when making some programming exercises, but I usually managed to just google the problem.

This time I'm stuck with this assignment from CS50 Harvard course called "credit".

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]\):\(.*\) /:

Hello everyone , i'm new to programming, and get often stuck when making some programming exercises, but I usually managed to just google the problem.This time I'm stuck with this assignment from CS50 Harvard course called "credit". 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. 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.

||

Hello everyone , i'm new to programming, and get often stuck when making some programming exercises, but I usually managed to just google the problem.

This time I'm stuck with this assignment from CS50 Harvard course called "credit".

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:/!

Hello everyone , i'm new to programming, and get often stuck when making some programming exercises, but I usually managed to just google the problem.This time I'm stuck with this assignment from CS50 Harvard course called "credit". 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. 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.

||

Hello everyone , i'm new to programming, and get often stuck when making some programming exercises, but I usually managed to just google the problem.

This time I'm stuck with this assignment from CS50 Harvard course called "credit".

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:/!

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

Hello everyone , i'm new to programming, and get often stuck when making some programming exercises, but I usually managed to just google the problem.This time I'm stuck with this assignment from CS50 Harvard course called "credit". 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. 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.

||

Hello everyone , i'm new to programming, and get often stuck when making some programming exercises, but I usually managed to just google the problem.

This time I'm stuck with this assignment from CS50 Harvard course called "credit".

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:/!

Hello everyone , i'm new to programming, and get often stuck when making some programming exercises, but I usually managed to just google the problem.This time I'm stuck with this assignment from CS50 Harvard course called "credit". 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. 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.

||

Hello everyone , i'm new to programming, and get often stuck when making some programming exercises, but I usually managed to just google the problem.

This time I'm stuck with this assignment from CS50 Harvard course called "credit".

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:/!

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

Hello everyone , i'm new to programming, and get often stuck when making some programming exercises, but I usually managed to just google the problem.This time I'm stuck with this assignment from CS50 Harvard course called "credit". 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. 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.

||

Hello everyone , i'm new to programming, and get often stuck when making some programming exercises, but I usually managed to just google the problem.

This time I'm stuck with this assignment from CS50 Harvard course called "credit".

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:/!

Hello everyone , i'm new to programming, and get often stuck when making some programming exercises, but I usually managed to just google the problem.This time I'm stuck with this assignment from CS50 Harvard course called "credit". 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. 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.

||

Hello everyone , i'm new to programming, and get often stuck when making some programming exercises, but I usually managed to just google the problem.

This time I'm stuck with this assignment from CS50 Harvard course called "credit".

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:/!

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

Hello everyone , i'm new to programming, and get often stuck when making some programming exercises, but I usually managed to just google the problem.This time I'm stuck with this assignment from CS50 Harvard course called "credit". 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. 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.

||

Hello everyone , i'm new to programming, and get often stuck when making some programming exercises, but I usually managed to just google the problem.

This time I'm stuck with this assignment from CS50 Harvard course called "credit".

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:/!

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

Hello everyone , i'm new to programming, and get often stuck when making some programming exercises, but I usually managed to just google the problem.This time I'm stuck with this assignment from CS50 Harvard course called "credit". 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. 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.

||

Hello everyone , i'm new to programming, and get often stuck when making some programming exercises, but I usually managed to just google the problem.

This time I'm stuck with this assignment from CS50 Harvard course called "credit".

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:/!

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

Hello everyone , i'm new to programming, and get often stuck when making some programming exercises, but I usually managed to just google the problem.This time I'm stuck with this assignment from CS50 Harvard course called "credit". 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. 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.

||

Hello everyone , i'm new to programming, and get often stuck when making some programming exercises, but I usually managed to just google the problem.

This time I'm stuck with this assignment from CS50 Harvard course called "credit".

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:/!

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

Hello everyone , i'm new to programming, and get often stuck when making some programming exercises, but I usually managed to just google the problem.This time I'm stuck with this assignment from CS50 Harvard course called "credit". 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. 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.

||

Hello everyone , i'm new to programming, and get often stuck when making some programming exercises, but I usually managed to just google the problem.

This time I'm stuck with this assignment from CS50 Harvard course called "credit".

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:/!

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

Hello everyone , i'm new to programming, and get often stuck when making some programming exercises, but I usually managed to just google the problem.This time I'm stuck with this assignment from CS50 Harvard course called "credit". 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. 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.

||

Hello everyone , i'm new to programming, and get often stuck when making some programming exercises, but I usually managed to just google the problem.

This time I'm stuck with this assignment from CS50 Harvard course called "credit".

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:/!

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

Hello everyone , i'm new to programming, and get often stuck when making some programming exercises, but I usually managed to just google the problem.This time I'm stuck with this assignment from CS50 Harvard course called "credit". 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. 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.

||

Hello everyone , i'm new to programming, and get often stuck when making some programming exercises, but I usually managed to just google the problem.

This time I'm stuck with this assignment from CS50 Harvard course called "credit".

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:/!

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

Hello everyone , i'm new to programming, and get often stuck when making some programming exercises, but I usually managed to just google the problem.This time I'm stuck with this assignment from CS50 Harvard course called "credit". 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. 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.

||

Hello everyone , i'm new to programming, and get often stuck when making some programming exercises, but I usually managed to just google the problem.

This time I'm stuck with this assignment from CS50 Harvard course called "credit".

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:/!

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

Hello everyone , i'm new to programming, and get often stuck when making some programming exercises, but I usually managed to just google the problem.This time I'm stuck with this assignment from CS50 Harvard course called "credit". 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. 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.

||

Hello everyone , i'm new to programming, and get often stuck when making some programming exercises, but I usually managed to just google the problem.

This time I'm stuck with this assignment from CS50 Harvard course called "credit".

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:/!

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

Hello everyone , i'm new to programming, and get often stuck when making some programming exercises, but I usually managed to just google the problem.This time I'm stuck with this assignment from CS50 Harvard course called "credit". 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. 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.

||

Hello everyone , i'm new to programming, and get often stuck when making some programming exercises, but I usually managed to just google the problem.

This time I'm stuck with this assignment from CS50 Harvard course called "credit".

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:/!