6 kyu
Number , number ... wait LETTER !
892 of 1,742user3879542
Loading description...
Strings
Mathematics
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.
python new test framework is required. updated in this fork
Approved
This comment has been hidden.
Not a kata issue. Why have you moved 24z6 to the end?
Examples : "24z6 1z23 y369 89z 900b" = 900 + 369 - 246 * 123 / 89 = 1414
"In the case of duplicate alphabet letters, you have to arrange them according to the number that appeared first in the input string."
Expected order 24z6 1z23 89z I lost more time than needed because I was ordering it correctly which was 1z23 24z6 and then 89z
Did you mean incorrectly, right? Read the text you copied again. The order you should use is how they appear in the original string in that case.
Nice kata overall but this part seem quite ambiguous: Basic math rules do NOT apply, you have to do each computation in exactly this order.
It would help if you say sth like: ignore operator precedence and evaluate in left to right order.
This is ambiguous (depending on the chosen language, here I'm particularly targeting Python). The description should explicitly state what kind of rounding method to use. E.g. here it just so happens to be (again, in Python) "nearest even integer".
Just to expand on this a bit for those who don't know, there are many issues with rounding and computers.
The three most relevant here are:
What this means practically for kata is that without a clear definition of what it means to round, it can become a game of 'guess how the kata author rounded' and become a problem to debug both kata solutions and the kata itself.
FWIW, Python's builtin
round
rounds .5 to the nearest even integer by default (withndigits = 0
orndigits = None
). Withndigits > 1
it looks to the digit to the right of the 5 to decide how to round, but because of (1) above, it can appear random or arbitrary.One solution to this problem is to not check for exact answers, and instead include a fudge factor:
assert abs(actual - expected) < fudge_factor
.I'm sorry I don't understand what you are both saying, about nearing to the "nearest even integer" (it's probably because of my lack of mathematical knowledge).
In Python, as far as I know, if you try to round let's say
4.6
, it will give you 5, which is the "nearest integer" (not even), just like it's specified in the statement.What am I missing?
Check what happens when you try to round following numbers: 2.5, 3.5, 4.5, 5.5.
I think this kata is not for 6 kyu level. I found it too difficult...
I agree, it does seem more challenging. I would say it feels more like a 4-5 kyu level.
Nice challenge!
Great kata, but way to difficult for a 6 kyu. It should be at least 5 kyu difficulty
Hi, for JS the issue is with limitation to Node.js v8. It has buggy Array.prototype.sort implementation (as it moves object that should stay in place). Therefore it causes random test fails. Stable sort is available for Node.js since v12 as mendtiond in MDN resource here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort
So I would suggest to update the Node.js version of this kata, otherwise, rewriting sort method for an array using any reasonable algorithm is a must for JS solution.
Unstable sort is not buggy, it's just unstable. And building a stable sort using an unstable sort as a base is also an interesting task in itself.
This is not really true.
It's not buggy, it's simply not a stable sort. You don't need to "rewrite" sort, but you can easily make it stable, as evidenced by 300+ JS solutions submitted.
There is already an open issue about updating available node version, so I'm gonna close this one.
Ok, my mistake, apparently stable and buggy are not the same as for most part you might not care that original indexes are different when the values copare the same (except in this kata where it ruins your solution). Also thanks for a hint that there are quite easy ways to make this stupid sort in node.js v8 stable, with that knowledge I was able to complete it in few minutes.
So make it separate kata and add it to the kata series! Wouldn't that be nice?
I don't think that hidden task like this is part of the kata and not mention in the description.
It's one of those things thats super easy and obvious when you know it, and super confusing and frustrating when you don't. Today I know and it was easy, yesterday I spent couple hours to figure it out and it was frustrating.
Still, please update node.js to newer version. Thanks!
Please make it possible to do in c++.
you cannot request language versions with suggestions, it's not how it works. someone with proficiency in the target language has to devote some of their time to make a translation; it's volunteering work
Very nice kyu Version should be updated. Sorted doesnt work properly.
Test cases should be upgraded to require total accuracy. My code is usually off by a few decimals from the actual answer, which I 'solved' using the round function, test cases with floating point outputs should be added
You missed that part of the specifications (although rounding is usually a bad idea and approximate equality would have been better)
This comment has been hidden.
your algorithm does not do that, because
sort()
is not stable in Node < 12.0//Language: JavaScript //Testing for '4d13 z44279 93y8 z792 1b54 5b34 2316b8 5290c7 8x84 76z60 b120 414c3' // Output on my computer: 359669281 //ERROR MESSAGE: It should work for random inputs too - Expected: 359669281, instead got: 733591213
What is Expected is the same as the output on my computer. This error message is confusing me, how can my output be what is expected, yet still be wrong? I will post my code next.
Keep your posts in the same thread, please. Your problem can be related to using different Node versions. Javascript's
sort
wasn't always stable.Okay. And thanks for the heads up on sorting.
Node v18 should be enabled.
here
Approved.
You have the error "24z6 1z23 y369 89z 900b" that is 900+369-123*246/89 = 3168, and the test is waiting for the answer 1414
246 appears before 123 and 89 there, check the example in the kata's description, it's one of them.
At least that's the way to explain that order, I guess it can be confusing.
Here is an older post asking the same.
This should be a 4 or 5 kyu, not 6kyu!
completely agree
can agree only becous of node version 8.1 used in this kata otherwize 6 kuy its more then enough.
So default sorting alghoritm in node v8.1.3 isn't stable?
Yes, see there: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort
An interesting map, but your tests are not working correctly. Writes: one was expected, and the other was received, but in all cases I get what was expected on my computer. It is unclear where the incorrect received data comes from. Sadly...
Unfortunately, it still is😥
Your code is wrong. You misunderstood what to do.
What language are you using? Perhaps the kata uses a different version of your language where certain algorithms work differently, such as the sort function on js
Awesome kata, I really enjoyed this one. Thank you!
Ruby 3.0 should be enabled.
done
I sent my solution but it didn’t work, everything works on my computer, checked all cases
Expected: 1414, instead got: 590 On my computer, the result is correct
You're probably relying on undefined behaviour.
Hello, My Javascript code is failing for some random tests by the test set up here. However, this this giving correct answer in my personal compueter sublime editor. I am using eval function and for rounding to nearest integer I using Math.round().
Ex: 586c5 9x7711 885y8 761z3 3b896 87b7 6x98 d86475 100a0 9327a1 9206z3 Codewar showing : It should work for random inputs too - Expected: -84271, instead got: -80447 my own test environment showing : Result = -84271
Is there any idea what am I missing ?
Sort Update : I was using "localeCompare" function for string compare and now changed to string.prototype.charCodeAt() function for the comparision. BUt nothing changed in codewar. I am still failing here but passing in my own system.
input '888a 999a' Visual Studio Code (highest possible js version)
sort
withlocaleCompare
=> 888a 999a JS version 8 (highest possible js version for this very kata) => 999a 888aMany people are using the built in
Array.prototype.sort
method. It is not necessarily stable, but the answer requires stability. Adding a couple of larger arrays in the test cases will probably cause some bad sorts.now that
Array.prototype.sort()
is stable these solutions are correct(javascript) random tests are failing. looks like test case has issue?
for e.g. Testing for '4d84 c44569 496w9 871d9 90a5 870w9 71y7 68d825 c1486' It should work for random inputs too - Expected: 805283, instead got: 805285
4d84 c44569 496w9 871d9 90a5 870w9 71y7 68d825 c1486 => 905 + 44569 - 1486 * 484 / 8719 + 68825 - 4969 * 8709 / 717
each steps
905 + 44569 = 45474 45474 - 1486 = 43988 43988 * 484 = 21290192 21290192 / 8719 = 2442 2442 + 68825 = 71267 71267 - 4969 = 66298 66298 * 8709 = 577389282 577389282 / 717 = 805285
I'm using Ruby
I got the same problem too. I tried to manually calculate the total and I got correct answer with the corresponding condition if the string have a the same letter. Anyone can confirm for us?
Hey, I realized that I'm wrong. I thought there's something wrong in the test but I found out something and I managed to fix it. Try dig more deeper with your result you will find out. Good luck!
.
I am a little stuck on this. i got most of the code to work, but when i get to the test random cases i get this a lot
Testing for '49d957 3300x4 5d76 46z895 134d4 92b8 670b14 97x7 28c8 a3559'
✘ It should work for random inputs too - Expected: 8774, instead got: 8775
Testing for 'y245 30x5 80d7 4c12 809a6 7x28 34d791 42c4 4y14 19w5 4w92'
✘ It should work for random inputs too - Expected: -215, instead got: -214
my code keeps being off by 1 number for a couple of the random test cases. right now i hover at about Passed: 33 Failed: 12
any ideas why this happens?
This comment has been hidden.
Solved it after solved some pbms with sorting. Have you read smile97 question below ( and answer from Cl3anKillx : ) ?
thx! It was very surprised.
"In the case of duplicate alphabet letters, you have to arrange them according to the number that appeared first in the input string" - confused me. Blocks like
"22y6"
not a numbers, so that sounds like subsorting by first number occurance in block is needed.the rule is:
each substring has a character. It's the sorting order.
when array sorted, should remove the charater and calculate the rest number
Thanks for helping!
^_^
.I think adjusting the description a bit by kata author would be helpful for other warriors.
@GiacomoSorbi:
Can you explain what the order of the string should be?
my order is:
I got an error:
My calculations:
Is there a problem with my calculations?
The problem is not the order, you have to calculate step by step (so not using "eval" on the complete string)... ;-)
I'm sure that I'm calculate them one by one
My results are not all wrong, only part of it. Both appear in test cases with duplicate characters.
Ah... sorry, my mistake, switched "Expected" with "instead got";-)... Your order seems ok and your result too (calculated the same before)...
Should be fixed now, let me know otherwise!
Ruby and JS translation submitted (both composed from Stansted Airport to two cities in Tuscany :D), if you want to approve them.
Also, as usual keep me posted about your next katas!
Just approved the JS one cannot find the second one again , sorry was away for the weekend , hope I didn't delay this too much :D
No probs for the delay; what about with a link?
Approved and ready for action !!!
Brilliant, thanks!
Hi, the order of the sorting is not clear to me, for example your description of "24z6 1z23 y369 89z 900b = 900 + 369 - 246 * 123 / 89 = 1414"... Why not "900 + 369 - 123 * 246 / 89"? Ok, "b" < "y", so 900 and 369 is clear, but for same "z" for example str(123) is smaller than str(234) is smaller than str(89)? So what's the second step for the order (numbers couldn't be, because the order would be 89, 123, 246)?
The way the sorting work is when there are duplicates lets say "246z 369z 123z" , it will stay in EXCACTLY THE SAME ORDER it occured in the string . so the final numbers will be in order 246 369 123 since thats the order they occur in the string .
Ah ok, thanks, perhaps a point for your description;-).
In the discription there is a part that states this . "In the case of duplicate alphabet letters, you have to arrange them according to the number that appeared first in the input string" , do you mabe think I should adjust the discription a bit ?
No... i'm blind, that's all;-)! Thanks!
So solved it, thanks again, good one - well done;-)!
I made a couple changes to your description:
I made a slight change to your solution to make this kata work for both versions of Python (
2 & 3
). Python division is slightly different in each version./
uses true division and//
uses floor division/
uses floor division. To get true division one of the numbers must be a float (or you can try:from __future__ import division
)To get around that issue where you used
/
, I simply changed the second value fromint() -> float()
. Now your tests pass for both versions of Python and each user can pick whichever version they prefer!I didn't want to do a total rewrite of your solution code so I just made that tiny change. There are a few things that could be written differently to clean it up a bit and conform to PEP8. I thought it might be better to fork your solution to show you a few improvements instead.
This comment has been hidden.
Oh yes your correct , sorry about that . Will fix A.S.A.P
No problem. You just forgot to
import collections
at the top of your test cases (since your solution uses it). I couldn't see it because I hadn't finished the kata yet, but I just addedimport collections
to my solution and it worked (and then I could see your test cases code).Fixed :D
Awesome, thanks for the quick response.
Also, you shouldn't use
dict
as a variable name (same as usinglist
,set
,tuple
,len
, etc...). Using PyCharm, you get a warning like this:Shadows built-in name 'dict'
. There is a free edition called PyCharm Community Edition that has all of these warnings (PEP8 included) built-in. It has really helped me (while learning Python) to write cleaner code.Do you mind if I fix a few spelling mistakes in your description?
Knock yourself out , I am still a bit new to programming started as a junior programmer about a month ago . Still learning all the correct stuff , but thanks for the feedback it helps a lot . Would also be wonderful if you could fix anything that you think could be beter .
Ok, cool. You're doing a great job with these katas!
I found Codewars over a year ago and I have learned so much by looking at other people's solutions after solving a kata. Best website for programming practice I've found so far!