8 kyu
Find the Difference in Age between Oldest and Youngest Family Members
11,124 of 20,863KaraM
Loading description...
Algorithms
Arrays
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.
Worst family gathering conversation, it's the same result every year until one of them dies.
This comment has been hidden.
Your oslution works incorrectly for some inputs. For example, for
ages = [5, 8, 72, 98, 41, 16, 55 ]
it should return[5, 98, 93]
but it returns[0, 98, 98]
.Your solution being incorrect is not a kata issue.
Thank you so much hobovsky, I am able to solve the issue now after you pointed it out with the above example, now my test passed
Rust translate
approved
i'm having this error, is this problem with the kata? 'assertSimilar is deprecated, use assert.deepEqual' btw i'm writing js.
Fixed
thanks, it passes now.
another java translation: https://www.codewars.com/kumite/66430df34fafee513f94386a?sel=66430df34fafee513f94386a
Why are they calculating the age differences between members if that is actually a constant? Why not just write it on a piece of paper and only recalculate when granny kicks the bucket? I mean don't get me wrong it's good for a kata. Just the story does not make sense.
That's not true, family members can change across time. Marriages, divorces, births and deaths (and not all family members can gather together at the same time for several other reasons) make that more dynamic than what you first thought.
And you never know if some family member have dyscalculia and might calculate its age different every year.
Also depends on when birthdays fall in relation to the date of the gathering.
This comment has been hidden.
If you tried to apply this code as is, in one line... well, this may be a problem, since JS compiler can't comprehend the several lines cojoined in one.
Also you forgot to return the variable
Double-also, not an issue, because it is used for the problems within the kata, not with the user code.
This comment has been hidden.
Please use the
spoiler
flag when posting code in the discourse. Cheers.Sorry my bad I will
Coffeescript
Crystal
(author inactive)
I'm not really sure how these are ranked. I've spent half an hour trying to just get the size of the array, or the array, to print in C. I keep getting memory errors. Even a simple
printf("%zu", a);
for the array size doesn't work. I've been really attempting to learn C but when one can just writeprint(ages)
in python and presto it's there, wtf over? I just have no understanding of how to access the information via these functions. The python problems seem super easy by comparison. Just getting access to the information in C is like 90% of the battle. /rantFirst of all, it's not really clear what you are asking.
Second, your rant seems to be somewhat... surprising. Because of two reasons.
Your conclusion is actually pretty correct and that's exactly how it's supposed to be. Comparing Python to C is like comparing apples to orange stem cells. C is low level, and it's difficult to get things working. Python is exactly opposite end of the spectrum, it's high level, and that's exactly why it exists: to make things easy.
Without seeing your code it's difficult to say why you were getting crashes, but it's most certainly some problem with your code.
printf
works perfectly well here, I had no trouble with printing size of the array using following code:Note that requirement of returning some allocated memory is because how test cases are created. Properly created test suite would work and would not crash if solution stub would return, for example,
NULL
.My question would generally be: if you can't handle low level, why would you even bother solving kata in C?
Hi thanks for taking the time to write back. I had no idea we had to return malloc'd memory. Or how one knows that you must do that. Thanks for the heads up. Frustrating that I just can't seem to grasp anything in C - nothing seems consistent in these puzzles. Not their fault, you are already supposed to know all this stuff, but incredibly frustrating as a newbie doing a level 8 puzzle and I can't even get past the first step that I thought would be a simple
printf
.I read the descriptions and am like "hey I got this" and the go to the next page and...I've got nothing
Just thinking aloud, it would be neat if there was a
hints
tab for those of us who don't quite get it. Not full blown answers, but stuff like this, "you must return malloc'd memory" and the reasons why. Because, I don't really understand why we must to be honest. Just that your solution worked lol. So I'm not really learning anything. Not picking on the site, this is great, and helping a lot, but I feel like I'm mostly just guessing and hoping stuff works vs understanding the reasons behind it. Thanks again.Okay, now I see where you are coming from. You are just discouraged by the fact that 8 kyu kata requires so much work and prerequisite knowledge in C. This is, unfortunately, true, and it's a result of a couple of factors coming together.
Some kata are created in high level languages (like Python or JS), get ranked as trivial, entry level task at 8 kyu, and some time later they get translated to low level language, like C. All language versions are ranked the same, but it;s true that because of how arrays are handled in C, it requires more work. Inconsistent difficulty between various language versions of one and the same kata is a known problem, but there's yet no agreement how to handle it. This is the main reason why sometimes you need some kowledge about memory management, pointers, arrays, and such, to solve C kata even when ranked as trivial.
Kata authors and translators also are at fault here. It's kind of a pattern in CW kata that if solution has to return a pointer or an array, it's required to allocate the memory. It is not a valid C pattern, or maybe it's not a pattern which is valid in many scenarios, but translators seem to not know anything better, so they go the way they know. With a very few active C authors it became a kind of a pattern for all C kata, that details on memory management are not given at all, and you are required to allocate the mmeory by yourself even it would not be the best way to handle such scenario in C in "real world". I generally regard such lack of specification as kata issue and I usually raise it as a remark when I get to seeing the translation before it gets approved. If you think there's not enough information, you can raise an issue or suggestion, so author would add required information to description or some hint to sample tests. "Hints" section should generally not be necessary, everything should be clearly spelled out in the task.
It's not the biggest deal in the world but I know for me it feels discouraging. Especially this puzzle. The actual logic on this was easy to get down once I could just understand how at least get the data to output. I've done a few 5 and 6 katas (in C) and they were easy compared to this, because I could understand how to get access to the data (and return the correct data, another hard point in C here). Granted, my solutions are not eqloquent by any stretch of the imagination but the first step is at least knowing how to get the data!!
As for why I am bothering to understand basic C? I dunno. Maybe a glutton for punishment? It feels like a basic building block for me, starting at the bottom of programming. The online course I took started with C and moved to Python after five or six weeks. Mostly I'm doing the C problems because I don't want to forget what I've learned already.
Remember that you can always ask for help on kata solving help Gitter channel. You can ask questions related to kata algorithm, language, some specific part of the task, whatever, and someone will eventually help.
Thanks. I've not heard of Gitter, but have been using Reddit, under the general r/learnprogramming. They've been super helpful and there is a ton of traffic there. But, while I finally felt like I had a handle on malloc, and basic stuff, this got to me. I just couldn't figure it out. So far the folks responding to my questions here have been great too. I think you've answered some of my questions as well. I was just unhappy I couldn't understand how to start such a base level problem.
This comment has been hidden.
read this for clarification on using
min
/max
Thank you, first time using that function didn't know the correct syntax :)
This comment has been hidden.
Next time, mark your post as having spoiler content, please. console.log just prints the result to the console, it doesn't return anything, just remove it of your return line.
You are right, sorry
I'm new to programming and was stuck on why my output was incorrect. I was returning a list instead of a tuple. Might be worth noting that to clarify since this is a kata for 8 kyu. But now I understand the difference. So maybe that was the point?
Edit: I was using Python
I was confused to with why my code output was wrong. I was trying to return the min, max, and the difference with an array and append just like you did. The only thing that made it right for me by returning those three values in a tuple and not an array.
Added to the instructions you need to return a tuple in Python.
[Python] In my opinion it has to be more clear in the instruction that you have to return a tuple. Now I assume I have to return an array. Fun kata nevertheless
can anyone translate it to java please
I was def thrown off by the "in order" part.
This comment has been hidden.
let
s by removing those 2 commaslet
Ruby translation kumited -- please check and approve (author is inactive)
cant this be achived using classes?
Sure.
But is that a good idea...? (like... using matches in a room full of gas...? x) )
C translation
CFML translation kumited.
another python translation https://www.codewars.com/kumite/59a5350007157ab56300013b?sel=5e71eeb425ba68002d56ad15
Julia translation
Approved
Python translation added.
Where's the link to it?
Under the language drop-down, add new.
PHP translation added.
Needs random test cases
Good to see that random tests are now in place :D
This comment has been hidden.
I second that
Hi, Thank you for your comment. The kata has 2 example test cases and then there are the extra test cases. What do you mean by random tests?
This comment has been hidden.
Thank you, smile67, for your good advice! Done!
Well done, it works;-)... (many solutions are invalid now, but not because of your new testcases, you changed the function name too)
Hi Smile67, I know, I had to change the name because I had a typo the first go around (it started with a capital letter) and I had to fix it. Unfortunately, that would have broken previously correct solutions. Oh well, it is still in beta. Thank you for being so helpful with the test cases!
Both no problem;-)... and i'm sure next time your new katas directly contain some random tests:-)...