7 kyu
Credit card issuer checking
1,764 of 6,402treffynnon
Loading description...
Algorithms
View
This comment has been reported as {{ abuseKindText }}.
Show
This comment has been hidden. You can view it now .
This comment can not be viewed.
- |
- Reply
- Edit
- View Solution
- Expand 1 Reply Expand {{ comments?.length }} replies
- Collapse
- Spoiler
- Remove
- Remove comment & replies
- Report
{{ fetchSolutionsError }}
-
-
Your rendered github-flavored markdown will appear here.
-
Label this discussion...
-
No Label
Keep the comment unlabeled if none of the below applies.
-
Issue
Use the issue label when reporting problems with the kata.
Be sure to explain the problem clearly and include the steps to reproduce. -
Suggestion
Use the suggestion label if you have feedback on how this kata can be improved.
-
Question
Use the question label if you have questions and/or need help solving the kata.
Don't forget to mention the language you're using, and mark as having spoiler if you include your solution.
-
No Label
- Cancel
Commenting is not allowed on this discussion
You cannot view this solution
There is no solution to show
Please sign in or sign up to leave a comment.
Am I missing something or, without more tests, could AMEX just be returned for any card number with a length of 15 digits?
No random tests in Haskell.
Fork with added random tests.
This comment has been hidden.
This comment has been hidden.
Description should be language-agnostic
In C++, Java : string as function input
In C, CoffeeScript, C#, Haskell, JavaScript, Python, Ruby, TypeScript : number as function input
python new test frame work
Approved
C#: method name should be
PascalCase
(Please refer to implementation of backward compatibility here )Any card number with a length of 15 starting with 3 is AMEX, not just 34 or 37.
Same for Discover: length of 16 starting with 6.
Should this remain correct?
I started this kata from TS. And in TS explanation for this kata hasn't table with numbers to match issuer. I couldn't understand how find this rule until open this kata on JS. It is unacceptable has differrent explanation for different languages.
Amazing challenge..
This is very likely use case in production. Good kata.
Enabled in this fork
This comment has been hidden.
Not a kata issue, it's a problem with your code. Read this
Your first condition is not good.
Please, NASM Translation
This comment has been hidden.
The kata isn't broken, your code is wrong, check how you use switch.
This comment has been hidden.
This comment has been hidden.
I think when you run this check: (n.substring(0,1) === "4" && n.length === 13 || n.length === 16) It should really be: (n.substring(0,1) === "4" && (n.length === 13 || n.length === 16))
Not a kata issue then.
Thank you @tbesmer!
For my solution using 'C', random tests are failing. The error message is not helpful either. @treffynnon could you plese look into it. I don't want to forfeit :D
What failures are you getting? I cannot see your solution so I've no way to know what it is happening unfortunately.
Test fails: For example this shouldn't output "VISA": 4111111111111111 4111111111111 4012888888881881 41111111111111 411111111111111
But the definition says, it's VISA
@treffynnon, C++ translation awaiting review. Thx.
In C, getIssuer accepts a pointer to long, but in the tests you pass a long directly. This should be fixed.
I think I have fixed this now.
Thank you very much for this kata. It taught me about matches method.
I passed sample test but attempt showing an error.
Should I obtain honour for this Kata (7 kyu) when I'm actually on 5 kyu? I did't obtain the honour for Kata's on 8 and 7 kyu's and I'm eager to know why.
Yes, it's a CW wide problem right now, come back later and they'll be there.
You have two tests that have the expected result as: "Values should not be equal: 'VISA'", but the kata expects VISA. You should change those tests to "Values should not be equal: 'Visa'" or delete them. Did this kata in javascript.
This comment has been hidden.
Thank you for replying. I think its because i misunderstood the requirments. I thought that the VISA length is between 13 and 16 and because of that I thought that the test was meant for something else. My apolopgies... After seeing your explanation I was able to fully understand. Thank you for this lovly kata!
Not an issue then.
Similar to phone number, credit card number is a string.
Phone numbers may or may not have a leading zero, contain formatting for country or area codes and additional information such as extension numbers etc.
Whereas a credit card number can be a string or when stripped of whitespace an integer.
This is also one little hurdle to throw into the kata to make it a touch more difficult/require some thought.
damn my solution looks like a sh**, i need more learn Good Kata +
This comment has been hidden.
You're right - that was an oversight in the tests. I've now added a couple tests to all the languages to prevent this from passing.
The solution in Java was even exploiting this!
Was a real PITA as I had to republish after changing each language - if I did them all at once it kept coming back saying the server had timed out!
Anyway should be fixed now for all langs.
Java Translation added! :)
Thank you for this kata!
This comment has been hidden.
On python I can complete all test cases on submit except for the last one. I get "None should equal 'Unknown'" Yet, even when passing None or not providing any input during my test cases 'Unknown' is returned as expected. What am I not understanding here?
I see you already found the answer.
For "Mastercard" the table states that it should begin with "51-55".
This could be interpreted (as I did) as "the first 5 characters should be a five, a one, a dash, a five and a five"
I think it would be better to spell out that this actually means "the first 2 characters should be within the range 51 to 55"
Description updated.
This comment has been hidden.
Needs fixed tests for card number length. Currently these are only randomly triggered by the random tests. And the test failure message needs to be helpful in this case.
(Ruby version, but I expect the other languages are similar.)
I don't think it is the role of the tests to become a hand holding guessing framework. Rather they are there to verify the submission.
I'm unclear on what "unfindables" are. I've written about 20 or so tests that pass and when I submit my solution everything passes except the second of the two "It should return Unknown for unfindables". The submission test result stated "Expected: Unknown, instead got: Mastercard". I wrote a new batch of tests to try and nail down variations of the Mastercard rules that shouldn't pass but cannot replicate this failure. Am I missing something in the definition of "unfindables"?
No you're not. Unfindables are just those numbers that exist outside of valid card numbers - so your solution is matching numbers as Mastercard even though they're outside the expected range/rules for a Mastercard. I might change that message to make it clearer I think.
Ok thank you, I appreciate your quick reply. I'll continue to write tests and try to figure out why I'm getting a false match.
You should state explicitly that Mastercard credit card numbers start from 51 to 55 included.
Ranges in natural language are inclusive though. I don't really see this as necessary.
My point wasn't the inclusive one, but rather "a - b" means "from a to b".
✔
Python PEP8:
Example:
It complicates the description some (what I was trying to avoid originally), but have morphed to PEP8 compat.
Nice, did it in js and no problems. Ready to ship !
Haha nice!
One tiny issue: the description mentions
getIssuer(number)
but in python the function isgetIssuer(x)
Otherwise nice and easy kata. I'm eager to see some creative solutions ;-)
Good point. All langs had the same shortcut - now resolved across all.
Duplicate: http://www.codewars.com/kata/credit-card-validifier
A JS translation was added for the linked kata 7 months ago by ZozoFouchtra(1 kyu) according to the discussion against it. That still has not been approved :(
Additionally the description and testing of that kata don't appear to be up to snuff according to the discussion on it. I have added a Python solution to my kata with improved tests.
I could submit a Haskell, CoffeeScript and JavaScript translation to the linked kata, but it doesn't appear it would have much hope of getting accepted.
How should one proceed in such a situation?
I have no idea, there are quite a few similar cases with inactive authors' katas, but I don't think there's an official recomendation on this matter.
Ah ok that makes it difficult then. Unfortunately, I didn't even know that one existed before I created this kata.
As it is not an exact duplicate I am going to mark this issue as resolved. If you disagree then please let me know.
Needs random test cases
Good suggestion. Now added.
Same as here (but not Python - so not labeled as "Issue");-): http://www.codewars.com/kata/credit-card-validifier/python