6 kyu
Statistics for an Athletic Association
299 of 10,913g964
Loading description...
Fundamentals
Strings
Statistics
Mathematics
Data Science
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.
My solution works but Codewars Environment throws and error. "solution.swift:23:31: error: value of type 'Duration' has no member 'formatted'".
Duration does have the 'formatted()' method.
The runner is very rarely on the newest version for any given language.
I want to ask about at least first example of test-case, for understanding, cause I can't take it. We have the array: "01|15|59, 1|47|16, 01|17|20, 1|32|34, 2|17|17", where the result is: "Range: 01|01|18 Average: 01|38|05 Median: 01|32|34". If we calculate the seconds range and we have maximum digit 59 and minimum digit 16, the seconds range must be equal to 43 (59 - 17), but in answers we have 18. How can we get range 18? Where did we get it from and why it doesn't equal to 43? Same question for minutes range. If we take minutes average: 15+47+17+32+17=128, then we divide it by 5(as we have 5 numbers here) and get average 25, but according to the tests answer it must be 38, but why? And I'm not sure about median where I used module 'statistics' and got "1|17|20" but the test is saying that it must be 01|32|34, as we have minute list [15, 17, 17, 32, 47] - median 17, and seconds list [16, 17, 20, 34, 59] - median 20. Can it be some mess with answers or else? thx
Agree, the maths in the answers seem to be off.
Think about it a little broader... The listed times were an hour and 15 minutes and 59 seconds, 1 hour 47 minutes and16 seconds, etc... These represent a definite time value. One length of time. If you want to do statistics on these times, it isn't going to work to break them into partial times.
I enjoyed this problem. I love working working with time values. I few iterations and I was able to solve this. I have to be honest though. I used Bard AI a few times just so I didn't have to scroll through MDN a bunch. I wonder if time to solve these problems has steadily improved on average since AI became prominent.
Before a lot of testing I made it!!!. Instructions al not clear. When the function recibe '' or 'you will return' or any text characters then return ''
My python code for this kata is 100% best practice fr fr
(hint: its 113 lines long with janky code)
Managed to get it done in 1 line of best janktice ;)
Can ye chuck a bit of markdown around the
""
empty strings in If the given string is "" you will return "" so that it doesn't read like some accidentally escaped version of the phrase 'If the given string is "you will return"' ?python new test framework is required. updated in this fork
approved by someone
I managed to pass the test but my statistics are slightly off by one for Averages and Medians in some of the 'Attempt' tests. Any tips on how to approach? My function converts the time strings to one unit before I work out the stats, I am a beginner by the way (Python)
This comment has been hidden.
I see my c solution crashing the test with "Test Crashed Caught unexpected signal: SIGSEGV (11). Invalid memory access." but I'm not seeing why. Any help please?
Sorry, but we can't see why either :(
Maybe if we could see your code we could know why it crashes.
This comment has been hidden.
Just FYI, you can post your code here in this thread, if you mark your post as spoiler and use markdown code formatting.
Now about your code: there's a lot going there, and there is a couple of problems with it. But the most important problem is that your solution suffers from buffer overflows. Did you try to run your solution in your local IDE, with all test cases given in sample tests? I changed your solution in two places by adding one character and it passed for me.
Other problems:
convertToText
is bad,comparator
is bad,sizeof(char)
is always superfluous and unnecessary,Aha, brilliant, thanks. Now using malloc rather than static. That bamboozled me for ages. Added 'const' back into the comparator and not using 'sizeof(char)'. Great help, passing now, thanks. Coming from higher level languages to come and grapple with memory management and pointers is something I'm finding really hard!
#Nice one, but at least 5kyu :)
C fork:
const
-qualified (fixes this issue)Thanks
C#: method name should be
PascalCase
(Please refer to implementation of backward compatibility here )This comment has been hidden.
I completely loved this!!!! It was like blueberries to my brain, Thanks!!!!!
Thanks!
I think there are some problems with the explanation of the median and the response of the median in this Kata. I can't pass because of this problem. Their explanation is correct but their result is wrong. Correct?
Python? There is no eerror in the tests. 2798 people passed the Python kata.
This is a good kata! But I think it's at least a 5 kyu level.
Thanks!
C translation has signature
char* stat(char* strg);
, whereasstrg
is actual aconst char*
, and cannot be modified. It would also be nice to mention in the initial solution that the result needs to be allocated and will be freed.Fork above
g964, very nice kata and very nice description here. Thank you!
Thanks!
hello; i have a question because the instructions was poor and didn't explain a lot ..
when the input was: "01|15|59, 1|47|16, 01|17|20, 1|32|34, 2|17|17"
the output was: "Range: 01|01|18 Average: 01|38|05 Median: 01|32|34"
when i did the math to count the range in the coulmn of minute it was like this (47-32=15) why in the output was (01) did I miss something ??
Range is the highest number in the list minus the lowest number.
In this case, 2|17|17 is the highest number which means 2 hours, 17 minutes and 17 seconds and 1|15|59 is the lowest number which means 1 hour, 15 minutes and 59 seconds.
So the range would be 2|17|17 minus 1|15|59 which equals 01|01|18 or in other words: 2 hours, 17 minutes and 17 seconds minus 1 hour, 15 minutes and 59 seconds is equal to 1 hour, 1 minute and 18 seconds.
The description is really bad. I read the description several times. But I don't understand it. It gave range , average , median calculate methods . But it isn't telling how can I calculte the range,average,median on the gaven string.
Same problem here
This comment has been hidden.
same to me . and there is other things i didn't understand how he calculated the numbers
Range applies to the full time span indicated, so if the fastest time was 1:02:03 and the slowest time was 3:05:07 then the time range is 2:03:04. If the fastest time was 1:30:40 and the slowest time was 2:20:30 then the time range is 0:49:50.
In real world terms the range question is asking "how long did the person at the finish line with the stopwatch have to wait, between the moment the fastest runner finished, and the moment the slowest runner finished? How much time passed between the winner finishing and the last person finishing?"
You have to do time math on the entire period of time, not just the hours/minutes/seconds components separately
I have 80% of the time an error with the random tests. Is there a way to see the test that failed?
Yes, see here.
See: https://docs.codewars.com/training/troubleshooting#print-input
Thanks! I didn't consider the empty string...
I get everything right except for the average, which is only slightly off: 01|35|57 vs 01|38|05 in the first case and 02|26|42 vs 02|26|18 in the second case. What could be the cause?
Asking for help is not a kata issue.
Log
Range: 01|01|18 Average: 01|38|05 Median: 01|32|34
None should equal 'Range: 01|01|18 Average: 01|38|05 Median: 01|32|34'
All tests are like this.(python) Am I missing something?
Please see if this helps:
Not a kata issue. Furthermore it seems that you have now passed the kata.
this one only took me 2 million lines of code to solve!
This was a heck of a lot of fun. Those tests made me refine my code! Gotta love unexpected results.
JS node 18. (mocha + chai
) should be enabledPython new test framework should be usedRuby 3.0 should be enabled
Ruby 3.0 enabled in this fork + Activated random tests
This comment has been hidden.
This comment has been hidden.
Empty strings are not tested in some languages
Done for Ruby
Nice Kata! I learn some good things :) Thx to the author.
Thanks!
This comment has been hidden.
This comment has been hidden.
To calculate the average it says to add the 'numbers' to a set, but if you do, it will fail. Just leave it as it is.
Removed the word "set".
mine result and answer the same, but happen mistake: Test Results: Range: 01|01|18 Average: 01|38|05 Median: 01|32|34 None should equal 'Range: 01|01|18 Average: 01|38|05 Median: 01|32|34'
OP solved it, closing
Very poorly explained
The requirements are not explained well, especially the way the NAs would be represented in the input and how they should impact the output. It is impossible to review the failed tests' definition, so good luck figuring out what the author expected the function to do.
ATTEMPT fails but TEST passes! Also I ran the ATTEMPT tests locally and they passed!
This seems like a codewars environment issue!
The only problem I am trying to solve is how can I throw the parseException on the test cases for attempt?
Why would you want to throw any exception? I don't see any mentions of this in description.
This comment has been hidden.
.
I'm sorry what is the meaning of that? Because I have a passing result on the BasicTests() scenario because I have put parseexception on that method but when I attempt to submit it the other class does not have exception handling that is why my answer can't pass those different test scenario.
Sorry, I forgot about your question. If you're still having problems, you could try asking for help on CW discord server. Otherwise, I could only suggest to avoid using whatever it is that you're using; you shouldn't need it here.
Good kata I liked this
Thanks!
This comment has been hidden.
Nice kata, enjoyed every moment solving it.
Thanks!
Passed it after many tries lol.. who is lying, the random test or statistic.median...?
This comment has been hidden.
Your code has a flaw. BTW don't post issues when so many people passed the kata (Python: 1,866 out of 6,890 in all languages). You make people waste their time.
This was difficult but excellent! Thanks for putting it together
very cool kata, i think it have to be a 5 kyu
Please, add check for empty string to test cases (Ruby).
Another great kata from g964, thanks!
For the first test case that has 5 terms, I am getting different answers to the 2nd and 3rd median values. It looks like the second median is 32, and the third median is 34, which is the 4th terms in each of their lists. Shouldn't the median be the 3rd sorted term in a 5 term list?
Good kata)
The description needs to include that there can be more or less than 5 runners. Else a lot of fun!
It was good kata. For these that didn't complete yet, remember that string can be empty :>
This comment has been hidden.
This is not related to the kata. I think you should find the anwser in Codewars documentation (link in left panel): https://docs.codewars.com/languages/julia
That was the first place I looked. It doesn't say one way or the other. And there's no way to comment.
Then the best place to ask is probably Codewars Discord (link on left panel).
Quite long Kata for a JS begginer, but very nice. Good revsion of of array method.
Thank you!
Working on this in swift, works correctly in my Xcode playground but I'm getting this error here:
So did the creator really just say "nope they can't use this already built in tool that would be perfect for this"??
Or am I missing something? I've imported Foundation at the top of my code but that didn't help...
The "creator" has forbidden nothing. Read this to see Codewars Swift: https://docs.codewars.com/languages/swift.
I guess I'm not seeing what that link is telling me. Thanks for taking the time to comment though, I'll just find a different solution.
"Substrings in the input string are separated by
,
or,
." as per description. But there is no test case for that in kotlin, no test with an input string without whitespace like"01|15|59,1|47|16,01|17|20,1|32|34,2|17|17"
They are ... (comma + white space). Maybe you didn't see the white space after the comma in description? Look at "Sample tests" and you will see.
Before posting issues look at the top of the page to see how many people passed the kata in your language. If there were problems somebody would have said them before you. Cheers and good luck!
I'm talking about tests WITHOUT white space, and there isn't such tests.
Sorry I didn't understand your post. When I wrote: Substrings in the input string are separated by
,
or,
" I didn't mean that in each language there would be the two types of separator; I meant that the types could be one or the other depending on the language. It happens that Kotlin has the first type of separator and Swift has the other type. Anyway with a regex (as yo did) the difference is not a problem. I added that sentence after a post from ByteEater that you can see below.Ok, thanks for your reply. It's all clear now.
I get the following error in Julia for both tests and attempts:
Looks like the test setup since there is a
stati
thereand the test area is outlined in red after any attempt.
Sorry for the inconvenience! I modified the template for initial solution. In Julia the name of the function is not "stat" but "stati". Should word now if you modify "stat" to "stati". Could you mark as resolved if it is.
Cheers!
Merry Christmas!
Merry Christmas to you as well!
This is amazing kate. I have finished and I'm happy. I had a problem - I used a name of function of Python dictonary.
This comment has been hidden.
But there is! The separator between results isn't described, so has to be inferred from the example, where it's always
,
. But in one of the tests it's just,
.Please which language? Are you speaking of the input or of the output? Can you give an example?
Racket. The random tests tend to include e.g.:
"02|32|34, 00|17|20, 00|15|17, 00|16|16, 11|25|11, 01|26|37, 01|16|16,01|15|59, 02|32|34, 01|20|14, 02|32|34, 02|17|17, 01|16|30,01|15|59, 10|26|37, 01|17|48, 12|17|48, 01|47|16, 00|15|59, 01|17|20, 01|32|34"
.Effectively it seems that it may happen but I don't see a "trap" with that... Nevertheless I remove the "There are no traps in this format." which in fact was about the
h|m|s
substrings. I also add: "Substrings in the input string are separated by,
or,
". Hope that will satisfy you.I feel as though this was more of a level 5 Kata than a 6 when considering the uptick in time commitment to work through each part of the problem.
Excellent Kata. I suggest one does https://www.codewars.com/kata/52685f7382004e774f0001f7/ first as a warmup to this kata.
Interesting that one is rated 5 kyu and this one is 6 kyu. This kata seems much more involved.
The description suggests that times in the strings provided are separated by "
,
", they're actually separated by ",
".No, as proved by the string you provide...
If the string I provided, which is used as the example, matched the format of the strings actually passed in, it would be
"01|15|59,1|47|6,01|17|20,1|32|34,2|3|17"
@ChrisMassie: which language? You are right: it can depends on the language. You see that in "Sample Tests".
Ah. I completed it for Swift. The tests given for swift require a different format from the tests for every other language.
Nice Kata!!!
Thanks!
holly frik lots of people solve it with so simple and clean code. feels so dumb :(
This is just my personal opinion. First of all this question is very impressed to be honest. But one thing that myself have been struggling with is about the format of the datetime.
Most of the time second will up or down 1 second at the random test cases. I think it would be nicer and more beginner friendly to have a format guildlines. (I guess that is what you called it.)
Because it yields the result differently on the different method
For further improvement! Hope that helps!
can anyone explain the explanation to me (i didnt quite got it)
their example input was "01|15|59, 1|47|6, 01|17|20, 1|32|34, 2|3|17" and answer is "Range: 00|47|18 Average: 01|35|15 Median: 01|32|34"
now when they say average does it mean average for every seconds,hour,min ex for min (15+47+17+32+2)/5 so average for min=56.5 but here its 35 (Average: 01|35|15)
for median its the middle term of the set so for median of minute it should be 17 becoz arranging in ascending order the minutes=[3 15 17 32 47] so the middle term for minute is 17 not 32
No it doesn't mean average for every seconds,hour,min. The average is global. BTW your calculation "(15+47+17+32+2)/5 so average for min=56.5" seems wrong but here it doesn't matter. Be sure there are no error in the tests so in your example the average is "01|35|15" which means that on average the team has run in 1h 35mn 15s.
there are 5 data in the example,each data is formated, you should change it so you can look for avg,med,range
can anyone explain the explanation to me (i didnt quite got it)
their example input was "01|15|59, 1|47|6, 01|17|20, 1|32|34, 2|3|17" and answer is "Range: 00|47|18 Average: 01|35|15 Median: 01|32|34"
now when they say average does it mean average for every seconds,hour,min ex for min (15+47+17+32+2)/5 so average for min=56.5 but here its 35 (Average: 01|35|15)
for median its the middle term of the set so for median of minute it should be 17 becoz arranging in ascending order the minutes=[3 15 17 32 47] so the middle term for minute is 17 not 32
(Median: 01|32|34")
same question could you pls tell me if someone has told you the answer ? thanks in advance
the average is for the total amount of time; consider the h/m/s as total seconds
This comment has been hidden.
Unfortunately no, hence the "Error: execution of an external program failed: '/workspace/tests '".
Nevertheless all was green because the testing function was wrongly placed. It is fixed now and you will be able to see where your function has flaws. I see you don't have a great practice of CW so you must know that when you post code, as you did, you have to mark your post as "Spoiler" (Red label. I did it for you). Cheers.
You're right about everything, thanks lots!
In the instruction is said: Each part of the string is of the form: h|m|s where h, m, s (h for hour, m for minutes, s for seconds) are positive or null integer (represented as strings) with one or two digits. There are no traps in this format.
Here are strings that I am getting for attemps: Log 01|15|59, 1|47|16, 01|17|20, 1|32|34, 2|17|1702|15|59, 2|47|16, 02|17|20, 2|32|34, 2|17|17, 2|22|00, 2|31|4102|15|59, 2|47|16, 02|17|20, 2|32|34, 2|32|34, 2|17|17
Can anyone says what are 2|17|1702|15|59, and 2|31|4102|15|59,? These are not in order and causing wrong results.
C version generates warnings.
Fixed.
Just spent 3 days on this problem and haven't got a solution until now. This is good but heart breaking at some point...
very,very very fun one! loved it.
Thanks!
Some of the "Attempt" test cases pass an empty string to the function, it seems, which can cause problems with trying to do maths on them or casting them to numbers. You can just skip these strings and it seems to work fine (or it did for me!)
I suppose you didn't read the description to its end.
You are correct, I missed that, apologies.
Nice kata!
Thanks!
ValueError: invalid literal for int() with base 10
I pass the test but on the attempts after I pass a few random tests I get this error. It seems that one of the entries has an non-intiger in it or my code isnt up to par yet. Been driving me a little cookoo trying to figure it out.
Ohhh jeez, some of the random tests may be blank completly. Duh. Fun challange, took me far too long to figure that silly part out.
I love katas like this to start my work day. It is not too tough but forces you to exercise multiple coding skills that are not too esoteric to apply in the course of normal technical delivery.
Literally had to nest functions that would handle conversion of time stamps to seconds and then vice versa.
Nice kata indeed to stretch you. Just started learning Python two weeks ago
A lot of work for 6kyu but fun still.
Yeah, definitely not 6 kyu - more like 5 kyu. So far the only 6 kyu kata I spent as much time solving as would be for a typical 5 kyu kata.
God, this one was very fun!
This comment has been hidden.
What language?
I tried your solution many times in a row and it passes all the tests so how do you explain that the test you gave is wrong? BTW before posting issues please notice how many people passed the kata: 295 in C#; if there were errors - and that can happen - do you think that nobody would have said long before you?-)
@Hobovsky - C# @g964 - My solution will pass now.Because when I had "that" one, it cannot pass all tests :). Problem is in processing of average. Because of that my "average" part looks in this crazy way.
Shouldn't morality of the story be: don't post issues too fast?-)
Sorry, but if expected for 26.615384... (with this conditions) etc. is 26, than it is not correct or am I wrong? I am used to round 5-9 to bigger.
And I agree, morality of this story is to not post issues to fast, put it in suggestions e.g. AND should be even that even the mountain is under the Sun ?-)
Description says that fractions should not be rounded, but truncated.
I am sorry. I am dumb o(╥﹏╥)o (╯°□°)╯︵ ┻━┻
I've forked the Rust translation in order to update it to Rust 1.49 and updated
rand::Rng::gen_range
to its new signature that takes astd::ops::Range
.Approved.
Hello, I'm stuck with the tests too, I think I'm understanding the problem in the wrong way but here's my question anyway:
From your example on the problem's description, How do you get a range of 00 for a set of {01,01,01,01,02} hours, isn't it supposed to be 01 (highest:02 - lowest:01)? "01|15|59, 1|47|6, 01|17|20, 1|32|34, 2|3|17"
"Range: 00|47|18 Average: 01|35|15 Median: 01|32|34"
From how I understand the problem, to get a range of 00 you'd need to have a full set of runners taking 2 hours min each.
I have kind of the same question for everything else (all tests), I'm getting all the tests wrong but I think my solution is right, at least for the description I understood.
It's been a really fun and refreshing kata aside from that issue.
This comment has been hidden.
I think I get it now, it's like seeing them like: 1:15:59 and 2:03:17
So the difference is: 00:47:18
Great! thanks a lot, like I said I misunderstood the description.
This comment has been hidden.
I'll try to explain for the 1st failing test if you read things correctly which is not evident. All you need is displayed. You have:
The last line says that you failed on "Median". You returned "03|33|37" written "0[3|33|3]7" to show the difference with expected median "02|24|57" written "0[2|24|5]7" The "[" and "]" show where are the differences, "[3|33|3]" being different of "[2|24|5]". Is it clearer?
Oh - I thought it was another test case that failed and doesn't showing me the inputs. Now I see, thanks!
This comment has been hidden.
Please which language? I have to suppose from your profile it is Python... Guy there is no bug in the tests! I tried your solution. You fail but not where you said in your post. You get a STDERR.
Yeah, i forgot to operate the 2-nd remark: "if the given string is "" you will return "" ". It's python. But the Sample Tests realy shown as broken: test.assert_equals(stat("01|15|59, 1|47|16, 01|17|20, 1,|32|34 2|17|17"), "Range: 01|01|18 Average: 01|38|05 Median: 01|32|34") And when i print(strg.split(", ")) - there printed ["01|15|59", "1|47|16", "01|17|20", "1"(!!), "|32|34"(!!), "2|17|17"]
After all, addind output "" for "" input - make the the bug disapeer ^^
Maybe I'm just dumb but I think the description of this kata really threw me off. I thought they wanted specifically the lowest/highest of each category in hours/mins/secs, not the lowest/highest overall times. I had to look at the solutions to find out that the way that makes sense in the real world is the answer they wanted, which was not apparent to me from the description.
So... what are we supposed to do if we get passed an empty string?
Ah. Return ''
Literally can't wait to see who solved this in 5 lines of code :)
Thankfully no one seems to have distilled it down that short 😂.
This is a genuinely long problem. Some very good and varied solutions to it. Lots of fun little sub problems to break down.
This comment has been hidden.
@DeadPaws mentionned that almost one year ago. Did you read the answers? This test is the first fixed test in all languages and 3836 people passed the kata. Nothing more to say.
my "solution worked" despite me not changing my code after 6-8 failed submissions
OK, depends of the random tests. Good luck can happen... bad luck too... Since you passed, look at other solutions and try to better your code so you pass each time at first try:-) BTW no need to post twice the same thing:-)
protip: if you submit enough times, you might get lucky and get the answer accepted.
my code didn't fucking work for a good 6-8 submissisions but decided to work. i feel like the test cases are messed up somehow.
seems like the example and tests are totally wrong
what prompts you to say? the Ruby tests look ok. what seems to be the problem?
Same for the JS tests, ran it multiple times without issues.
I'm fairly new to programming and this kata was very challanging for me. after three or four hours of trial and error I came up with a solution that actually works but it's not the most readable and it might look bizzare in the eyes of a more experienced programmer. I would greatly appreciate it if a better-than-me programmer would kindly review my code and give me feedback on it and on how I can improve it further.
Not sure if I just don't know how Codewars works, but looks like you have no solution to show.
Would be happy to take a look. Mine isn't as elegant as the top 2 answers (I didn't use Object classes or anything), but I think I've got my head wrapped around some good ways to do this kata.
It's definitely more challenging & time consuming than any other <6 Kyu> I've done before. Several sub problems to solve.
This comment has been hidden.
Could anyone tell me if there is any way for the platform to display the arguments used in the assertiveness test?
This would make it easier to identify why we were unable to send the code, but we were able to pass simple tests.
Print the input.
однако тяжёлая kata... для 6-го то kyu
I'm not the strongest coder. Been on and off with python for a while now, and lately I've been more dedicated to learn. This Kata was extremely hard for me, definitely stretched my limits, I can't even believe I solved it. It's borderline spaghetti code, but I learned a lot doing this, I look forward to cleanining up the code for clarity.
I will be looking at solutions to learn from, just wondering if others had a tough time with this as well and where they got stuck for extended periods and how they overcame it.... ok blab over just got a rush from this and am excited to discuss.
my pea brain couldnt do it
What about rounding Average is 5.5 will by 6 or 5?
The random tests use a different format than the basic tests. There is no blank after the comma, which prevents the strsplit() from working if the delimiter ", " is used.
I can be wrong but I don't think so. 35 guys passed the R kata. Either with
", "
or","
you can split... Moreover you passed the kata:-)Yes, it was not hard once I printed the test values to the console and saw the problem. But In the details, there was a comment about "no traps". Changing the format is kind of a trap ;) If you use "," from the beginning, it's no problem. R is quite flexible in recognizing integers with leading blanks. But if you use ", ", the random tests raise errors. But It's a really small issue. Thanks for resolving.
OK. "There are no traps in this format." is about hours, minutes, seconds:-)
This comment has been hidden.
This should be at least 5kyu. Its hard.
The kyu is not given by the author but by power users when they approve a translation (and they are smart:-)
I'd still agree with headliner.
Several subproblems requiring multiple functions and transformations (whether labeled or anonymous) is probably a 5+. This was definitely more time & brain consuming than any 5 I've done so far.
Fun kata, I enjoyed it. Not sure it is a 6 kyu imo. The empty string instruction could be improved for greater clarity.
This comment has been hidden.
Not a question :) AND please adhere to the https://docs.codewars.com/community/rules/#rules
Nice kata and description. Sometimes I don't understand your katas description, but I like them. They always are interesting.
Great kata, but I think slightly challanging for 6kyu
This is among the more challenging of this kyu level, especially if one demands of himself that his code stay clean and organized.
Nice katas:)
Thanks!
This comment has been hidden.
Check what? Your solution is giving clearly wrong results.
@DeadPaws are you sure about the output? I've tried it in repl.it and it gave me the expected value.
This comment has been hidden.
The name of the function is the same as a function provided by the C library.
87 guys passed the C kata so I couldn't change the name now since it will invalidate all these solutions. Moreover the C stat() function is relative to files as far as I know and I don't see how you could need it here. Sorry, cheers.
I'm doing this in Ruby and I'm having trouble making this one pass all the tests.
If I could see the full test string where it's failing than I may be able to fix my code. It is passing the two sample test. Is there a way I can see the string that is making it fail? Or can someone give me some more sample strings so I can test my code. Thanks.
Print the input.
Thanks, I got the test strings to display in the log. I was putting print after return and that's why I think it wasn't printing the inputs.
This comment has been hidden.
All test pass, but at the end runtime exception. Looks like some test dsl issue. https://ibb.co/s9h5vd9
"at System.Globalization.TimeSpanParse+TimeSpanResult.SetFailure (System.Globalization.TimeSpanParse+ParseFailureKind failure, System.String failureMessageID, System.Object failureMessageFormatArgument, System.String failureArgumentName) [0x0002e] in :0
I tried a few solutions and all worked fine. You fail on fixed tests: can only be a problem in your code.
This is really misterios. I've wrote this tests with xunit and all pass. Also run your test on local Fuchu. All fine. On CodeWars output log all 3 cases pass too. Any ideas? https://ibb.co/PG3Rj79
Ok. Problem was in a defferent formats of timesnaps. Unobviuos runner error messages.
Tests for this kata fail. randomTests.py for x in range(0, 50) takes too many positional arguments according to the tracklog, line 70. (maybe python2 vs python3, i wouldn't know.) Can't submit my answer until it's fixed.
454 guys passed the Python kata; I just tried several solutions and had no problem. So I think it is not an issue of the kata but maybe a problem in your code.
Traceback (most recent call last): File "main.py", line 75, in randomTests() File "main.py", line 70, in randomTests for x in range(0, 50): TypeError: range() takes 1 positional argument but 2 were given
i've no such code in my solution.
OK. I see the line in the tests. But AFAIK range in 3.x takes 2 arguments as well as in 2.7 so I don't understand why you got this TypeError. I tried different solutions with the different proposed versions of Python (2.7.6, 3.4.3, 3.6.0) for this kata and had no problem. Which version did you use? As I can see CW proposes the 3.4.3. Small note: no need to downvote my post. It doesn't make things easier.
used 3.4.3. I can send you my code if you want.
solved, was being retarded. Didn't notice that i defined a function called range, which your code tried to call instead of python's range. Thanks for your patience.
Thanks for your post.
You could use nested function when possible. Happy you found the reason :-)
I used C to pass all the tests, but when I submit, I got this information.
``` Test Crashed Exit code: 0 Signal code: 8
Please add Swift 4 support. Thanks!
I like this Kata, combines a lot of different skills.
Thanks!
%02d is a valid expression in sprintf in R. However, it always gives error for that.
Are you sure the error is from sprintf? Guys passed the R kata. Maybe you should have again a look at your code.
This comment has been hidden.
Slightly modified the description. Thanks!
You should really point out in the problem description that empty strings should be handled in a specific manner. This really made me angry. :(
The descrition says:
What do you want more?
oh, I had problems with that as well (until I read this post, that is). The way there is no whitespace or colon made me think "you will return" is the string given and then the sentence just ended abruptly. NOW, when I think about it, it seems stupid of me. Anyway, if I may propose the following: If the given string is: "", you will return: "" or If the given string is empty , you will return an empty string
There might be few people in need of clearification there, but it'd probably held the ones who are.
Other than that, I really enjoyed the Kata, thank you.
That was fun :)
Thanks!
wrong example in the explaining lol "01|15|59, 1|47|6, 01|17|20, 1|32|34, 2|3|17" "Range: 00|47|18 Average: 01|35|15 Median: 01|32|34" not right rly
no, the test is right.
This comment has been hidden.
Unfortunately for you there are no errors in the tests. You don't say which is your language, I suppose it is Java. Look at the top of the page to see how many guys passed the Java kata. Please don't post an issue unless you are sure of your code.
im sure of my code, its java, can you tell me where is the error? i tested with many difference number and the result is right
Probably this:
I pass all the sample tests but when attempt i get error: undefined offset 1. hose tests are terribly wrong. Everything works when I test it on my localhost...
Did you account for the case of empty input? -->> 2. if the given string is "" you will return "" <<--
so essentially:
if ($strg == ""){ return ""; } else{ return $result; }
Am I handling empty input correctly?
I'm still getting undefined offset 1. All sample tests pass. Anything else that I may have overlooked that could be causing this error?
Thanks
This comment has been hidden.
I believe that the test in this kata is incorrect. so you can not go through this kata. Data for the entrance: "01 | 15 | 59, 1 | 47 | 16, 01 | 17 | 20, 1 | 32 | 34, 2 | 17 | 17». The data you need to get: Range: 01 | 01 | 18 Average: 01 | 38 | 05 Median: 01 | 32 | 34. Data that are obtained: Range: 01 | 32 | 43 Average: 01 | 25 | 29 Median: 01 | 17 | 20. Correct the calculation formulas in the test.
This comment has been hidden.
Nice kata :)
Thanks!
Polite suggestion: change the gendered wording in the first sentence of the description.
Instead of writing
You are the "computer man"...
,write:
You are the "computer person"...
(orcomputer expert
etc.)...or keep the punctation right - "You are "the computer", man..." ;)
SHould i check as spoiler ? :D
Fixed.
Hi, there's an error in the last random case. I'm using C code and counts the number of imput times using the number of spaces +1. This work for every case except the last (the random one) because in this test the last time is followed by comma and space. It can be easily solved but is triky. The description sais "no surprise in the input format" so I think this is simply an error of how the random test is written.
Guys passed the C kata as it was, not tricky:-) Nevertheless I removed the comma. Please tell me if it fits you now. Cheers!
Me too has passed the test as it was. I'd like only to warn about this difference in the last test. Some other languages or differet ways to count the times could led to different results clearly. Nice job anyway. Cheers.
This comment has been hidden.
51 guys passed the PHP kata, the tests are the same in all languages passed by 543 as you can see at the top of the page. The tests are not wrong. When you ask for something please don't post an issue (which makes lose points to the author...), post a question for somebody having a look at your code... if somebody wants to.
I am sorry for this. I didn't know. Have a nice work.
Thanks!
Can anyone into the test cases of the c version?
I got some strange test case like this: "00|15|1711|15|59, 02|22|00, 02|47|16, 02|32|34, 01|17|20, 12|17|20, 01|22|34, 02|17|17"
Tried to handle "00|15|1711|15|59" as two seperated records, but got this error message: "Error. Expected Range: 11|33|49 Average: 03|12|29 Median: 02|19|38 but got Range: 12|02|03 Average: 04|03|04 Median: 02|22|00"
How is it possible that 11|33|49 is the range!?
Finally worked around it by adding this hack:
Turns out that "00|15|1711|15|59" should actually be "00|43|31". :)
I am very sorry: a comma was missing; you should have had
"00|15|17, 11|15|59, 02|22|00, 02|47|16, 02|32|34, 01|17|20, 12|17|20, 01|22|34, 02|17|17"
. I have corrected. I tried your solution and now it passes without "hack":-) Thanks and cheers!Indeed! Thanks!
This kata's instruction need to be expanded. It should be clear from the instructions how the program is expected to deal with missing delimiters and such.
This kata has been passed by 364 guys so I think that description is clear enough. Where do you see missing delimiters? Strings have always the same format, for example:
"01|15|59, 1|47|16, 01|17|20, 1|32|34, 2|17|17"
.You're right, it seems I was confused by the way codewars sometimes discards newlines (thus concatenating two sets of output without delimiters). Sorry!
Hi guys, my solution works fine when testing it through VS. But when I try the solution through the portal it outputs different values to what VS does. Does anyone know why this might be happening?
Which language? Do you pass the same tests on the same data in VS?
C++ and yes. I have passed both example tests shown there on VS but for some reason the code computes a different output on the interface.
Weird, 24 guys passed the C++ kata, 357 with all languages and the tests are the same in all languages. You could give the text of a failed test.
another trap I found is missing commas between runner times. I used print to log the string that is used as a parameter and get:
01|15|59, 1|47|16, 01|17|20, 1|32|34, 2|17|1702|15|59, 2|47|16, 02|17|20, 2|32|34, 2|17|17, 2|22|00, 2|31|4102|15|59, 2|47|16, 02|17|20, 2|32|34, 2|32|34, 2|17|17
2|17|1702|15|59 is not a properly foratted time. Should the solution split that into 2|17|17 and 02|15|59 or should all of it be ignored?
I don't know how you print the input but your string is a concatenation of many strings:
01|15|59, 1|47|16, 01|17|20, 1|32|34, 2|17|17 02|15|59, 2|47|16, 02|17|20, 2|32|34, 2|17|17, 2|22|00, 2|31|41 02|15|59, 2|47|16, 02|17|20, 2|32|34, 2|32|34, 2|17|17
14 guys passed the PHP kata and I just tried a few solutions, all worked fine. Did you get that for fixed tests or random tests?
print($strg)
where $strg is the input parameter
this was in random tests
In the description it said there were no traps in the input data. However, in the random test it failed because an input string was empty. It would be useful if the instructions provided for what should be returned in the case of an empty string.
It disturbs me for long time and makes me so angry, thank you very much!
Didn't you read the description? At the bottom of the page it is written:
Does anybody tried to solve this using Date object in JS?
All tests passed. But I have the error. Ruby 2.3.0
stat': undefined method
-' for nil:NilClass (NoMethodError) fromrnd_kata_tests' from
if the given string is "" you will return ""
This part is kinda silly.
In C#, "run test" does not work .. output: No tests were provided
The tests are there! It seems that CW has changed something in C# and nothing works anymore. Report at CW as a bug.
Works Now;-)
Thanks for the feedback!
Your tests in coffeescript give the following error - ReferenceError: pad is not defined. It looks like a problem on your end.
Modified, should work now. If it doesn't, could you tell me? Thanks for your post!
Thanks a bundle - it works now!
Thanks for letting me know!
My solution is always failed on random test. I have a FormatException in this lines:
string[] dates = str.Split(new string[]{", "}, StringSplitOptions.None); ... TimeSpan.ParseExact(dates[0,1,2...loop by dates here], "h'|'m'|'s", CultureInfo.InvariantCulture);
But on my computer it works with all input values, you pass into my stat-method What's wrong with me?
Hello, can u help me? assertEquals("Range: 01|01|18 Average: 01|38|05 Median: 01|32|34", Stat.stat("01|15|59, 1|47|16, 01|17|20, 1|32|34, 2|17|17")) im have result string :-> Range: 01|32|43 Average: 01|25|29 Median: 01|32|34 expected: but was: If range = max_value - min_value, i cant get Range: 01|01|18 for this stats. same in Average... No ideas what im doing wrong.
Which language please? Could you post exactly what the failing test writes? (between 3 backticks:
... blabla
multilined)Language is Java.
BasicTests(StatTest) expected: but was:
thats all. I think test is failing coz : /Testcase code/ assertEquals("Range: 01|01|18 Average: 01|38|05 Median: 01|32|34", Stat.stat("01|15|59, 1|47|16, 01|17|20, 1|32|34, 2|17|17")) Range cant be 01|01|18, average wrong too.
Tests are not wrong! They are the same in all languages and lots of Codewarriors passed them. Maybe you can view again operations on hours, minutes, seconds:
h is for hours, m for minutes and s for seconds. Hope that helps.
OK. if we have results of team like a /* 01|15|59, 1|47|16, 01|17|20, 1|32|34, 2|17|17 / So RANGE: hh = 2 - 1 = 01, mm = 47 - 15 = 32, ss = 59 - 16 = 43; Range = 01|32|43 Average: hh = ( 1 + 1 + 1 + 1 + 2)/5 = 01, mm = (15 + 47 + 17 + 32 + 17)/5 = 25, ss = (59 + 16 + 20 + 34 + 17)/5 = 29; Average = 01|25|29 Median = sort and fine; Median = 01|17|20 So resulted string must be / Range: 01|32|43 Average: 01|25|29 Median: 01|17|20 / But test comparing it with wrong string like / "Range: 01|01|18 Average: 01|38|05 Median: 01|32|34" */ Or i can understand what is range, average, median? Thx for helping!
As I said the tests are 100% correct. Your calculation is false. You should view again operations on hours, minutes, seconds. The easiest way is to convert hours and minutes into seconds, then make your calculation in seconds and then back to hours, minutes, seconds.
Im sorry and thank you ;)
You are welcome and I'm happy to see that you succeeded!
This comment has been hidden.
The better way I know is to try:-) but no there is no need to handle input value above 24 hours.
This comment has been hidden.
Before posting an issue be sure of your code:-) Many guys passed the C# kata with no problems. I just tried a few solutions and I got no problems at all. There is nothing wrong with the random tests or fixed tests. You got:
The problem seems coming for your use of TimeSpan on a string which can't be submit to your use of TimeSpan. Furthermore the kata can be passed easily without TimeSpan... Be simple, don't use big guns for a small bird:-) You are speaking of random test cases but do you pass "Run Tests"?
Like I said I passed every test except random test. I passed even first random test but only in VS. I was sure my code is working ( I searched for bugs for 2 hours :) ). When I printed input to function and input as array of strings after first linq query everthing was ok ( strings were corectly formatted hh:mm:ss ) but exception was thrown on TimeSpan.Parse(). And this exception is only thrown when I submit my code ( when code is runing on codewars servers ). When I test it localy on my PC, for the same input there is nothing wrong - code is working.
I think I will just make new version without TimeSpan ( but I think TimeSpan fits to this Kata and I used it to refresh my knowledge :) )
You don't even get something like "Expected", "Got"? Only errors as you reported above? When I tried a few solutions of the guys who passed in C# I used two solutions where there was a use of TimeSpan and they passed like a charm. Nevertheless their solutions were at least twice as long as solutions without TimeSpan. Good luck and tell me when you succeed!
No, I don't. Only error at first random input. Ok I found error. In Linq query this line of code: "where !string.IsNullOrEmpty(time)" was needed to stop my solution from crushing. In your random test code must be place that adds additional ' ' to input. When there was only one space after time representation (e.g. "0|11|00, 12|31|20") my solution worked. But when I added second space after ',' exception was thrown (e.g. "0|11|00, 12|31|20" or "0|11|00, 12|31|20 ").
Hi! my code works fine with the Test Cases and when I click on "Run Tests" it passes the tests. but when I try to submit the answer it tells me that the answers are incorrect. what should I do? I checked the program with my own compiler with different strings and it worked fine /o\
First: which language? Then: when you submit tests are more difficult and long.
C#. but if the code works fine with 3 or 4 example why shouldn't it work for another examples?
When you test a program 3 or 4 examples are not -unfortunately- sufficient:-( You may have edge cases. Your rounding/truncating may be correct in some cases but not in all cases. Several people passed the tests without problems. Never have doubts about the tests, rather have doubts about your code. You are still a real beginner so be modest:-) Good luck!
thank you for your reply :-)
You are welcome!
g964 !
I agree with you on basic tests, but on complex tests (when we send the code), can you tell me if there is any way for the platform to display the arguments used in the assertiveness test?
This would make it easier to identify why we were unable to send the code, but we were able to pass simple tests.
Explain properly edge cases
Seems there is only one "edge" case (though not really "edge") is when the input string is "". The description says:
Did you see it?
Yeah, sorry about that. I was working more in the problem and realized I was mistaken.
Thanks!
Hi! Everything seems to be working, but still i get:
RandomTests(StatTest) ****** Random tests ****** expected: but was:
I don't know what the test input is, so i don't know what to optimize, what to work on. I'm am working in an ide, there everything is fine. I can't figure this one out :)
To large
What does that mean?
Haskell: Initial solution is missing the module header.
Fixed, thanks!
This comment has been hidden.
Read again the description. Why would it be a bug?
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
Thanks for the feedback!
And finished...!
Thanks for the kata. :)
Good!
In JavaScript, I just the following message when running the random tests:
I pass the hard coded tests.
I forgot to modify a name in a part of the "solution" in the random tests... Corrected, should work now. I thank you again for your kindness.
Yep, works nicely now.
Thanks for the kata! :-)
I get a similar issue in coffeescript. I pass the hardcoded tests, but get the same error for all random tests:
My bad, I fixed it. Could you please tell me if it works now?