7 kyu
Sort Out The Men From Boys
549 of 10,686MrZizoScream
Loading description...
Fundamentals
Algorithms
Sorting
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.
Wow, what a brief description! I wish you had added a few more pages to really clarify things 👍
This comment has been hidden.
This comment has been hidden.
Your solution has a bug, it's not a kata issue.
Hint:
console.info( -3 % 2 === 1)
.This comment has been hidden.
This kata made me wonder, what would be the best way to remove the duplicates in an array of ints in C. I thought about something like a hashtable but decided to simply sort the ints and remove the duplicates afterwards because that was much simpler to implement for me. What do you think is the most efficient way to build a set of ints in this case?
Has someone resolved this using custom Swift SortComparator?
Am I missing something in the problem description? Why does the C++ reference solution return
{72, 22, -10, -22}
when given{72, -10, 22, -22}
as input? Shouldn't the correct answer be{-22, -10, 22, 72}
?The exercise of the kata is great. The forced use of stretched stereotypes in the instructions is lame. (IMO)
Real men don't use smileys.
please change: "Repetition of numbers in the array/list could occur , So (duplications are not included when separating)." to: "Repetition of numbers in the array/list could occur , So don't return duplicates."
Can we stop with all the annoying emojis? They clutter and make the kata descriptions more difficult to read. Also, what's with the insanely large headers?
Swift translation kumited :)
Revised and BIG APPROVAL :+1:
Rust translation kumited :-)
Revised and _Manly APPROVAL :neckbeard:
This comment has been hidden.
C language : int *men_from_boys(const int *values, int count, int *new_count) stupid...I don't know what's the usage of "*new_account" above.
it is a pointer to which you will assign the length of the resulting array
CFML Translation!
Revised and APPROVED :+1:
Manly Prolog translation kumited!
The weirdest one I've done on this website yet...
This comment has been hidden.
This comment has been hidden.
That's a question, not an issue:
So, the working code that doesn't work specifically in this Kata (without any explanation) is not an issue? Ok. Tested it in MS Visual, works fine there, but you are the boss.
I don't do C++, but it seems a problem with your code, if you comment out any of those inserts, they work separately, but when they're both there the error 139 appears (that's a segmentation fault).
Good luck.
@alexwade94 Sorry, I just didn't know how to assist. But considering that number of completions: it would mean a problem in your code, and in CW you mark that as a question. ;)
Your code fails tests like this one:
Assert::That(menFromBoys(vec{2,15,17,15,2,10,10,17,1,1}), Equals(vec{2,10,17,15,1}));
check the part where you delete the duplicated values, that's your problem.This comment has been hidden.
Big thanks! Completed this Kata a few minutes after posted the question (lol), but all things that you guys said helped a lot.
Elixir translation
ReasonML translation
mm , Nice , Revised and APPROVED :+1:
:coffee:Script translation
Yep , Revised and APPROVED :+1:
TypeScript translation
Yep , Revised and APPROVED :+1:
Julia translation
Yep , Revised and APPROVED :+1:
Anyone knows a great guide to lambda :3
Dart translation kumited (oh, just noticed there's more dart to do :wink:)
@Steffan153
Well, some of them I don't think I can solve.
PHP translation kumited
@Steffan153 .. Thanks Caleb , Revised and Approved :+1:
This is weird, when I display my answer(which is an array) in the console it is correct but when I try return the answer(which is an array) it runs my code multiple times which causes me to get the answer wrong. Why is it doing that? scratching my head
This comment has been hidden.
This comment has been hidden.
thanks a lo for the reply i made the changes you suggested,but the problem was not solved
This comment has been hidden.
Look at the function return type, and then at the value you're trying to return.
@MrZizoScream, C and Java translations available.
@clcraig .. Revised and Approved .. Thanks :+1:
Haskell : https://www.codewars.com/kumite/5b6f257eb3d977da20000573?sel=5b6f257eb3d977da20000573
@cliffstamp ..
Are you so much pathetic/butthurt that you will downvote all my 600 comments? :D
@FArekkusu ..
Both of you got downvoted below; not for all your comments though, neither of you.
Hey, I had somebody ( I honestly forget who ) downvote litterally thousands of my comments, which must have been a lot of work. It's not worth losing sleep over. :]
This comment has been hidden.
I read ( parts of ) the Wikipedia article on radix sort, but that seemed to be no better than
O(n log n)
. There was something about count sort, but that's when I decided my head hurt enough already and I saved reading that for another day.Dinner turned out nice anyway, thanks for the well-wishes :] - we had bacon-cheese-hamburgers, and pancakes with burning rum for desert ( burning alcoholic beverages on dinner or desert plates is A Good Thing™; I do it rather often :).
@JohanWiltink ..
If you're going to specify Expected and Efficient Time Complexity, I expect an example solution that actually showcases the Efficient Time Complexity. The JavaScript translation at least, doesn't ( and it would have been easy to do if the original language example solution had ).
I also expect the Efficient one to be attainable, and I'm quite sure it isn't in this case. I would love to be proven wrong, but sorting things takes at least
O(n log n)
, and ( again ) you are implying sorting can be done inO(n)
. For God's sake man, show us how it's done, you'd revolutionise computing !!I haven't actually checked, but do the tests really expect at least an
O(n log n)
solution, and thus fail anO(n²)
one? Somehow I doubt it, and there ought to be truth in advertising and kata descriptions.As I was saying earlier in the discussion under one of the solutions, you can sort in
O(n)
time but those algorithms are worse than comparison sorting algos, so stuff like "radix sort" and "counting sort" are rather memes than an actually good practice. And no, the test suite is so insignificant that even a bubble sort will complete in in a matter of milliseconds - to experience the difference betweenO(n log n)
andO(n²)
solutions, the tests would need to be increased in number/size hundreds of times, to makeO(n)
sorting algos more effective thanO(n log n)
- thousands of times.By the way, you shouldn't expect much from posting this issue. Zizou doesn't seem to know any theory behind the subject which is why he included this "Expected and Efficient Time Complexity" part in the description. Most probably he'll resolve the issue with his very first comment.
If I read Wikipedia correctly, radix sort is
O(wn)
, andw
is not really a constant, it's a variable and it is necessarily at leastlog n
. So it still cannot be done faster thanO(n log n)
.I don't really mind, I can live with
O(n log n)
. But I'd like truth in advertising and in this ( and every ) kata's description. ( And world peace. )@JohanWiltink .. Well ..
@FArekkusu ... I Think he's asking the description writer , at least you're not the responsible of what i've done , so why bother yourself repying Alex ?? .. and as for shooting me with don't know a thing , i think it's better to provide some informations to help me getting know , rather than saying it out loud , that's will not help at all
If you need a smiley to recognise tongue-in-cheek instead of destructive sarcasm, here's one: :yum:
I'd love to see the more efficient solution. As the example solution, specifically. Can you do that? Will you do that?
This comment has been hidden.
I'd try it ( immediately after world peace :yum: ), if I felt I could do it. I still can't make chocolate of the Wikipedia explanation though ( cooking dinner tonight was difficult enough already. somehow, I'm not at my best ATM ). I'll try again later maybe.
@JohanWiltink .. Well .. Take your time johan and feed me back , ah by the way , if not personal , or vulgar , did you the one downVote me in above comments ?? Just to know ?? .. regards .. Zizou
No, I didn't.
Wait, I can upvote you ( plural ) again! :blush:
ETA: Blindly upvoted everything I could. Because I could. My contribution to Peace On Earth. :D
@JohanWiltink ..
@JohanWiltink ...
Nope, it was me. First time because telling people to shut up is not cool, moreover the discussion here is free and you can't ban people from taking part in it. Second time because you marked the issue as resolved, though you neither changed the description nor agreed to show us the miracle of
O(n)
sorting with radix/counting sort (I'll un-downvote this one because this was rather on emotional basis but not the first one where you told me not "interfere" in the discourse).And again, I'm telling this not to make you look dumb or anything.
O(n)
sorting algorithms are a very questionable topic because:For example, couting sort creates
m
buckets for all numbers frommin(array)
tomax(array)
(even ifarray = [1, 10]
, it will create 10(!) buckets for each number1
through10
). If this numberm
is a lot, LOT smaller than length of the arrayn
, it will be a good choice, BUT if the array is small and the difference between smallest and biggest numbers is gigantic, the counting sort will be very inefficient.In your kata, the array length is relatively small like 4 - 20 numbers, but they vary significantly (in Python, JS, Ruby, Crystal from
-1000
to1000
), which leads to creating hundreds of buckets for only a few numbers to be sorted, so radix sort will miserably lose to comparison based algorithms and will never achieveO(n)
time complexity here.And that's why I'm telling you this again: please, do not include this "expected/efficient time complexity" everywhere because sometimes
theory != practice
.This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
maybe you could rewrite the description a bit? This one has stil some of yours "old fashion ways" (not sure about the translation, sorry if that means nothing x) ), lots of colors, bolds, italics, caps and all of that mixed together... ;)
Hope Zizou won't change it back insisting that without each word in italics it will be harder to differentiate important and unimportant parts :)
@FArekkusu .. Well Alex I think i've mentioned more than my head hair number that if you want to add any changes in the description , inform me before doing this .. and yeah , Although you did get the point of bold and itialic Highlighting the importamt parts in the description , also you've changed it .. :disappointed: :disappointed:
@FArekkusu .. Well .. Feel Free to add any changes to the description Before I'll reverse them back tomorrow
I think you misunderstand it because the description doesn't get any better from using italics (it decreases the readability in fact) - only text in bold and backticks is actually highlighted well enough and catches the user's attention. Moreover, there's always lots of broken English in your description which is not really good...
@FArekkusu ..
"As long as you get the task clearly then nothing hurt." You explained the task in a wrong way, and after I rewrote the description to be correct, you suddenly thought that the whole kata asked for a different solution. Bravo.
By the way, "we are not in the final english exam" is a popular excuse among russians who are "too smart to write properly". Are you from Russia by any chance?
Surely it's ok to correct bad English or mistakes, but not the whole kata or description... perhaps there's no copyright, but generally it should be respected that there's an author with an "individual style", so better to make suggestions;-)... So peace on earth;-)...
@smile67 ..
Yes , that's Exactly what I'm talking about , Suggestion lable , here you can just take a bathe and back , astonished that Your kata's description has been edited ..
By the way , Matthias theses typos have been revised in my previous katas and fixed .. Regards .. Zizou
@FArekkusu .. Well .. if i was back because the kata was asked about something else then Why i didn't change my solution that still this moment fit all the tetscases and random ones ?? .. i Think russia is a good place for hooking Girls , So Why not having a visit ??
I can NOT understand anything from this message.
Is this a very cryptic way to say that you're in fact russian, or a very cryptic way to say something which doesn't really fit in this platform?
@FArekkusu .. if you didn't get neither the first part of the message neither the one concerning the russian , then who the better revise his broken english for more understandability ??
Next time try harder - I didn't even smile.
( ͡° ͜ʖ ͡°)
@FArekkusu .. I did laugh enough tonight from your comments that my voice cracked yours ..
Python translation available. Please, review and approve.
@FArekkusu ..
How is this what is requested?
It should work for random inputs too - Expected: '[71, -86, -766, -288, -18, 463, 10, -28, 100, -4, -10, 12, 88, 4, 859, -68, 74, 8, 52, 343, 327, 185, 89, 47, 27, 7, -13, -95]', instead got: '[-766, -288, -86, -68, -28, -18, -10, -4, 4, 8, 10, 12, 52, 74, 88, 100, 859, 463, 343, 327, 185, 89, 71, 47, 27, 7, -13, -95]'
@MerdinhasDeJava .. Well Nuno ..
Fixed :+1:
Random tests in JavaScript seem pretty messed up -- after passing all the Basic tests, I get error messages like this (and I'm not modifying the input array):
@tachyonlabs .. Well .
Fixed and oddly enough it was about a relatively easy to spot bug that was not trigger by not a single one of the 15 fixed test cases.
I also pass the basic tests but then get the same error message as tachyonlabs -- i.e., It should work for random inputs too - Expected: '[3, 739, -10, -56, -6, -826, 290, 796, -22, 876, 22, 106, 498, 88, -64, 693, 671, 351, 33, -9, -35, -67]', instead got: '[-826, -64, -56, -22, -10, -6, 22, 88, 106, 290, 498, 796, 876, 739, 693, 671, 351, 33, 3, -9, -35, -67]'. Please help.
Reset the kata a couple times and try again (note: copy your code as it will be erased after reset).
I am also failing only the random tests in JS ... is the JS translation being fixed at the moment? The expected results for random test cases are clearly not what the Kata is about, hence I reckon there's still some issues going on...
You may be sorting it the wrong way, though. The reference has been fixed.
I might be wrong, but the first test I fail is the following
It should work for random inputs too - Expected: '[21, 14, -386, 4, -10, -720, -398, -2, -40, -786, -190, -32, -33, 96, 50, 967, 133, 781, 411, 628, 924, 569, 861, 222, 565, 849, 697, 653, 75, 17, 9, 3, -1, -31, -73, -89, -441]', instead got: '[-786, -720, -398, -386, -190, -40, -32, -10, -2, 4, 14, 50, 96, 222, 628, 924, 967, 861, 849, 781, 697, 653, 569, 565, 411, 133, 75, 21, 17, 9, 3, -1, -31, -33, -73, -89, -441]'
it shouldn't be starting with 21 in the first place, for the simple fact that it's an odd number, or am I missing something?
Try resetting the kata a few times and reloading the page. If you started doing the kata before it was updated, you may still be working with an older, broken version.
I checked the output when trying to return wrong output, everything is correct for me.
logged out and in, finally solved :) thanks folks!
after a refresh it worked as expected, thanks!
I'm repeating this again from the previous version of this kata:
I find the sample tests very unhelpful in debugging code. Why not just have simple and easy to reason test cases like these? These 4 tests alone are more instructive than the 15 tests you have right now.
For what is worth, just seen now and agreed.