6 kyu
Dashatize it
5,477 of 15,115Dragoris
Loading description...
Strings
Arrays
Regular Expressions
Fundamentals
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.
Groovy Translation
One of the weird sample tests uses 1 and expects 1, not -1-.
1 is an odd number and so the test should have dashes
Edit: forgot to mention this is the JavaScript version
From the kata's description:
Not a kata issue.
Fair enough. I completely overlooked that
for Java, I change parameter in function from int to long. There is a test where num = -2147483648
C translation (author gone)
Approved
Nice Kata
Some languages do not generate negative numbers in random tests
Done in JS, TS, Ruby and Crystal
Scala translation
Approved
Missing sample tests in Crystal.
nvm im stupid
Not all languages are compliant with current specifications. Putting this issue here so I (and others) can track fixed languages.
Fixed py, coffee, js, ts.
Rust, java, swift are already compliant.
Fixed ruby
Fixed crystal
All current languages fixed.
JS, TS: random tests may generate
NaN
(when the initial value ofrandNum == 0
).One random test case: n = [None, 8.967284948465766e+18] 'None' should equal '[None, 8.-9-6-7-284-9-4846-5-7-66e+-1-8]'
In the description it says we should return "None" if n is not an int, but random test cases are generating different results when n is not an int.
Looks like reference solution used in random tests is broken in Python:
Python version has been unvandalised.
This comment has been hidden.
python: random tests never generate invalid inputs.
Now they do, thanks to OP's fork
python new test framework is required. updated in this fork
Approved
@saudiGuy, did you by any chance modify the reference solution? After your fork the kata is broken in Python, see issue above.
@ejini战神, could you please take better care checking saudiGuy's forks before approval? The exact same thing happened 3 months ago with another really old kata: https://www.codewars.com/kata/59c5f4e9d751df43cf000035/discuss#650a77c6a5de2b73654098d4
I commented on the translation itself about this. In summary I suggest removing the invalid input requirement altogether, because if looking at earlier versions of the description it says "given a number" - so give a number, simple.
As for reviewing, imo it's better to approve them and deal with the fallout later in the interest of getting it done. I think it should be easy to make changes so that things can get fixed without too much friction, but that also means that reviewing needs to be cheap. Break things. It's fine.
Yes, the ref sol is indeed modifed by saudiGuy, I also did not check it properly since it is one of the current solutions from the kata and such solutions used to be correct, but now has become invalid when random tests generate list of floats or ints that have odd numbers in them. (In fact a lot of solutions will be invalidated because of this)
I've provided a fork (only changes reference solution to properly handle edge case) to address this (not taking the approach of @natan as of now since it will be inconsistent with other languages) Making breaking changes to a kata should not be done on a user level, rather requires community attention and concrete discussions before initiating further actions.
I would approve the fork in the interest of fixing the kata, however I disagree with keeping this invalid test case since it doesn not seem to me like it matches the original intention of the kata.
I don't think my suggestion is a big change, it's certainly much smaller than the one currently being made. Also, rust already sensibly does this, though its description needs to be changed to omit the part about "empty result"
that argument speaks against introducing this new requirement
The invalid input stuff is just NaN being originally considered a number because the Number type in js can take that value. Then that got mistranslated and made weird, and now it's blown out of proportion further.
Thank you @ejini战神
@natan, the original intention of the kata does seem to not consider this case, but it was later added when someone translated into CS, TS, Crystal (expecting "" for invalid inputs) and Ruby (expecting
nil
for invalid inputs) as well (which likely follows JS and the preceding languages)... So, it is not an easy fix, but I will bring this discussion to the right channel in discord for further discussion!this kata should be 8 difficult category
There is an issue in the 4th test of the wierd tests.
No, and there are only 3 weird tests in PHP.
Why am I getting just with EdgeCases Test two this Error and every other Test does work: expected:<[]2-1-4-7-48-3-648> but was:<[--]2-1-4-7-48-3-648>. Cant understand where the difference to the other tests is and why my code fails on this one. I even tried to replace those Symbols in the beginning before the 2 with .replace() and substring but they do not delete it. Im using Java.
expected:<[]2-1-4-7-48-3-648>
is the correct answer, which is2-1-4-7-48-3-648
whislt your code returns--2-1-4-7-48-3-648
(2 leading dashes).The
[]
are just there to indicate the difference in your answer and the correct one.Read this for more info
Nice quick Kata but the JavaScript version requires the string "NaN" to be returned if a non-number input is given, but the instructions say to return an empty value. Either the instructions need to be clarified to adhere to the kata test, or the test should be tweaked to adhere to the instructions.
Great kata but i didn't understand the logic behind returing 'None' instead of None. :(
Good task, i liked it.
How is it possible that tests are putting not integer into a method that requires integer?
TS: missing return type in initial solution
Done in latest fork
I manage to pass all tests except for "Weird: no 4"
Can anyone provide some tips?
Is the whole number negative or am I misunderstanding something? My code apparently only returns '9'.
I though the number was passed in as an integer not a string?
Print the input. The numbers are pased as integers, yes.
Yeah, was my poor interpretation - realised there was a negative in front of the first number.
Resolved now, thanks for the swift response though, much appreciated!
Traceback (most recent call last): File "main.py", line 13, in test.assert_equals(dashatize(None),"None", "Should return None"); File "/home/codewarrior/solution.py", line 7, in dashatize if int(n[i]) % 2 == 0: ValueError: invalid literal for int() with base 10: 'N'
Has anyone got this error fixed?
Yes, it's an error caused when converting from str to int, as 'N' is obviously not a digit. In such cases, you'd have to make sure it's digits only.
This comment has been hidden.
For the last sample test shouldn't -28369 => "28369" not "28-3-6-9"? The instructions clearly state that if the number is negative, remove the negative sign.
This comment has been hidden.
I think this means that "None" shouldn't be returned as a string.
Edit: Or rather it SHOULD be returned as a string.
this definitely should be 5 kyu
Ranks can't be changed
If n is not an integer, we are told to return an empty value. So for python I suppose we should return None. However, right now the kata requires "None" instead of None. I hope this gets fixed.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
If you are going to add non-integer characters in the test strings,please specify in the instructions.
i think there is an issue in the 4th test of wierd tests cuz i got error in that test even after handeling it manually!
Not a kata issue. You should
return
the result instead ofprinting
it. Read this for more infoAlso, your code (excluding the debugging section) will have leading
-
At least Ruby:
Test.assert_equals(dashatize(nil),"nil", "Should return \"nil\"")
.Requirement has been removed.
This comment has been hidden.
Not an issue, this is a question.
Rust translation kumited! :-)
It appears the random tests for JavaScript do not test for negative integers. I've included negative and positive integers in the random tests for Rust, both ten digits long.
The random test generator only produces integers in the range
-1_000_000, 1_000_001
. Sounds like you meant to set the range between-1_000_000_000, 1_000_000_001
Thank you, that's a good spot. It seems I might need to keep an abacus next to me. I've edited the translation.
👌
This comment has been hidden.
Exactly, how do we know that 68 should be 68 and not simply independent values 6 and 8. dashatize(6815) -> '68-1-5'
Because both 6 and 8 are even numbers.
poor instructions
Great kata. Tought me one more time about careful details reading. I solved from even values, that's was a little bit more tough. Because of rushing during description reading. Thank you.
I'm getting 4 tests passed, then an exit code error - "ValueError: could not convert string to float: 'o'"" Did anybody else get this?
would be neater if python returned bool None in exception rather than "None" :(
keep getting error that num.split('') is not a function ofr javascript. I know it should be working
is
num
a string?I'm doing the Java version but the instructions don't say what you're supposed to do in the edge cases. What am I supposed to return if the input is "-"? The input value is a int, not a String. How is "-" even being passed as a parameter?
Issue does not seem to be present from looking at the Java tests.
I ran the exact same code in Eclipse for Java, and I passed those test cases that were returning [#-#-#-##-#] specifications, but the site said it was returning [######].
This comment has been hidden.
Poor instruction around negatives and "weird" test cases.
The instructions don't explain all these other scenarios we need to handle. Please update it with explicit requirements.
Agreed.
For real!
This comment has been hidden.
This comment has been hidden.
JavaScript: The solution template has a dangling semicolon.
not an issue.
I was on a roll until today. This one wore me done and I gave up =( gonna hope I can give it another shot on practice&repeat.
Typescript:
Test.assertEquals(dashatize(NaN), "NaN", "Should return NaN");
causes timeout. Also, it's not well defined in the instructions for behavior of negative numbers and others
Test is removed due to specification changes.
Is there an issue with the Swift version? It's not allowing me to use flatMap, and I'm compiling with Swift 3.1.1.
This comment has been hidden.
See the input for those tests, they're negative numbers, your code is failing with them.
This comment has been hidden.
Kata specification in this case cannot be changed or else will break existing solutions
This comment has been hidden.
it's calling mine wrong, when mine meets the requirements described in the instructions. 1 comes back 1, 6815 comes back 68-1-5 - if there are "weird cases" you should say what those are in the instructions. otherwise it's like YOU'RE cheating.
Ruby:
What in the world?
It expects a string
"nil"
not thenil
value.Yeah, but look at the description :
"Given a number"
How is
nil
a number?Added in description - there may be values other than integers.
How is this kata not an exact duplicate of mine? https://www.codewars.com/kata/55960bbb182094bc4800007b
It looks very much like it is…
Not exact because yours is between every 2 odd numbers so you can never have a dash on the outside. :)
Great Kata, but one thing: If you need the output to not begin with a dash, then why test for negative numbers?
I believe I have arrived at a solution for the Java version of this kata. However, I am failing a test case which appears to test the method with a String -> dashatize("-");, even though the method signature calls for an int. I had even tried using an overloaded method that takes a String and then calls & returns dashatize(0) - which works in Eclipse, but no joy here on CodeWars. I am just wondering whether I am missing something or perhaps this is a glitch of some sort. Thanks in advance if you happen to see this comment and reply.
It's been six months since the question was asked, but in case someone else runs into this problem, here's what's going on. The tests check for negative numbers, and you're likely treating '-' as a digit of the number somewhere. Since '-' isn't a number/int, it gives this error. The instructions should point out negative numbers must be accounted; though really it doesn't make sense to include them given that the output can't be negative.
I think this Kata should be upvoted to a level 5. Great Kata, really enjoyed this one.
I'm glad you enjoyed!
The kata for Crystal has no test cases programmed in.
And one of the submit test cases is the string
"--1"
, which is silly.Give it a try now, should be fixed.
Hello, I am getting this error when it tests for "Weird": Should return None: None should equal 'None'
Anybody knows why?
@MariusAFT
,The return value is supposed to be a string ->
"None"
Thank you, it worked!
@Dragoris
,As
@nap4lm
already mentioned, the random tests on the Python version of this kata don't work becauseimport re
is not at the top of the main test cases.My solution does not use
re
but I still had to import it to get the random tests to run.same here
Thanks for highlighting this, I wouldn't have passed otherwise.
sorry for the slow reply, I added import re, let me know if its still not working.
@Dragoris
,I just tried submitting my solution without
import re
and it worked fine. Thanks for the fix!Hello Mate! I had a problem, I solved it without regular expressions. But it still needed me to import re. Not that big of a deal but just so you know :)
This comment has been hidden.
TypeScript translation
Should return 2-7-4 - Expected: '2-7-4', instead got: '[-o-b-j-e-c-t- -U-n-d-e-f-i-n-e-d-]'
:D:D
CoffeeScript, Crystal, and Ruby translations available. Please take a look and approve. Note that in Ruby/Crystal, an input of
nil
(similar to JS'sNaN
) returns ''. Thanks!I was able to easily approve your CoffeeScript and Crystal translations, but keep getting "Description cannot be approved, recent changes from related record must be merged first." when i try to approve the Ruby translations. Any idea why this might be?
This comment has been hidden.
Thanks for pointing this out. I had all my tests under 'Test Cases', instead of 'Example Test Cases'. The non-random tests should now be shown to users.
This is the first Kata I've made and I honestly don't know how to write random tests, i just wanted to give it a shot. Do you have any advice or resources on creating randomized unit tests that you could point me to?
This comment has been hidden.
Awesome!
Ok, I think the random tests are now working properly.
Well done ;-)
Nice first kata! Very good job!
Thanks man, much appreciated!