6 kyu
Create Phone Number
127,856 of 352,551xDranik
Loading description...
Arrays
Strings
Regular Expressions
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.
I pass the challenge! I'll just leave a hint: Please, use the string format class 💪🏽
This comment has been hidden.
y se supone que es nivel novato porque sin anestecia ponen un problema de funciones?
This comment has been hidden.
I happy to join code wars!
This comment has been hidden.
This comment has been hidden.
This code is mostly correct. You are using a template string in your return value, and template strings will create exactly what you write in them... so your current return value includes extra quotation marks, extra spaces, and even linebreaks. So, for example, if the correct return value is
(123) 456-7890
, your function is returning the following (I'm using underscores to show spaces here, your return value does not contain underscores, they are spaces in your return value):As a further note, you don't need to call the function yourself at the end of the code, the tests will do that for you. In this case, it doesn't matter that you call it yourself, though.
thank u i see it
This comment has been hidden.
check to make your comments readable: https://docs.codewars.com/references/markdown
This comment has been hidden.
Read this: https://docs.codewars.com/training/troubleshooting/#expected-the-same
there is broken encoding in C version of
Can you explain how it is broken or provide an example ? I don't see any error.
The C tests seem fine. Without more information, I'm going to close this issue.
OP had an off-by-one error in their
for
loop: loop counteri
goes to14
but thepattern
variable has14
characters, so the last iteration accessesphnum
out-of-boundsThis comment has been hidden.
Kata hint != kata suggestion, resolving.
This comment has been hidden.
Comment deleted, resolving this.
This comment has been hidden.
you forgot to close the quote sign at the end of the return statement
For the inclusiveness and self-awareness (and professionalism), this kata should specify that the phone number format being used is the North American Numbering Plan https://en.wikipedia.org/wiki/North_American_Numbering_Plan
This comment has been hidden.
This comment has been hidden.
if you don't know why your code does not work, it is not a kata
issue
. instead, post as aquestion
https://stackoverflow.com/questions/9050355/using-quotation-marks-inside-quotation-marks
https://pythontwist.com/mastering-nested-quotation-marks-in-python
https://thewebdev.info/2021/10/23/how-to-use-quotation-marks-inside-quotation-marks-with-python/
This doesn't explain how to make a number.
.concat() in a "for of". convert in toString() the key value. After replace a mask (***) -*. this is resolution.
WHERE ARE THE SOLUTIONS?????
Im getting this error.
`createPhoneNumber': wrong number of arguments (given 0, expected 1) (ArgumentError)
not a kata issue, works fine in ruby, and you have passed the kata anyway
This comment has been hidden.
BF:
'\u0000'
(charcode 0) isn't the same as the character'0'
(charcode 48). Can you find a way to map charcodes 0 - 9 to the actual characters'0'
-'9'
?(Not a kata issue by the way)
How is this a 6 kyu? More like a 7 kyu to me.
скорее даже 8 так как на синтаксисе js это почти базовая задача
=)))
100 %
why i cant use the class Arrays?
Because you need to import the needed library.
you don't need to use an array base here
am return (123) 456-7890 to func is fixed noop testing
get error None should equal '(123) 456-7890' works in vscode tho
Your code doesn't return the result, it just prints it. Not a kata issue. Please read troubleshooting section.
"Write a function that accepts an array of 10 integers" "Write a function that accepts an list* of 10 integers"
The description is shared amongst all languages, in Python the input is a list, yes. But generally they are called arrays in other languages so...
This comment has been hidden.
Don't post solutions in discourse please
kata solution != kata suggestion
i pressed this damn discuss button and it deleted my code
It didn't - it's still there in "Past Solutions", when you go back to the task.
It only shows up in "Past solutions" if you already hit Attempt and it was successfully passed all the tests.
However, you only need to press test/attempt button and your code will be saved locally when you enter the trainer again. If you don't, and navigate elsewhere, your code gets lost.
algém poderia me ajudar sou iniciante , mas estou tendo muita dificuldade não sei como começar todos desafios mesmo os de nivel iniciante são muito dificeis para mim aprender a programar e o meu sonho
Que erro vc está recebendo?
can someone explain to me WHY the array of numbers to be accepted (const unsigned char nums[10]) is defined as "char" and not "int"? it take me a while to understand that it was a array of integers, not an array of chars, even if the problem said that the input were integers. why not to just declare "const unsigned int nums[10]"?
btw... i've solved in C, i forgot to said that.
It's because all values are going to be in range 0-9, so author decided that
unsigned char
is enough to represent input values.[signed/unsigned] char
does not necessarily mean a character, it can be used for small numeric values as well. Whether it's good design or not is another question. Sometimes it is, sometimes it's not.In statically typed languages like C, integer widths (
char
,short
,long
, etc.) may serve as a form of self-documenting code, by restricting the possible values a variable can take. I guess the point here was to highlight the fact that the numbers are digits, so they are small positive integers.But I agree with you that using
unsigned char
is misleading, because programmers associatechar
with textual data (andunsigned char
with binary data (bytes)).I modified the code to use
uint8_t
from<stdint.h>
instead, while keeping backwards-compatibility.thank you for your answers guys, it helped me a lot. :D
regExp <3
This comment has been hidden.
Not a kata suggestion. See https://docs.codewars.com/training/troubleshooting#post-discourse.
My code pass the first test but fail the attempt. I dont understand!!
You can refer to this documentation to help you debugging: https://docs.codewars.com/training/troubleshooting
there may be an edge case in the full test suite that you didn't account for.
This comment has been hidden.
Use this to see how they work: Pythontutor Visualize
This comment has been hidden.
Please use appropriate formatting when posting code. See https://docs.codewars.com/training/troubleshooting/#post-discourse.
Your function always returns
undefined
. See https://docs.codewars.com/training/troubleshooting/#.print-vs-return.You're also not supposed to write tests in your solution code. See https://docs.codewars.com/training/training-example/#writing-a-solution.
Not a kata issue.
This comment has been hidden.
You should only post as an
issue
when there is a provable problem with the kata code. You could instead post as aquestion
.Your code has multiple mis-matched names:
creatPhoneNunbers != createPhonenumbers != createPhoneNumbers
This comment has been hidden.
Please don't post solutions in the discourse. See https://docs.codewars.com/training/troubleshooting/#post-discourse
Not a kata suggestion.
This comment has been hidden.
Well, for starters, have you examined the error messages?
For the first test:
So, you can see that you have wrong numbers, so hopefully you can use this to debug your algo.
I read the error messages but it didn't make sense to me. Aren't I supposed to write a function that just produce random phone numbers in that specific format? How am I supposed to know what phone number is expected in each test?
Have a look at the problem description again. It says that you will be given an array of numbers that you are supposed to convert to a phone number in the format that the example show you.
Also, remember that you do not need to convert numbers to strings as this is done implicitly (if you are using c#, which it looks like you do).
I'm not sure if I was the only one, but this seemed too easy to be given 6 kyu.
EDIT:
I'm assuming that all the inputs into the function will be an array of length 10 and that it only requests the format provided in the details.
This is an old kata so ranks can't be changed
That makes sense, thanks for clarifying that
This comment has been hidden.
Hi, a
suggestion
is for how one might improve or change the kata. You should not post a solution like this, otherwise anyone can use it without solving the kata on their own. I have added the spoiler flag to your comment. Welcome to the site and happy coding!This comment has been hidden.
your code needs to return a value
This comment has been hidden.
question
instead of as asuggestion
This comment has been hidden.
You don't read the input from the keyboard here, use the function's argument. Also, your function needs to return a value, not print it to the console. Read this please: https://docs.codewars.com/training/training-example Not a kata issue.
Thank you
This comment has been hidden.
A good one!
This comment has been hidden.
This comment has been hidden.
Please don't post solutions in Discourse.
This comment has been hidden.
You can. Your problem now is related to this: https://docs.codewars.com/training/troubleshooting#expected-the-same
Thanks, fixed it and passed my first kata!
Why my output expected "expected signal: " Someone can help me? Im coding at C language
Only 12 others have finished this in BF???????
Hey I'm new. My teacher sent me this website where I could work more on anything, and functions are my biggest weakness. Just took a final exam filled with functions and I'm just worn out. I'm having trouble with this simple problem here, and I can't figure out how I would appraoch this. Can I get some assistance? Should I just assign an array to it, or do I need a for loop because loops and functions have been double teaming me lately.
A problem with your code is not a kata issue. You need to use the function's argument
numbers
, an array, to build the output string and return that. Read the docs: https://docs.codewars.com/getting-started/solving-kata and check Discord channels like this: https://discord.com/channels/846624424199061524/846628654716551198just keep at it mate you will get there. I taught myself from freecodecamp it's easy with practice
Hi, guys i was thinking of solving the challenge usinf Regex
not a kata suggestion
This comment has been hidden.
A problem with your code is not a kata issue.
It's very difficult to see what's happening with your code, because it's not formatted properly. It appears that you're never returning any value, that's why it's not correct. See https://docs.codewars.com/training/training-example
you need to return the result but not console them
This comment has been hidden.
You are returning an object instead of just the phone number. I guess you are doing something like this:
Change it to:
silly me, yes i wrote it that way... all done, kata passed successful! thanks for the help Kacarott.
I think there may be a curly brace in your output.
How can I submit my solution?
This comment has been hidden.
Read the error message:
Not a kata issue, read this: https://docs.codewars.com/training/troubleshooting/
thanks!
Text doesn't match code (speaking of int array, passing char array). Passing the int values you want to have rather their char representation is BS and just confusing.
this was way too easy to be a 6
This comment has been hidden.
This comment has been hidden.
You're printing instead of returning, more info on this here.
You should use code blocks when pasting code.
Also, consider joining the Codewars discord. There is a dedicated channel to get
#help-solve
ing kata.that would make sense. Thank you so much for your help!
I think there is different path to solve this task, at list I I did three of them. Also it is better to refactor/refine leter the end. Thanks.
The prompt isn't very clear to me, I made my string of code and it is saying to me that I can't use the input function which doesn't make sense to me...
Not a kata issue, in the whole site you never use input, you use the function's argument, please read the docs: https://docs.codewars.com/getting-started/solving-kata and https://docs.codewars.com/training/troubleshooting
Description is not clear enough what is a valid phone number?
(ddd) ddd-dddd
where d is any digit between 0 and 9.I'd guess an American one maybe?
This comment has been hidden.
Read this: https://docs.codewars.com/training/troubleshooting/#expected-the-same Not a kata issue.
Weird, but pretty cool!
Why is no one handling errors? Also, it seems to me that the tests should account for non-int inputs and where len(n) != 10, no?
This test felt too easy for a 6kyu. In my opinion it should be a 8kyu question;
Who solved it with PHP? My code work correct in PHPStorm, but test failed
You already passed, closing then. Read this too: https://docs.codewars.com/training/troubleshooting/
I see, thank you. My code was correct, a little. But I failed some tests. This kata is passed now.
This comment has been hidden.
kata hint != kata suggestion (also spoler flag plzzzz...
That space after the parentheses threw me offguard, I may still be able to solve this but wil require something evil.
This comment has been hidden.
That you're missing a number in your answer, please, don't open an issue when your code fails. Read this: https://docs.codewars.com/training/troubleshooting
apologize i am completely blind xD
How to solve this task if I don't know?
Was tough to me
This comment has been hidden.
Read this: https://docs.codewars.com/training/troubleshooting/#post-discourse it's
toString()
but there is a better way to do what you want.This comment has been hidden.
There seems to be an issue with this test.
There is no issue with the tests, your code isn't using the function's argument, so, no matter which value you call your function with, the answer will be the same.
The question did not provide any required function, parameter or argument names, so I'm not sure what you mean.
Javascript's initial code:
The function is
createPhoneNumber
and its argument isnumbers
. If you do something like this:It doesn't matter if you call your function like this:
createPhoneNumber([1, 1, 1, 1, 1, 1, 1, 1, 1, 1])
the answer will be"(123) 456-7890"
instead of"(111) 111-1111"
. And that's what's wrong with your code.This comment has been hidden.
Read this: https://docs.codewars.com/training/troubleshooting/#expected-the-same and this: https://docs.codewars.com/training/troubleshooting/#post-discourse
You're meant to return the String, not log it out into the console
Quite amazed at the sheer diversity of solutions written in rust :)
The tag Regular Expression does not fit. Please delete it.
Why? You can use regular expressions if you want, you're not forced to do it tho.
You need formatted output. Why would you use Regexp which matches patterns? I can think only using it for testing your result, which is done anyway.
Go to Solutions, see how you can use regular expressions to solve this kata. In some languages you'll find more than in others.
Oh, now I see! Yes, it makes sense to use regular expressions, in some languages more than in others. Most solutions use a regexp replace function. Even if it first seemed artificial and overly complicated to me. But in some languages it is one not so complicated way to solve the kata. The topic of the kata is conversion int -> string and formatting. Regexp can do both. So this tag is a hint of one method to solve the kata.
If I first had studied the solutions and thought about it, it wouldn't have been necessary to give my suggestion. Sorry, that I bothered you and thaks for your help. This case was quite instructive for me. CodeWars is a wonderful place to learn new ideas!
Don't worry, glad you learned something new.
I learned replace method from this kata
I don't get it. Why would it fail a test case when the answer is actually correct? I'm returning the output, not printing it
It seems you passed the kata.
This comment has been hidden.
Read this: https://docs.codewars.com/training/troubleshooting#expected-the-same
This comment has been hidden.
Please don't post solutions in Discourse.
I thought if I checked spoiler, it would hide my post.
It did, but there is no need to post solutions in Discourse, it'll clutter it in no time if everyone posted his/her solution here. You can discuss solutions in Solutions instead.
My code in C, passes all the sample tests, but when i try to attempt it with the main tests it fails. On the tests screen it says the nums array is just an array with differnet symbols and no numbers. My code is making a char array with the right format, and when it returns in the sample tests its correct. But in the main tests nothing gets returned.
you must write to the parameter
phnum
and return it, instead of allocating a string on the heapI added a note in the initial code
This comment has been hidden.
This is not a problem with the kata, but with general setup of Codewars runner. The issue has already been reported, you can see and upvote it in
codewars/runner
repository: https://github.com/codewars/runner/issues/209Resolving here, because it is not an issue strictly with this kata.
.
I wrote my code for this kata, and when I would press 'test' I would bet an error that it was expecting "}" on line 15, even though there was nothing wrong, when I pressed to continue my code was correct, so I am not sure what the issue was.
Click reset, try again, maybe you messed up the sample tests.
Exact the same problem, but with square brackets, I think is a bug!
Which language? I don't think so:
Hi,
My cod doesn't word : "EOF when reading a line" form the first line. The line is : n = int(input()).
Have you an idea ?
Error in your solution is not a kata issue.
On Codewars, you do not need to use
input
. All inputs are provided to your function as function parameters, you don;t need to read anything from users.Ok ! I got it.
Thank you for your reply.
This comment has been hidden.
my code works on pycharm but here return this error: None should equal '(123) 456-7890'
You need to return the phone number, not print it.
Not a kata issue, please read this: https://docs.codewars.com/training/troubleshooting/
This comment has been hidden.
This comment has been hidden.
Kata ranks are shared across all the programming languages; while this task is easy in Python (for example), it may be much much more difficult in another language.
Also this is a very old kata, so ranking was a bit more generous back then.
This comment has been hidden.
That your function returns a wrong answer, not a kata issue. Read this: https://docs.codewars.com/training/troubleshooting/
Your function should use the value passed in
numbers
argument, not create a random number.i dont know what to do
The description explains what you must do, and gives an example.
I thought I knew what to do, but it's not working. Perhaps that's why the kata is 6kyu, even though it seems simple.
I'm getting the same output as it wants from me but it throws an error after testing. I double checked and changed the brackets, dashline and even added the quotation marks but it still says "None should equal '(123) 456-7890' "
*Update: ah I'm sorry. It's sattled, I noticed I was printing the resault and not retruning it 🤦🏻♂️🤦🏻♂️
When i run the code in pycharm everything works fine but when I paste the same code here it doesn't work what can I do
Your code works fine, and you passed the kata.
This comment has been hidden.
RESOLVED
Found out I needed to 'return phn_num' not 'return print(phn_num)'
This comment has been hidden.
@mattdivs: Please don't post solutions in discourse.
i used all cases but my program is giving some random output. i don't understand why people are using +'0' after intializaton.
I imported random. I set up area_code and prefix to randomly take 3 string digits and line_number to take 4 string digits. I set up return to generate the numbers where they belong. I'm getting these errors: '(381) 127-4848' should equal '(123) 456-7890' '(822) 869-8435' should equal '(111) 111-1111' '(769) 704-8103' should equal '(123) 456-7890' '(702) 922-2003' should equal '(023) 056-0890' '(201) 455-5480' should equal '(000) 000-0000' How do I force my random numbers to generate their random numbers? I must be missing something.
You should use the argument of your function
n
, not create random numbers.Thank you!
D translation
expected:<([123) 456-7890]> but was:<([[123) 456-7890]]> I don't understand the square bracket error. Can anyone explain it to me please?
It's a bit confusing here because Java's test framework adds square brackets to emphasize the parts of your output that are different from the expected result, and your output contains brackets squares, while it should not.
I didn't add square brackets anywhere in my code I don't know why it is there
They come from
stringnum
;)Thank u
expected:<([436) 239-6034]> but was:<([521) 140-5843]> the numbers is expected to be random , but i cannot really understand whats problems with it
What is random is the parameters your function will receive, You must not generate random numbers, you must write a function that will handle correctly any input it will be passed.
This comment has been hidden.
Read this: https://docs.codewars.com/training/troubleshooting#.print-vs-return
Thanks!
This comment has been hidden.
you need to write a function
createPhoneNumber
, not name that as the variableThank You!
This comment has been hidden.
Your solution function is wrong, because it does not return any value.
Please see if this helps: https://docs.codewars.com/training/troubleshooting#expected-the-same
Not a kata issue, its a bug in user solution.
oh, oops. thank you!
Using my IDE and running the function it returns the correct values (123) 456-7890. But testing in kata says expected (undefinedundefinedundefined) undefinedundefinedundefined.... BBlahblah to equal expected value (123) 456-7890 SO FRAUSTRATED sigh can someone please help?
what is your code returning?
if it's
(undefinedundefinedundefined) undefinedundefinedundefined.... BBlahblah
you need to take a look at your function againAre you really testing your code with the same input (for example
[1, 2, 3, 4, 5, 6, 7, 8, 9, 0]
)? Does you IDE really use NodeJS? Which version?You are using rest parameter syntax in your function. The argument that is passed to your function is already an array, using the rest parameter will place that array into another array, so
numbers
will become a two dimensional array with only one value (That one value being the array that contains all 10 numbers). You should change your function declaration fromto
That should solve your
undefined
problem, at least.Yes was definitely using the rest syntax will check that soon.... Thanks
This comment has been hidden.
You need to add an import statement for using Arrays: import java.util.Arrays; Also there is another minor mistake: in the createPhoneNumber function you return the StringBuilder instance, not a string.
Getting this Actual: "() - " Expected: "(123) 456-7890." I tried using a different IDE and when I try testing printf("%s", phnum), I get "(123) 456-7890" so I think it's returning the string phnum correctly?
For Ruby, I'm not sure this Kata - 6 KYU, more like a 7 or 8.
For Python, I'm not sure this warrants 6 KYU, more like a 7.
Ranks can't be changed ATM
This comment has been hidden.
Going on where? What
const
? Why do you want to add 0?This comment has been hidden.
you are not supposed to modify
nums
, it is your input. you have to fillphnums
, and return itThis comment has been hidden.
please dont spoil solutions or algorithms in Discourse :(
I'm getting error Actual: "() - " Expected: "(123) 456-7890" but when put into a codespace on github and adding a print statement i get the expected answer returned.
you're probably printing the answer instead of returning it
means that your function returned
"() - "
when the answer is"(123) 456-7890"
My code works when I run it through my own python notebook, but not when tested through codewars. I'm not using any special packages or anything, but where I get phone numbers, codewars gets 'None'.
Read this: https://docs.codewars.com/training/troubleshooting#works-but-no and this: https://docs.codewars.com/training/troubleshooting#expected-the-same
why a ternary operator not accepted?
This comment has been hidden.
lol people complaining this kata should be 8 but I'm dying over here make it 1
A good assignment. I used the slice() method to take a specific part of the array. Presented it as a string using join(). I wrapped the brackets in quotation marks and folded everything. Don't forget to add a space in quotes.
This comment has been hidden.
Don't include brackets in your output.
Используй: "".join(n[:3])
This comment has been hidden.
This isn't a kata issue, it's a problem with your code. In your pc, the input is a number, here it is an array of numbers. Please read this: https://docs.codewars.com/training/troubleshooting
U're damn right, thanks bro!
I thought we should at least validate the array length and if its elements were Integers, as well as if the numbers inside it were indeed between 0 and 9 and lastly return a string. Most ppl simply returned a string without any validation. Isn't that cheating?
This is doable without any kind of loop....
How would not having a loop account for different input?
Why isn't this 8 kyu?
Because this is one of the oldest kata in Codewars and back in 2013 there were completely different measures for difficulty. And reranking kata is not a trivial process at all and generates high load on the servers.
Man didnt realize that i knew nothing about const keyword. spent most of the time figuring out why I couldnt iterate through it or assign it to a string variable. xD
This must be my problem, and I can't figure it out.... I've Googled everything I can think of on this, but can't find what I'm doing wrong. Any tips on what you looked for?
So const is a way of making an variable read only. Now let's look at the = sign, this can be called "is" as its an assignment operator. so if you tried dog = cat then your saying dog IS cat assigning it to cat. now if cat is const then this is doesnt work. but what if we said dog = dog plus cat. were not directly assigning it, were only accessing the value to modify another. I hope this helps and I haven't made it more confusing and good luck.
this IDE is so fucking bad holy fuck. also I can't use the std::string append function? no string.append? fix your site please
It's not an IDE but just a text editor with code highlight. If you want IDE support, you can solve the kata in your local IDE and copy the solution over into the trainer when you are finished.
append
is avaliable as usual and if you can't use it you have done something wrong or use a C++20 feature but we can't tell without seeing at least the error message.Is this testing algo wrong? my solution works on my IDE...
You need to make sure you use "return" not "print"
i am gettings this what is wrong expected ''(123) 456-7890'' to equal '(123) 456-7890'
You forgot put the space.
thanks!
Hola alguien sabe como puedo poner la pagina en español es que no entiendo ? :>
Hola, la verdad no sé cómo se pone la página en español, pero si querés te puedo ayudar a entender lo que dice el kata
No se puede. Esta web está toda en inglés exclusivamente. Si vas al Discord me puedes pedir ayuda en mensaje privado, a menudo me podrás encontrar allá, y aunque no se me vea conectado, debería de contestarte en menos de un día (uso el mismo seudónimo).
Lo que puedes hacer es añadir una extension a tu navegador para que traduzca la página si estas en Firefox en Chrome ya lo tiene por defecto solo buscalo
Si estas en google chrome, das clic derecho sobre la pantalla y dice traducir al español.
Damn, Learning two languages at once. Pro
This comment has been hidden.
This comment has been hidden.
You should
return
the result notprint()
e.greturn phone_number_format
For troubleshooting your problem
Thanks
I realy don't understand what i should do, anyone to help
you need to return a string of 10 numbers (which is given to you as an array) in the form of a phone number
Traceback (most recent call last): File "main.py", line 2, in import codewars_test as test ModuleNotFoundError: No module named 'codewars_test'
Can someone help?
select Python 3.8, if you don't see
import codewars_test as test
as the first line in the test suite, copy/save your code & click resetit's working :D thanks
Hi, can someone explain why there is * before n? (*n) couldn't find relevant examples, and I want to understand what it means thanks
COBOL translation (author inactive).
approved
Should this be a 6kyu? I feel like it was a 7 or 8.
The rank of a kata is set according to the votes of the ones who solved in when it was in beta. Then it cannot be changed. Old katas tend to be overranked, it's rather the contrary on newer ones. Moreover, consider kyus are shared across languages and there may be great variation of difficulty between them. Many discourse pages are full of comments saying the kata should be one kyu above or below. They are useless.
This comment has been hidden.
Please don't post solutions in Discourse.
I dont understand. I get this error: '(111) 111-1110' should equal '(111) 111-1111' Why should the last 0 be turned into a 1?
Print the input.
Seem like we are not doing the same challenge on a same discussion board
Bhery Easy!!
This comment has been hidden.
You're printing out the numbers as a string, but it needs to be formatted as a phone number with the brackets() and the hyphen (-)
as far as i can tell my code output is matching the expected test answers but it is still saying all tests are failed. Please give me a hint or some help.
Read this: https://docs.codewars.com/training/troubleshooting/
This comment has been hidden.
Read this: https://docs.codewars.com/training/troubleshooting/
your code just prints the result, it does not return anything. You need to make the method return a value.
Test Results: Basic tests Log (123) 456-7890 None should equal '(123) 456-7890'
ok? guess programming isnt for me
Not a kata issue, your code is wrong.
please read this bullet point: https://docs.codewars.com/training/troubleshooting#.print-vs-return and don't give up this easily.
you need to return the output and not print
This comment has been hidden.
This comment has been hidden.
Hopefully this helps: https://docs.codewars.com/training/troubleshooting/.
This comment has been hidden.
Please don't post code like that without marking your post as having spoiler content.
too easy for 6 kyu. rank down plz
Impossible.
WHAT
Completed in 14ms.
Add a test, where it would check if numbers are less than 10, because now i can get a very long phone number and pass a test
The description states we receive an array of 10 integers, so this would be pointless.
Too ez for lvl 6 kata, more like lvl 7
Try it in NASM and we'll talk about it once you're done ;)
This comment has been hidden.
This is the initial code:
The function receives an array as input, you've changed that.
This comment has been hidden.
Not a kata suggestion, please read this: https://docs.codewars.com/training/troubleshooting/
your func must return something. "print" don't work
it's interesting kata, thanks(:
Thanks for the easy honor bruv
Almost overcomplicated the solution...
I get the desired result of a string in the proper visual format with my code, but I get this error: '([0,) 2,- 3, ' should equal '(023) 056-0890' '([0,) 0,- 0, ' should equal '(000) 000-0000'
I see a bracket as if part of my code is being interpreted as a list, but my final output types are string class. Can someone assist? Thanks in advance.
make arrays out of cycle
This comment has been hidden.
The idea of
Sample Tests
is to give you a clear expectation of what exactly your function should return based on a few input examples. This does not give away all the answers. When you clickATTEMPT
, your code is tested more extensively by additional tests, edge cases, and random tests.so the samples are the end product of what ones solution should accomplish. Thank you. That makes sense now. I take it the syntax needs to be perfect ?
with this example:
Assert
will tests whether your code returns the string"(123) 456-7890"
based on the input of an array of integers:arr{1, 2, 3, 4, 5, 6, 7, 8, 9, 0}
.As for syntax, perhaps there could be some varience, but if your function does not return the expected value for every test, it will not pass tha kata.
thank
This comment has been hidden.
Truly, not every rating is perfect (as this site evolved while it grew) so there is some varience in the kyu from kata to kata, especially depending on their age.
can we concat array with string directly? confused with this solution
This comment has been hidden.
https://docs.codewars.com/training/troubleshooting#post-discourse
This comment has been hidden.
This comment has been hidden.
Please read this paragraph: https://docs.codewars.com/training/troubleshooting/#post-discourse
This comment has been hidden.
Not a kata suggestion, please don't post solutions in Discourse.
nice, I like ur solution
This comment has been hidden.
Please read this paragraph: https://docs.codewars.com/training/troubleshooting#post-discourse
Passed the test results then got this for attempt: Test Results: Generic_Test should_return_the_phone_number Actual: "" Expected: "(123) 456-7890" Nums: [u, u, u, u, u, u, u, u, u,
But the log shows the correct output. Help please, using C
why cant i use Array.Sort Method in your Kata? In vs its working fine.
Why would you need that? If you're confused about this:
in order
there doesn't mean you need to sort anything, it means, you need to do A to accomplish B.I see, im dumb, i dont know why i thought that! Ty
dud i,am not from america !! we dont know how phone numbers look like in there ?? what are the rules :_(
Refer to the example on the description and the sample tests.
Too simple for 6 kyu?
F# Translation
Enjoy! :)
I can't understand why my code isn't running. While I've checked carefully and tested on another page already. I think your kata is really problematic
Please read this: https://docs.codewars.com/training/troubleshooting
The problem is in your code, not the kata.
Me,too
This comment has been hidden.
I've got it so that my outputs are the exact same as the test's output, with the exception that they are not surrounded by single quotation marks. What does this mean?
This comment has been hidden.
To begin with, the function
CreatePhoneNumber
in C# for this kata requires a return type ofstring
, whereas your code shows a return value of typeint
. Next, don't redefinenumbers
, instead you are to use the inputnumbers
to format your phone number output as described in the description... for example:"(123) 456-7890"
..
This comment has been hidden.
In your terminal, what's the input value? Is it a string maybe?
Yes, I see now thanks. The test on here is a list of ints and I need to convert to string before returning?
That's one way of doing it. Your code should return a string.
what am i suppose to do when it says i failed but the outputs are correct?
This comment has been hidden.
that's smart
This comment has been hidden.
Not a kata suggestion, and please, don't discuss solutions in Discourse, do it in Solutions.
Chrono, I'm newbie, Can you tell me how delete or edit my post?
You can't, but don't worry about it, just don't do it again and that'll be fine. Make sure you read the DOCs: https://docs.codewars.com/
This comment has been hidden.
Please don't post solutions in
Discourse
, there is aSolutions
section for that.Not a question either.
Sorry, I'll correct now
I have no idea what to do with this quesition but i guess i will figure it out when i get more time. I am a complete noob
Same Here bro😂🥱
This comment has been hidden.
same bro)
Me too:)
This comment has been hidden.
Please don't post solutions in Discourse.
kinda easy for 6th kyu imho
how did u manage to do it?
Looks like it would be a 7 Kyu going into it, but certainly worthy of its 6 Kyu rating.
This comment has been hidden.
A phone number from where?. This question is culturally biased.
In this case the point of the excercise is to help you learn how to format String data types in code, not to persuade you that american phone numbers are better. If you were developing software for a company someday in the future, you would need to be able to offer multiple formats for a phone number based off of the formatting style that the user prefers.
almost overcomplicated the solution, lol! i wanted to directly use a char array, but you have to put a NUL at the end by yourself else it reads junk data at the end. guess i learned something :D
useful!learned from you.
ez
This comment has been hidden.
including template literals from es6 would be nice.
See other's solutions, using template literals is possible.
ig there was a bug on my end, it wouldn't accept
${}
format.did you use quotation marks or backticks? not sure what problem you're having...
backticks.
ive already solved this without template literals, and i see other users have been able to use them.
unsure why i was unable to input them, but its no longer an issue for me.
thanks for your concern though.
I really feel like this should be 8kyu kata, but i know u cant change the rank.
At first glance the answer is obvious, but if you try to think about how you could abstract your code, then that is what makes it 6yu in my opinon
This comment has been hidden.
try returning rather than printing
it works, thanks
This is not what phone numbers look like where I am from. Can somebody clarify what the formatting rules are?
I wrote a solution for the three initial test cases, but I'm seeing some unexpected requirements in the random tests.
TIA
Which language? The format should be exactly as the example in the kata description.
Just after posting this question I realised I had massively overcompliated the requirement in my head, and now have a working solution.
Thanks for responsing so fast, though.
Hey guys, I have a question regarding unsigned char initialization as seen in this program. The programming language is C.
(const unsigned char[]){ 1,2, 3, 4, 5, 6, 7, 8, 9, 0}. Can someone explain to me how to read it from the function ?
Using a pointer and (const unsigned char[]){ '1','2', '3', '4', '5', '6', '7', '8', '9', '0'} works for me but I cant figure how to get the code running with the default setting.
Any help would be appreciated :). Thank you.
\t isnot working , how can i add whiteSpace in code ?
That's the
tab
escaped sequence, have you tried a literal white space?In scala this kata's test cases are lists of size 9, not 10. So problem should be updated
This comment has been hidden.
You're probably reading the wrong error, because there's no way those 0's turned into 1's.
I resolved it and it works but it's written that thre is an error: from array import* def create_phone_number():
arr=array('i',[]) for i in range (9): n=int(input("enter a number : " )) arr.append(n) print('(', arr[0],arr[1],arr[2],')', arr[3],arr[4],arr[5],'-',arr[6],arr[7],arr[8])
Why are you creating a new list, and trying to take the user's input? If that's Python, and I'm pretty sure it is, the list is passed as an argument in
def create_phone_number():
. It should look something like this:def create_phone_number(n):
,n
being the list of integers.I review other answers and sometimes I past them in an IDE to follow it better and understand what they are doing. I wonder if that is somewhat of a shortcut and I should wean myself off of it or not.
This comment has been hidden.
This comment has been hidden.
Thank you sir
This comment has been hidden.
Please don't post solutions in Discourse.
This comment has been hidden.
Please read this: https://github.com/codewars/codewars.com/wiki/Troubleshooting-your-solution#how-do-i-post-to-a-kata-discourse
This comment has been hidden.
Read this: https://github.com/codewars/codewars.com/wiki/Troubleshooting-your-solution#when-i-print-my-answer-it-looks-exactly-the-same-as-the-expected-output-yet-tests-fail
im not really sure if this is accurate but during this i was testing which methods are better, list vs. tuples and list vs. string concatenation i found tuple(map(str,n)) is faster than with using list with great margin i also found that string concat is faster than list as well with small margin
I have written this test in Java but am experiencing this error.
./src/main/java/Kata.java:3: error: cannot find symbol assertEquals("(123) 456-7890", Kata.createPhoneNumber(new int[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 0})); ^ symbol: method assertEquals(String,String) location: class Kata
I just a have a quick question as to why using print() to give my final result didn't work, but return did. There it is. That's the question.
You can read that (and more) here: https://github.com/codewars/codewars.com/wiki/Troubleshooting-your-solution#when-i-print-my-answer-it-looks-exactly-the-same-as-the-expected-output-yet-tests-fail
As the function written to test the function we are working on is checking the output ie he return statemnt's value plus its dataType and coparing it with the expected output.
This just saved my ass. I was about to give up and switched "print" to "return" and that fixed it. Thank you.
Please, I tried to do this kata in PYTHON. I used f-string to write the result of my function, but I don't understand what is wrong with my result and the waited result.
Read this: https://github.com/codewars/codewars.com/wiki/Troubleshooting-your-solution
Even I am getting the same error. The output looks exactly same as expected. I checked all spaces.
I found the issue. We were trying to print the result instead of returning it. :P
This comment has been hidden.
Please, don't post your solutions in Discourse. There is a Solutions section in each kata for that. You can see other's solutions and talk about your own. There too, use spoiler flag if you disclose information about the solution.