Draft
Tug-o'-War
790 of 1,680edm2410
Loading description...
Arrays
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.
Trivial comparison/sum of list values is not a novel idea.
"Predefined tests in a random order" is not good enough. Actual random tests need to be created.
Need to add more anchors:
test.assert_equals(tug_o_war([[1,3,2,4,5], [5,4,3,2,1]]), "Team 1 wins!")
Number of team members shouldn't be limited:
test.assert_equals(tug_o_war([[1,2,3,4,5,6,7], [7,6,5,4,3,2,1]]), "It's a tie!")
test.assert_equals(tug_o_war([[1,3,7], [8,3,1]]), "Team 2 wins!")
I think it would be better if the cases above are also required in the instructions and tests.
Requirement changes are not happening.
No randomized testing.
Duplicate issue.
Lack of sample tests in Python
How can somebody contribute that work?
Sample tests covering the
"if teams are equal compare their anchors"
rule should be added to all languages.No random tests in Python, Ruby, Java and C#.
Kata approved :)
Did you read what a 6kyu should be? I don't know who voted 1kyu but that messed the rank mean. It should be 8 or 7kyu at most.
It has none of those.
Also, this could easily be a duplicate of an already approved kata. And I'm pretty sure it IS a duplicate of something now.
@Chrono79 : I merely approved it as the average rank assessed. Also if 1 person in 680 ppl ranks as 1Kyu, it'd barely matter (even if they are PU)
I'll change it to 7Kyu :) Edit : or not, apparently it's not working for some reason right now
1 kyu
was voted by a cheater (and quite possibly it was you).Dude, do you think everybody forgot that you're
no one
? And I'm pretty sure you've spammed1 kyu
votes on beta katas, even if it was not this one in particular.I have no idea what you are talking about. But I'll assume that the person you are talking about is a cheater or someone mental like you (a safe assumption, both of them). In any case if you proof of either I'd be glad to hear it, otherwise I suggest you scram.
Oh, look you edited : so I'll edit my comment as well to answer part 2 :
Kindly provide proof, otherwise stop wasting other people's time.
I think this kata's about ready to come out of beta, but a couple more sample tests would be nice
Not fixed in Python.
Make it more clear what the ends of the rope mean in terms of array
I'm not sure when the diagram was added, but I thought it was pretty helpful in illustrating the "anchor" positions.
Diagram illustrates
It's important that the lengths of the test cases vary. Otherwise one could simply hard-code the anchor indexes.
I think that's a good idea, though I would suggest forking it and making the team sizes variable (in the description, it's clear that there are 5 team members, and for a lower kyu problem, that makes sense to me). A further complication could be added by making the surfaces the teams are standing on of different materials, so they are more or less grippy/slippery.
Ruby here. Anchor 1 is
teams[0][0]
and anchor 2 isteams[1][-1]
becausearr[-1]
returns the last element of the arrayarr
. If your lang isn't this convenient, I submit my totally unbiased opinion that you should switch to the best language,HaskellRuby.Honestly, it's much more important that the test cases are random or numerous or both. With a low-level kata like this, people may be tempted to hard-code the final answers.
Needs random test cases
I added them.
Nice kata, little but of !*&@$ but well definitely good
This comment has been hidden.
Your value needs to be returned, not logged out. Though upon my review, I did not see that having to return the value was included in the description. So, +1 for adding that to the description.
You should always assume you should be returning the value because CodeWars doesn't read from the console ever, AFAIK.
Not an issue
May be we can improve a bit of fun by add more than one Anchor :)
Would make the problem needlessly complex. This is good for a low-level kata.
Closing.
This comment has been hidden.
You should
return
instead ofconsole.log
. Always assume you should return the answer because AFAIK, CodeWars doesn't read from console ever.Closing.
I think you need to explain how teams are in the array Team 1 : Anchor + 4 members Team 2 : 4 members + Anchor
I spent a lot of time searching why tests were failing :)
But it's a nice Kata
It's currently in the description.
There is even a picture and further examples.
Diagram and description ilssutrate
Need more tests
I enjoyed this kata, thank you very much.
Needs more tests
There should be more test cases related to the Anchor.
There should be more test cases in general. Also random cases.
In the "more examples" area, the comments need to be switched. Other than that, it's amazing! I really like the originality!
Nope, they are fine
Need more test cases.
so cute
WTF ?
Kumited a ruby translation. My first translation on code wars, so let me know if it needs any work.
This comment has been hidden.
The instruction is, "farthest fromt the middle" which is pretty clear. And your code of [1][4] would be incorrect if there each team would have more or less positions
I made it clearer now I believe. I also included an image.
If this is no longer an issue could you mark as solved please? Thank you.
This comment has been hidden.
You are not picking up the correct anchors.
I've clarified the description and included an image.
If this is no longer an issue could you mark as solved please? Thank you.
Not an issue.
The final tests should include a situation when the strenght is the same and the anchors are the same (what if the second 'anchor' in order is stronger in one team?)
The test is now there.
If this is no longer an issue could you mark as solved please? Thank you.
Resolved
which member is anchor in which team should be explained in a clearer fashion. otherwise the kata is ok.
totally agree ! Damn...
I made it clearer now I believe. I also included an image.
If this is no longer an issue could you mark as solved please? Thank you.
Issue solved
TypeError: Cannot read property 'length' of undefined at tug_o_war at testResult
I get this kind of error, although my code works, when I test it on http://eloquentjavascript.net/code/
More unit tests to explain Anchor system
I made it clearer now I believe (in the description). I also included an image.
If this is no longer an issue could you mark as solved please? Thank you.
Can you please add more test cases because it's unclear in some instances why code fails when you run "Submit" (and it passes when you just try the tests provided). Thanks.
Anchor positions should be clearly described in the problem description
I made it clearer now I believe. I also included an image.
If this is no longer an issue could you mark as solved please? Thank you.
I think that the explanation of 'anchor' is confusing.
This comment has been hidden.
I made it clearer now I believe. I also included an image.
If this is no longer an issue could you mark as solved please? Thank you.
The definition of anchor is unnecessarily confusing. Some clarification here would be quite helpful. Otherwise, it looks good.
feel free to provide a specific suggestion
I made it clearer now I believe. I also included an image.
what's the anchor ? I just can't understand...
var r=teams.map(x=> x.reduce((a,b)=>{return a+b})).reduce((j,k)=>{return j-k});
return r==0?"tie"r>0?"Team 1 wins!":"Team 2 wins!";
In C#, I'd suggest making the provided test case initialize a jagged array instead of the [2,5] array because that's what the real test cases use.
Minor Issues (I still voted "Ready" however): Missing test cases
I would add tests that suddenly change people per team to 6, but better logging is needed to inform the coder of such a change. This would simulate changes (as they happen in real life) and would encourage coders to think about maintainability.
(just my thoughts ofc, rules say "5", so my thoughts can be disregarded)
In the test the function takes a bidimensional array while in the implementation/solution it takes a jagged array.
The test code provided does not work, using int[,] instead of int[][].
The anchor decision should be placed more to the beggining of the description, rather than in examples.
I've added Python translation! Enjoy. :)
JS solution does not work.
I've sent in a Java translation.
Unit test for C# is coded different than how the submission is coded. It uses int[,] in the unit test and int[][] in the submission.
The description test case for c# is incorrect as people have pointed out.
test case needs to be tweaked to work
The definition of anchor can be a little better (the farthest player from the center of the rope, obviously the last player in the list -> wrong) or maybe a representation could be provided, such as
tug_o_war([[5,2,3,1,4],[4,3,2,1,5]]) -> 5,2,3,1,4 --> | <-- 4,3,2,1,5
that way the anchor is clearly defined
The C# Example Test Cases has an error in the array input.
The Example Test Cases is:
It should be like in the Description:
I tried to corect this, please check and mark as resolved if Ok.
Seems fixed. Yay!
Would be fun to add some test cases with unfair teams, like one team having 5 and the other team having 6. Should be easy to do in C# at least, since it is a jagged array.
Default test case needed slight modification to work
As it was mentioned, test case doesnt work properly. You have to pass correctly defined parameter to the function.
The default test case does not work for c#!
The default test case has this line:
Assert.AreEqual("Team 1 wins!", Kata.tug_o_war(new int[2,5] { {1,2,3,4,6}, {5,4,3,2,1} } ));
which is invalid. the line needs to be
Assert.AreEqual("Team 1 wins!", Kata.tug_o_war(new int[2,5] { new int[]{1,2,3,4,6}, new int[]{5,4,3,2,1} } ));
Marked as major because the tests fail to run due to this even if the users code is valid.
I tried to corect this, please check and mark as resolved if Ok.
This issue has been fixed.
Could you mark as solved please? Thank you.
The instructions could use a bit of work on specifying the anchor.
I enjoyed this Kata and wanted to spread it more, so I made a kumite for a C# translation. Arrays are so much easier to manipulate in javascript, so I had to make some structural changes for it to work right, but the test cases should all be the same. :)
The acceptance test cases always have the same number of players, there should be some variety there as the problem does not explicitly state team size.
People should be punished for making assumptions about the size of the team and that he team 2 anchor will be index 4 of the second array.
I don't know if he has changed it but it clearly states at this point in time that there are "Two teams of 5 members"
Unfortuantly I saw that right after I submitted the feedback, I am rather new to the site and I have no clue how to edit the post (heck, I didn't know how to see my comment until after I got a notification about your reply). Either way I think the question would be better if the team size was not fixed, in general I find it best not to make solutions only work for arbitrary limits.
I'm rather new to the site as well, so I can relate and you're absolutly right about the limits in general.
If you click on your kyu you can see Discourse->Conversations to find your comments again and there is an Edit button next to your comment.
Have fun on this site
More tests needed.
great, thanks
This comment has been hidden.
Test case added, thanks