7 kyu
Credit Card Mask
78,843 of 194,878samranjbari
Loading description...
Strings
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.
This comment has been hidden.
The suggestion flag is intended to be used when someone proposes an improvement of the kata's description, or has made a fork to fix a bug, or wants a review of a translation in a new language, etc.
just completed my first kata, it was a good Feeling .
Hey guys, i've just completed my first kata! It was pretty confusing at first time, but I understood, that programm doesnt need to include "input"
My code run correctly in ChromeDev Tools, but when I tested it here it giving me an error.
check this please : https://docs.codewars.com/training/troubleshooting#your-solution-seems-to-work-or-is-close-to-working-but-still-fails-tests
This comment has been hidden.
You did not null-terminate the
masked
at all.thanks a million.
This comment has been hidden.
The
Issue
label is for provable kata issues. Please use theQuestion
label when asking for help and mark your post as a spoiler and use appropriate markdown formatting when posting code. See https://docs.codewars.com/training/troubleshooting#post-discourse.Your code throws an error when executed. Read and understand that error and you'll understand why.
Not a kata issue.
I tried to use end= '' but it said that I need to use == or :=, can someone help me with this?
This comment has been hidden.
This comment has been hidden.
Can you tell what your solution would do if the input was
"11111"
?it is fully masked/censored. Also forgot to say but my code is written in python
Hi, Please edit task Description: if number of simbols equals or less then 4, need to return all this simbols.
Does anyone know why the web doesn't accept this code??
// return masked string function maskify(cc) { if (cc.length > 4) { const cadenaVisible = cc.slice(cc.length -4, cc.length); const caracteresQueOcultar = cc.slice(0, cc.length -4); const enmascaramiento = '#'.repeat(caracteresQueOcultar.length); console.log(enmascaramiento + cadenaVisible); } else { console.log(cc); } }
Lol. For C language, you could've written that the masked pointer is already allocated. So I could just write to it 🤦♀️
When you enter the trainer, the solution setup for C says literally that? Maybe the wording is not clear enough?
it's not only specified but also tested.
This comment has been hidden.
"This is my secooooond kata"
This comment has been hidden.
That's a problem with your code, not a kata issue.
This was my first kata. It's been a few months and now I feel more powerful. Thanks for this kata!
Great
MY FIRST VICTORY.IT WILL NOT BE THE LAST.I WILL BE THE GREATEST C SHARP SAMURAI!!!
yes iam autistic
Congrats!!!
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
This is a question, not a kata issue. See https://docs.codewars.com/training/troubleshooting#post-discourse.
Read the documentation.
This comment has been hidden.
This comment has been hidden.
Please use appropriate markdown formatting when posting code. See https://docs.codewars.com/training/troubleshooting#post-discourse.
The message "expected
'##y'
to equal'miy'
" indicates that your function returned'##y'
when it should have returned'miy'
. So, yes, your function is returning'##y'
but is doing so incorrectly.Also, you raised a question but I don't see any question in your post. Closing.
4556364607935616 turned to ############5616 Still showing error for some reason.
Not a kata issue. See https://docs.codewars.com/training/troubleshooting#post-discourse.
i have same problem how you solved it
Wow
This comment has been hidden.
Your code is not returning anything. Not a kata issue, please read the docs: https://docs.codewars.com/training/troubleshooting
This comment has been hidden.
Please use the spoiler flag and appropriate formatting when posting code. See https://docs.codewars.com/training/troubleshooting/#post-discourse.
You're printing instead of returning. See https://docs.codewars.com/training/troubleshooting/#.print-vs-return and https://docs.codewars.com/training/training-example#writing-a-solution.
?wtf It is example only. Print was for output only. Code succesffuly works in the Jupiter/Console etc
If you show us some code that's wrong and ask what's wrong with it, we tell you what's wrong and you should correct your code for it to work. Since then, you've changed your code and now passed the kata.
It should be less than 4 right?!
masking: '123' Log '123' None should equal '123'
idk what is wrong i get exactly the same as asked but i keep getting an error message
In almost every case, Codewars requires your function to
return
a value, notprint
it out.https://docs.codewars.com/training/troubleshooting/#.print-vs-return
Please use the
issue
flag for problems with the kata itself, not problems you're having solving it. If you want to ask a question about solving the kata you should use thequestion
flag.it works for me but this error appear : should work for random examples expected 'o' to equal 'swo' it is the case where the result have to be masked , what is this error!???
Add this test to sample tests:
Your code returns
'o'
instead of'swo'
.how would i do this. Im new to this, and i dont know how to implement the examples.
https://docs.codewars.com/getting-started/solving-kata
Ruby, detected by the post from
amedeomajer
below: tests are susceptible to input mutation.This comment has been hidden.
Already fixed it.
the expected result for the last test is wrong, the fourth to last number is always different than the input one.
example: cc = "65473632678289" expented output = "##########4289"
That's because strings are mutable in Ruby, and you're mutating the input, changing the expected value. Now it doesn't happen anymore, but you should fix your code to make it work.
This comment has been hidden.
You need to declare your two variables
lastFourDigits
andoutput
inside yourmaskify
function, because if you declare them outside your function, as static, they will keep their values and will not reset to empty strings(""
) for every new test.This comment has been hidden.
This comment has been hidden.
Not a kata issue. Your mask is longer than it should be.
solution.ts:3:50 - error TS2550: Property 'replaceAll' does not exist on type 'string'. Do you need to change your target library? Try changing the
lib
compiler option to 'esnext' or later.why?
strings are immutable
I have a problem I don´t understand. my code runs perfectly on VS, ive already tried it with many samples including from CodeWars but I get errors whrn I test it here but i get no errors when tested on VS. If anyone could help please. I used Regex
Check again what you're returning, it's the input value, not the value you got after some code. Then check the second sample test, your code won't work with it.
thanks for the reply, the problem was in the return value.
This comment has been hidden.
Hi,
Not an issue a question.
Cheers
nice job making something applicable to the real world for beginners
TypeScript Translation
Approved.
It looks like there are errors in the sudevars service. Why does it not accept the code, although it works in another interpreter.
Traceback (most recent call last): File "/workspace/default/tests.py", line 1, in from solution import maskify File "/workspace/default/solution.py", line 1, in a = [i for i in input()] ^^^^^^^ EOFError: EOF when reading a line
Because the code is not correct.
Please see https://docs.codewars.com/training/training-example
Just spent minute to make sure that there is all nananana in batman song.
Nice Task !! Here How i did it (Am looking for some advices for making fast or other methodes )
In some random tests there is " or \ or ' in the string. Is it on purpose? If it is \ or other special sign in the test string, it completly destroys program.
(C) it's not a kata issue, but it's true that unescaped
\
and"
can look confusing in the assertion messages; i removed these from the RNGWell, the given task has a strange description. It's ask you to make the code that covers all the characters in the string to # except the last 4. So when I did it, I failed tests where some blank spaces were changed to # as the task description says, because in these tests they should stay blank, what the heck?
It took me so long to realize that they were giving me an EMPTY string. I'm a beginner so I thought I must have been doing something wrong when indexing the string. Maybe they should warn you that empty strings are a possibility?
it is already part of the example test
I finally got it to work. I kept getting "error unreachable". I commented out the "throw" statement
This comment has been hidden.
Please read this: https://docs.codewars.com/training/troubleshooting/#post-discourse
Your code is failing the second sample test.
hey eveyone! When I test my solution the result is the same as it was supposed to be, but it keep showing error message. Exemple: My solution: '############5616' Message from codewars: expected undefined to equal '############5616' Does anyone know how can I solve this problem?
Hey @Priipc and welcome to Codewars! It seems you are working in JavaScript; the error message should be interpreted as:
"Expected: What Your Code Returned to equal: The correct answer"
So here, it is your solution that is returning
undefined
while the correct kata answer is'############5616'
.Make sure that you are returning your solution, not just logging it to console? You may also find these starter documents useful:
https://docs.codewars.com/getting-started/solving-kata
https://docs.codewars.com/training/troubleshooting/
I agree with you Benjaminz White, I also had the same issue, not until I came across your comment. Thanks, and keep up the good work.
I think it will be better to add more tests for different argument types.
No, thanks.
c#. my program works in vscode but test gives error(The name 'Kata' does not exist in the current context, kata - name of default class. i tried to rename it but it didnt work) what the problem ? help please
i am doing this in python, really confused, new to coding, any tips? so very confused...╰(°▽°)╯
This comment has been hidden.
Hello :)
I managed to solve this problem in Java in more than one way in intelliJ, but here I have errors. Like: "error: unreachable statement String newString = null;"
I don't understand why... Thanks :)
Hello :) just a little remark : if you really test a type number, it will crash. Example:
Test.assertEquals(maskify(12345), '#2345');
You have to foresee this case in the final tests ;)
kata hint != kata suggestion
maskify takes string.
loved it!
did not anybody solve that with the replace() function?
This comment has been hidden.
hello team replace all function is not workig may be u can use the latest versions
It requires Node v15 and it isn't implemented in CW right now.
What about strings of 4 characters? How should I deal with them? Should I convert the entire string, or not convert it at all?
All but last four, if it has four or less you don't mask it. It's a question, not a suggestion.
This comment has been hidden.
No, your code is wrong and it fails with some input values (not with that one). Not a kata issue.
Scala translation
Approved by som1
very beginner friendly!
D translation
Approved!
For my first time coding, I consider it great for practicing your logic.
Challenge description is stupid. You can't get instantly the fact that you have to replace all the symbols for # except the last four
Nah, I understood the task perfectly fine..
This comment has been hidden.
Your code fails with inputs from 5 to 8 chars, figure out why now.
There is definitely an error on attempts. The test brings diferent results than what the code is expected to do. Example: "'####m>#b' should be equal '####m> b'" and the fact is, my code does returns '####m> b'.
What language?
No, your code is wrong, see the input of the failed tests and figure out why. Not a kata issue.
This comment has been hidden.
Please don't post solutions in the Discourse page. Solutions need to be submitted, then they appear on the Solutions page, it's their place. Whenever you post code somewhere however, please use the spoiler flag so that users who didn't solve the kata cannot see it.
@LaideLawal I have a question, why you put "/./g", after that .replace(). I mean what is the meaning
This comment has been hidden.
Look at other solutions in Solutions section.
This comment has been hidden.
The expression in the
if
is incorrect.In the future, please mark your comment as a spoiler if it contains code.
Yes thank you, I fixed it now.
Thanks for the heads up.
This comment has been hidden.
You don't print the output, you return it
I think this test is broken. I got the it right but the it says otherwise :( Sample tests - masking: ' ' - Log ' ' - None should equal ' '
You need to return the value, not print.
thanks, my bad
The JS Array method replaceAll() is not being recognized by Node, for some reason.
Some reason
This comment has been hidden.
It does not. Take a closer look at the assertion message.
in the output i get this expected '############5616 ' to equal '############5616', so these are not equal?
No, they are not.
Thanks, now I saw the problem, this " " shoult be this ""; Thank you again both!
This comment has been hidden.
Your solution is incorrect. Did you try examples from description in VSC or browser console?
oh, sorry i missed ) in the end. Yes, i tried and in VSC and browser.
What does your solution return locally for
maskify("123")
then?wow, realy, its wrong) thank you man
COBOL translation (author is inactive).
Can't approve because description changed. I corrected and also slightly changed the description and create fork.
Thanks!
This comment has been hidden.
Please read this paragraph: https://docs.codewars.com/training/troubleshooting#post-discourse Please read this paragraph: https://docs.codewars.com/training/troubleshooting#expected-the-same
why?
By reading the first paragraph, you will find out what you did wrong when posting your code here. By reading the second paragraph, you will find a hint (in the fourth bullet point of the paragraph) which addresses exactly your problem and tells you why your code does not work.
thanks. I understood the rules. But I didn't know why code was not correct.
Also, you should use the function's argument, not a fixed value.
the random tests throw errors like:
"expected 'u' to equal 'bzu'"
"expected 'e' to equal '7ue'"
Yes, such things happen when your solution returns incorrect answers.
For strings under 5 characters, nothing should be censored. It looks like that your solution fails on those inputs
i've got it working now-- afaict, the problem only existed for strings that were exactly 2 characters; does anyone know why that might be the case?
Without seeing the pre-fixed code, I can't tell
I'm getting an unreachable statement on the first line of my code and I can't figure out why.
Which language? We can't see your code either, please read this: https://docs.codewars.com/training/troubleshooting
Without knowing what language you're coding in, or seeing your code, there is no way anyone can help you. You could pop by the Discord to have someone help you.
Unreachable code is generally a warning rather than an error and usually involves badly formed conditional statements or statements that follow a guaranteed return of a function, for example.
This comment has been hidden.
Your solution works only for input
'ggggggggggggggmymy'
. What if tests call your function with anything else, for examplemaskify('1234567890')
?You have error in youre test. "expected '##m6x' to equal 'm6x'" if you pass ##m6x you have to receive ##m6x not m6x. Occordint to legend we dont wipe characters equil to mask.
Your function returned
'##m6x'
instead of'm6x'
the input was'm6x'
, the problem is in your code, the tests are fine.This comment has been hidden.
Not a kata suggestion, please, don't post solutions in Discourse.
i don't get how y == 'e67' normal test's pass but this i don't get
You're doing or reading something wrong, read this: https://docs.codewars.com/training/troubleshooting/#print-input The tests are fine.
This comment has been hidden.
Use
console.log(cc)
and analyze why your code fails.got the error thanks for the tip
Can't understand what is wrong with this error "expected 'y' to equal 'e6y'". Normal test passed, but full test has mistake. If I put 'y' I must return the same 'y'. What wrong?
In that error message
'y'
is what your function returned, not the input value, to see what it is, print it: https://docs.codewars.com/training/troubleshooting#print-inputThis comment has been hidden.
It's because you're adding an extra # when input is of length 4. It should stay the same in that case.
Really! I didn't read the condition for length 4 carefully. Thank you very much!
how to put a string list on one line, help me
???
This comment has been hidden.
This comment has been hidden.
Please use Solutions section to discuss your solution, there you can see other solutions, some like yours, some completely different.
This comment has been hidden.
It probably means you return nothing. You must return the result and not print it. You may find some helpdul resources there: https://docs.codewars.com/training/troubleshooting/
ty very much
This comment has been hidden.
This comment has been hidden.
Perl translation kumited
This comment has been hidden.
Read this: https://docs.codewars.com/training/troubleshooting#expected-the-same
I guess your answer are above, it will be good u keep a look·
But i guess you need to change your final "console.log" for a "return"
This comment has been hidden.
Your code is wrong, not a kata issue.
The initial code only has one argument. Please read this: https://docs.codewars.com/training/troubleshooting/
This comment has been hidden.
Please don't post solutions in Discourse.
This comment has been hidden.
I see you're new, but what didn't you get of "Please don't post solutions in Discourse." ?
This comment has been hidden.
Please read this paragraph: https://docs.codewars.com/training/troubleshooting#post-discourse
Set
11
as the Java's version.This comment has been hidden.
brother,is this the problem of kata..bcoz when i run the code in my preferable compiler i'm getting the expected output in the console..ple reply!!
pbharish are you using Java or Python?, please read this: https://docs.codewars.com/training/troubleshooting
Yes this is the kata problem. that's where I typically get my output in.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
Read this: https://docs.codewars.com/training/troubleshooting/#expected-the-same
There is another problem with your code too. Check which tests your code doesn't pass and fix it.
You should check the string first if it's length is greater than 4,and then you can write the algorithm, it will run
This comment has been hidden.
Not a kata issue, you're using a fixed value
a
and that should depend on the value passed to your function.MY FIRST KATA!!!
Add the null case to your test code. Otherwise you teach how to write bad code.
C translation (author inactive)
Approved :)
This comment has been hidden.
Please read this: https://docs.codewars.com/training/troubleshooting/
Not a kata issue, check which input makes your code fail.
This comment has been hidden.
Giving away full solution isn't helping.
padstart it!
This comment has been hidden.
This comment has been hidden.
Please read this: https://docs.codewars.com/training/troubleshooting/#post-discourse , Especially the third bullet point of this paragraph.
Guys, be aware that codewars.com does not recognize .Allreplace-method though it does exist https://developer.mozilla.org/ru/docs/Web/JavaScript/Reference/Global_Objects/String/replaceAll
And on that site, do you see the number next to node version? That's 15, CodeWars doesn't support that version (yet). Node v12 is the latest ATM. (only v10 enabled for this kata)
ok. Thank You.
This comment has been hidden.
not an issue
This comment has been hidden.
Firstly remove pass. it's only used when we need a statement, but don't want to put code, like for Java, we'd have to put some filler command like "System.out.print("");" in that function as it can't be empty.
Moving onto the question, since you're already reducing the length you need to act on ( for example, if your string is 'hello', then "len(string)-4" will imply, you'll just read 'h' ), so you don't need to use if-else. Finally, you need to RETURN the encoded sting instead of printing it, so you'll have to convert that list back to a string.
I used the following code to do that:
codedstring = "".join(map(str, cc)
return codedstring
Also, in your function body use another variable name like "cc_new" instead of "cc" but that's just my opinion.( cc_new = list(cc) )
This comment has been hidden.
Read this: https://docs.codewars.com/training/troubleshooting/#expected-the-same
Well i'll go wait in the car... Thanks for this. After reading over the docs I realized I was "printing" rather than "returning". DoH!
This comment has been hidden.
This comment has been hidden.
There's solutions tab for that, this is offtopic. Also, spoiler flag!
Ooops , sorry for that still not too familiar with the site, should i delete this one?
This comment has been hidden.
Python new test framework should be used (Refer this & this for more detail)
Ruby 3.0 should be enabled (Refer this & this for more detail)
Fork for Python
Done for Ruby
Getting error on char[] declaration. ./src/main/java/Maskify.java:6: error: unreachable statement char[] input= new char[str.length()]; Works fine in elcipse. Any thoughts?
This comment has been hidden.
Please don't post solutions on the discourse page.
Your solution is supposed to go into the training page
This comment has been hidden.
Julia translation
Self-approved!
Why is there one fixed test with a Char instead of a String?..
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
kata solution != kata suggestion
In Rust, types str and String are Unicode strings, with varialbe sized chars, so you can't index into them or easily determine their length in chars or graphemes. The len() method is the length in bytes. The only way to reliably process a Unicode string is to iterate from the start. All the solutions to this in Rust which make use of len() are vulnerable to Unicode strings with multibyte chars.
expected:<############[]5616> but was:<############[####]5616>
I get this error but when tested on my own system do not get that [####] weird one... not sure what is going on there...
Basically the square brackets are JUnit's way to tell you where two values differ, and they are not a part of the actual value. The
expected:<############[]5616> but was:<############[####]5616>
means that the actual value (returned by you) has####
where expected value should not have it.Hello all,
Im coding with js, and str.lenght always returns undefined. Does anyone know why this is so?
It should be spelled "length" and not "lenght".
OMG, im gonna cry. Tnx m8
This comment has been hidden.
This comment has been hidden.
Hi, All of my tests were fine except one: expected:<[X]g-j> but was:<[#]g-j> I do not understand it because I did what the instruction said and I did not find anythig like that.
That string has 4 characters, you should leave it as it is, your code changed the
X
for a#
.Ok, I got it and it is fixed. I think it was the full moon and the front.
Hello! This one gives errors when using String. Example: String result; // gives error Example: string result; // works fine
Swift translation updated. Please, review and approve :)
This comment has been hidden.
consider the string: a_string="NgBANAN"
if you want to print(not only print but also yoy can save the out put in a variable)first letter of the string you need: print(a_string[0]) because the first letter has '0' index no in the string.So, the no within the "[]" imply the index no or the range of index no(better known as 'index slicing).Suppose you want to print 3rd to last letter of that string, you need: print(a_string[2:7]).so the ':' sign within the "[]" bracket indicate print the string from index 2 to 7( but not including the index 7, as you can see there is no index 7 item.It's also the best practices to write it a_string[2:0] or a_string[2:])
hope this will help you.
Question answered & user solved this kata
Help, Python bites! I don't understand why this error prevents me from typing "input" into my code, for example: "a = input()" I just catch this error : Traceback (most recent call last): File "main.py", line 4, in r = maskify(cc) File "/home/codewarrior/solution.py", line 2, in maskify a=input() EOFError: EOF when reading a line
Why you are using
input()
?There is no need for using
input
because you are passed a string value. You can see the input by printing it as shown here:I want the code to be automated and it was possible to check the code not only on the data that is offered,I want the code to be automated and it was possible to check the code not only on the data that is offered. Although I tried to give variables data for tests, but something went wrong
Thanks rowcased
May the Lord bless you! May strength and blessing be with you, thank you again rowcased for saving me from suffering because of my stupidity
You are very welcome, but please do not feel so bad about not knowing what to do. For example, in the very first week I studied coding, I began to wonder as to whether functions could give out any useful information, meaning: I still didn't know about the
return
statement. Imagine that!If I dont use the input, what will be the value of cc? I try to delete the cc = input(...), but shows that I didnt pass the cc value.
cc is the function's argument, the value passed to it is in there.
This comment has been hidden.
This comment has been hidden.
Where are you returning the result? Are you even using the given function argument?
Actually, where is your function defined? Look at initial code and complete given function.
"Usually when you buy something, you're asked whether your credit card number, phone number or answer to your most secret question is still correct. However, since someone could look over your shoulder, you don't want that shown on your screen. Instead, we mask it.
Your task is to write a function maskify, which changes all but the last four characters into '#'. - it's task and the code returns the correct answer, but program say...
Time: 727msErrors: 1Exit Code: 1
/home/codewarrior/test.coffee:6:26: error: unexpected ] mastify4=(mastify[-4:])
Wait, you're using coffeescript now?
There is no function named 'maskify' in the code you posted.
Hi , thank you for the great page , but im masking the numbers correctly, it shows me the log is whats expected , but it says its failed? I dont get it? Please clarify data type... but its obviously string... It looks solved on my part.
Read this: https://github.com/codewars/codewars.com/wiki/Troubleshooting-your-solution are you printing or returning the result?
/printing the reuslt
This comment has been hidden.
Please don't post solutions in Discourse: https://github.com/codewars/codewars.com/wiki/Troubleshooting-your-solution#post-discourse
This comment has been hidden.
This comment has been hidden.
Does anyone have issue with JavaScript?
I pass all three tests, but only about 25 of the 100 attempts. There has to be some kind of error.
Yes, and it is in your code, read this: https://github.com/codewars/codewars.com/wiki/Troubleshooting-your-solution
This comment has been hidden.
Racket translation
Rejected, see remark in translation
how can i see what output my code is giving and not just that it doesnt work?
Printing the output before returning it.
This comment has been hidden.
Please don't post solutions in Discourse, it's forbidden.
Ah, ok, thanks for the heads up I won't do it again ... can we ask for help on code that isn't a solution yet?
yes
This comment has been hidden.
This comment has been hidden.
TypeError: string indices must be integers. That's up to you to figure out what this means (search engines are there for this). The errors are very visible to you too.
Edit: 'abc'['1'] is not valid in python.
I finished the kata well but it cost me and my solution was far from efficient. They are great to see the solutions of three lines of code of some warriors.
What makes you think that solution of three lines of code is efficient? :)
Haha, my solution was only one short line but unfortunately grouped with an ugly 7 lines long broken lambda function, but that is a joke, so it was funny to see when I have solved the kata :D
I don't know, maybe because it cost me more than I imagined and seeing those solutions left me knocked out. Anyway, it's my mistake to see it that way haha
This comment has been hidden.
This comment has been hidden.
Please don't post solutions in Discourse.
This comment has been hidden.
Read this
I've copied and pasted your code and it worked, what's the error you get?
My bad! This is my first Kata, so, instead of returning the new string, I printed it because I didn't know how was the output be like. I put the return in my post just to show a cleaner code. Sorry and thanks!
This comment has been hidden.
Please, don't posts your solutions in Discourse. You can make those comments under your solution in Solutions, and mark your post as having spoiler content, even there.
OH sorry about, that, i'm new here, i'll remove the post and move it to solutions.
Edit: Well i can't see how i can delete my comment, or even how to edit it. So if an admin can just delete it if it doesn't belong here, that woudl be fine by me.
I have a question, I think i understand everything up to this point
string masked = lastFour.PadLeft(charcount, '#');
and lets see as an example the input is 10000
masked ends up equaling 1####
but lastFour = 0000 and charcount = 5,
so i don't see how masked knows about the "1"
any clairification would help! Thanks for you sharing your solution
This comment has been hidden.
Check this: https://github.com/codewars/codewars.com/wiki/Troubleshooting-your-solution
This comment has been hidden.
Nice fun Kata. Thanks!
This comment has been hidden.
Please don't post solutions in Discourse.
Why doesn't replaceAll() work here?
Well strange, it works for me in my Java solution...
But if you mean why
replaceAll
does not work in CodeWars JavaScript runner, then it's because CW uses Node v10 as JS runtime.For java solutions, replaceAll() doesn´t satisfy all test scenarios, mainly because replaceAll expects a regular expression as its first parameter. Therefore inputs like "<[7/f* +]|3>H" wont work as expected. Because it resolves intoa regular expression.
Another posibility is to use str.replace(charSequence, str)
hi need help here this is what the final test before submission outputs
Expected: "############5616", instead got: "455636460793"
. why is the expected number am getting as an input different than the on am expected to output.Print the input (neither of those two values is the input, the first is the expected one and the other is what your function returned), your function returned the first 12 digits instead of masking them and leaving the last 4 digits unmasked.
This comment has been hidden.
Not a kata issue, it's a problem with your code:
cc[0 : -4 , 1]
-4,1
isn't an integerThis comment has been hidden.
Not a kata suggestion. Please, don't post solutions in Discourse, there is a Solutions section where you can discuss this.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
You should read how
str.replace
works.cc.replace(x, "#", len(cc) - 4)
doesn't replace firstlen(cc) - 4
characters of the input string with"#"
.it also fails because youre using a
return
statement within a for loop, no matter where its at, once a funciton hits a return, it will leave the function.This comment has been hidden.
PHP translation added
This comment has been hidden.
Please, mark your post as having spoiler content next time. Check the description examples again, and check what your code is doing, there is no guarantee, cc.Length will be greater then 4.
Ok, thanks a lot, I've understood!
The code I've written worls perfectly on my IDE but here I get the error, "String index out of range: -3"
Output from my IDE for Reference -- Enter String : nananananananan Batman! ###################man!
Could you share more information about your issue? Info like used language and version is helpfull to simulate your situation.
Nobody told you the string's length will be always greater than 4, it's a problem with your code, check the description examples.
This comment has been hidden.
Not a kata issue, your functions should return in CW, not print the result. Also, you don't need the additional quotes, return the string only.
This comment has been hidden.
Your functions should return in CW, not print, use Question next time as this is a problem with your code and not with the kata, take a look at how many solutions there already are for Python. Return only the masked string.
Thank you, sorry for my incompetence.
I didn't mean it like that, don't you feel bad. I was just summarizing the things you should be sure of before creating an issue. There is no tutorial for new CW users sadly.
I didn't mean it like that either, i have a habit of not think about stuff before doing it.I appreciate your help and your advise. :-D
This comment has been hidden.
Check your first if, typo in
length
.Fuck me... tnx
Is python3 disabled for anyone else?
Yes, but I enabled it, so it'll be fine now.
Its back, thanks.
Is java broken?
No, why do you ask?
Sorry, no problem. I just realized repeat() doesn't work on java 8.
Solved then.
This comment has been hidden.
This comment has been hidden.
Happy days. Being a rookie I made a simple error which slowed me down, but I came through and learned a few things in the process.
Given the nature of the problem (and the description), one would expect only integers as input but test cases does not take that into account. Several solutions here expects a string input and would fail on an actual CC number.
How is "SF$SDfgsd2eA" a valid CC number again?.. Wouldnt it actually be a good idea to fail on that input and throw an error to be handled?
This comment has been hidden.
This comment has been hidden.
You create a copy of the initial string and store them in intermediate variables, then u return the origianl string which changes nothing.
what the fuck?? submit button's missing!!!
Try changing browser zoom level.
my code ran fined in pycharm. tested it on kata, it was falsely executed. My answers seemed to be mixed up. '1' return '22' '22' return '333' '333' return '4444' '4444' return'####3700' ect.
Ruby question. I set up the first method to except out the last 4 digits and the second method to "x" out the other digits of the card. The code I wrote tested fine except I kept getting an "unexpected "end" code on line 5"?! There was no code on line 5 first of all, and second of all, that was the line b/w the first method and the second method. This has been hugely disappointing b/c this is my first attempt on this tutorial site which my instructor highly recommended. :(
Why are the Expected and Actual flipped???!
State the language (there are a lot of them and we shouldn't be guessing). Fixed Python.
This comment has been hidden.
Actual and expected were flipped in Python (solved it a while ago), C# and Java. Fixed all of them, if there is any other language that has the same problem, let me know.
This comment has been hidden.
Paste your code and mark your post as having spoiler content.
C# is broken, according to comments this has been broken for over 3 years, I have no idea why this is still on here. I wonder how many other problems I did not complete have been bugged too. I figured it was broken out after 25 minutes, time I will never get back. This has been reported as broken since 2015, site mods need to be more vigilant.
C# isn't broken, it had actual and expected flipped (and you could have seen that in the responses to those posts too). It wasn't possible until recently to fix that once it was solved more than 500 times. I've fixed it now, you're welcome (I'm not a moderator by the way, just a user with access to fix things like this).
it is showing me an error
all my tests are clear i am ready for final submit and suddenly the button dissapears. and there is a message correct! refactor/comment your solution and submit
When I annotated a word "throw new UnsupportedOperationException("Unimplemented");" ,this programmer is run properly.
So... kata-question want me to replace all digits with # except for last 4. WHY THE HELL it show this as an error?! '########d2eA' should equal '#F$#Dfgsd2eA' Even so, how the hell i am going to do that? Like: Here is the random-placed-digits, but we are going to mask them right away without letting you know the original version, try to understand what are those masked ones, good luck!
Actual and expected are flipped in Python (not fixable for the time being), so it's your code what's returning the wrong value. You can check the original string printing the input value.
Fixed.
This comment has been hidden.
expected:<[[#, #, #, #, #, #, #, #, #, #, #, #, 5, 6, 1, 6]]> but was:<[############5616]> please help me with this.
By the sounds of it, expected and actual were flipped
This comment has been hidden.
This comment has been hidden.
Hi,
you wrote
This code works well on my local machine, but it is showing some error here.
.Then compare the code on your local machine with the code you have posted.
int or var
For the first kata it's a pretty terrible welcome.
But its not even the first kata though
Python test broken '######3700' should equal '####303700'
I'd suggest that two test cases are added, one where the input argument (cc) is null and where the input argument (cc) is string.Empty;
This comment has been hidden.
The expected and actual are swapped around, so you are returning an array and you need to return a string. You should use the
join
method to convert the array to a string.C# Tests are broken: index 4 Expected: "####95162398" But was: "########3640"
My Python code is passing all tests, but giving an error:
Paste your solution here and mark it as a spoiler.
This comment has been hidden.
This comment has been hidden.
Python test is broken, error comes from the tests itself.
This comment has been hidden.
It worked for me. What error do you see?
stupid test
it's a good test,i can't find a better way to solve this.
This comment has been hidden.
I am also getting the same error.
Which language?
In my case, C#
I think the tester for Javascript is totally broken. I took a screenshot and the results matched the expected... but they still counted the tests as failed attempts.
HI i am new to CW, am getting this error
Test Results: masking: matches None '' should equal None
Can some one help me to solve the issue....?? And i am running my code in another compiler its running fine, but in CW i am getting the above error.
And one more thing is the "" to the output necessory????
The expected and the actual messages are swapped around. So your code is returning None whilst the expected answer is "".
None
is the default value when nothing is returned from the function - you either printed it to the console instead of returning it, or you didn't make a separate case for the input.I feel the empty string ("") is necessary since if the input is a string, the output should also be a string. If an empty string is passed as an input, the output should be the same because it shouldn't be modified in anyway - it is still a string.
This comment has been hidden.
1.) Return the final output, don't print it to the console.
2.) Your print statement was incorrect anyway, you can't have two separate print statements connected by an if statement. You would have to remove the second print, so that the first print contains the 'if' ternary statement.
3.) You don't have to manually call the function because testcases do it for you.
4.) This is not a suggestion, but a question.
Python version is broken : ######3700 matches 3656013700 '######3700' should equal '3656013700'
The expected and the actual are swapped around, so the expected is '######3700' and your code is returning '3656013700'.
This is proven if you put "return True" in the code, where it will say that the expected is 'True' when it isn't.
I pass 5 tests in the python version but get the 'TypeError: expected a character buffer object'. Can someone help me out?
Python tests are broken: '########d2eA' should equal 'SF$SDfgsd2eA'
The expected and the actual are swapped around, so the expected is '########d2eA' and your code is returning 'SF$SDfgsd2eA'.
This is proven if you put "return True" in the code, where it will say that the expected is 'True' when it isn't.
Fixed.
Okay kata is not broken in C# although the Expected is swapped with Actual and it confuses a lot. If someone know how to fix it I would be glad :)
Fixed.
it keeps showing should equal none no matter what, i tested the problem offline and works 100% as described, i´m using python
return
it instead of usingprint
.