8 kyu
Find the Slope
3,494 of 10,807elexie
Loading description...
Mathematics
Fundamentals
Algebra
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.
"Assume that [a,b,c,d] and the answer are all integers"
Yet the unit tests expect strings!
That means the string represents an integer.
There is an issue in test case 1!!
I dont understand the error in random test, my code is in python, i use two casting requerided and i have this... I dont figure out Testing for: find_slope([19, 61, 45, -3]) It should work for random inputs too: '-2' should equal '-3'
Testing for: find_slope([-1, 80, 74, 13]) It should work for random inputs too: '0' should equal '-1'
Find another way to get an integer result.
This comment has been hidden.
I could be wrong, but it seems that the random test outputs expect incorrect answers. For example, in cases where y1=y2 the slope should = 0 yet, the test expects -1? :/
same here
Yet most random tests result in a decimal slope and expect an integer.
This does not seem to be made correctly
This comment has been hidden.
python new test framework + random tests are required. updated in this fork
Approved
NO random tests in
This comment has been hidden.
This comment has been hidden.
OP solved it, closing
is this slop always round number? how? why?
To simplify things(I guess). floating point Arithmetic is kind of a problem in computing
I cannot complete this in ruby even though I have tried in my laptop.
A problem with your code is not a kata issue, read the error message:
Your function returns a number instead of a string.
C# Function name should use
PascalCase
Feels wierd that answers has to be strings. Also undefined as string, seems wrong.. Mby im wrong.
This comment has been hidden.
You may find some help in this documentation. Otherwise, ask a specific question; how else are we to help you?
It's kinda strange that it expects string as the output, even for non-number values such as
undefined
Ruby 3.0 should be enabled.
Enabled in this fork
(JAVASCRIPT) I cant make it so it will return undefined when it is an impossible slope but i can do the slope part, can anyone help?
OP solved it, closing
Java sample test cases are still written in wrong syntax.
Fixed.
For Java, I discovered that the return String when a denominator value is "0" takes precendence over the return String when the numerator value is also "0".
The slope is defined by two points. If numerator and denominator are
0
you only have one point.Ah. Okay. Thanks!
This comment has been hidden.
This comment has been hidden.
issues with the java example test cases have still not been addressed....
fixed.
There are still mistakes in java tests (i can see, they were already reported by spike 11 months ago)
(coffeescript): The test cases should be actually undefined and 0, not "undefined" and "0" as strings.
From the description: "[...] return a string representation [...]"
I understand why you'd rather have a different return type (me too), but these are the requirements.
Right. My bad!
This comment has been hidden.
The snippet with the error does not have a function but tries to execute code directly in the class body.
Is it just me or does returning the string "undefined" seem like a HORRIBLE idea.
I don't know if this is intentional or not, but I feel that the ordering of the input is poor/non-intuitive. If (as the exercise's prompt states) the input is an array [a, b, c, d] representing the two points (a, b) and (c, d), then it stands to reason that a and c are the x-coordinates of the two points; likewise, c and d would be their y-coordinates. However, the slope values expected in the test cases return the reciprocal of the slope. In other words, the expected answers seem to be calculated as the difference quotients of the x-values over the y-values as opposed to the difference quotient of the y-values over the x-values, right?
This comment has been hidden.
This comment has been hidden.
Needs random tests
this is a suggestion not an issue :(
There are three issues with the java version. The test cases need to be written
Also, the x is switched around with the y. In other words, this means the numerator is switched around with the denominator if you want to make it pass the test, or pass the final submission.
These three errors with the Java version need to be corrected.
these issues were fixed a long time ago. Apologies for the late reply
Java test cases still have wrong syntax.
Use
Since a string is returned, it could make sense to add non-integer answer test cases.
there are
This comment has been hidden.
(points[1] - points[3]) / (points[0] - points[2])
:convert this part of your answer to a string.Thank you, I'm an idiot.
JAVA: Test cases should be changed this way: from "s.slope([-7,2,-7,4])" to "s.slope(new int[]{-7,2,-7,4})" and so on... Good luck! =)
The Java version had some major problems in the test case, the actual value that the test case was testing wasn't proper java syntax.
Your test should be changed to integers. Right now you are testing to see if integers are equal to a type string. If the person isn't familiar with unit testing, they are going to have it right and think its wrong because the types won't match. Just a suggestion.
Is there a reason that the Python kata expects strings instead of ints for the return value?
all the languages do
This comment has been hidden.
which language are you using?
looks like ruby
are you returning them as doubles or as integers?
i think that may be your problem
You don't return anything all you do is puts the result! If you remove the puts it should work perfectly :)
Ahhh thanks guys! That's it.
This comment has been hidden.
In Javascript all of the tests expect the result to be a string rather than a number. They should expect the function to return a number.
Expected: 0, instead got: 0
From the instructions : "return a STRING representation of the slope." One of the main purposes of this kata is to introduce the user to data conversion. Also, the answers can't be only numbers, especially since you could have and
undefined
solution.Yeah, I apparently missed that part of the description. I'll mark my issue resolved.
Still, it's a strange request. It would make more sense to return a number, and Javascript does have an
undefined
data type, so it'd make sense to return that instead of"undefined"
when you can't return a number.The Java test cases didn't work for me as well. My solution got accepted though.
Hi, it's been years since I was coding in JavaScript and I forgot lots of features on the language. I finally passed one of the challenges such as finding the "slope". Can anyone review my code and so I can improve my coding?
Thanks
A few pointers, since you asked. Your indentation is all over the place. Most Node programmers use two spaces for a single level of indentation, and you have two in some places, four in other places, and your closing brackets don't match either K&R style or Allman style formatting Wikipedia: Indent Styles.
In terms of the logic in your code, you're calculating the same slope 4 times, once for each argument, which is unnecessary. If you want to check that all the parameters are legitimate, you should do that in a separate loop (it's not required in the problem description, but it's not a bad idea). You also don't need to be concatenating values onto your result string. There's a fair amount of "dead code" here. Take a look at some of the other solutions to see what most people consider "best practices."
Thanks. I appreciate it. I'll re-edit my code to improve.
I re-edit it by reducing smaller lines of code. Hopefully it's better than last time.
I just went through the existing languages. And there seems to be two issues left, even though this kata went live:
Slope
. I don't really think this should be fixed after the kata wen't live, since it will invalidate a bunch of good, working solutions. But just remember it for future katas. :-)I am having the same problem in Java. The tests don't compile.
This appears to be somewhat of a duplication Here's another kata which has the same issue only difference is the input parameters and expected output.
This kata was not duplicated. I was reviewing some basic algebra when I had just joined this site, then I realized it'd be a great idea to write a kata that asked the user to calculate to slope. I proceeded to search for "slope" in the kata search bar, but none came up. that as when I wrote this kata. When nothing came up, I decided to make one.Also if you search for a kata involving "slope" right now, mine is the only one that comes up. http://www.codewars.com/kata/search/my-languages?q=slope&beta=false
Maybe because you have my-languages on because I see it. Try this.. http://www.codewars.com/kata/search/javascript?q=slope&beta=false . Even though you didn't mean to create a duplicate you have...
does this mean I have to delete this?
I don't think so, this kata has more translations so I guess.. just be more careful?
thank you. I was pretty new here, and not very familiar with how the search works
This comment has been hidden.
And also please change test case 2 for Java (you say:"The coordinates should have been [-7,2,-7,4] instead of [7,2,-7,4]").
thank you for the corrections. I was pretty sure I changed it. error on my part
also, some of these problems seem to be out of my domain. When I tried to republish the java kata, it took me about an hour (I had to eventually close the page). this isn't the first time I've changed this error.
I have some problems with test cases. Test cases is written incorrectly. I didn't change anything in tast cases. Problen in Java.
/SlopeTest.java:13: error: illegal start of expression assertEquals("undefined",s.slope([7,2,-7,4])); ^ /SlopeTest.java:13: error: ')' expected assertEquals("undefined",s.slope([7,2,-7,4])); ^ /SlopeTest.java:13: error: ';' expected assertEquals("undefined",s.slope([7,2,-7,4])); ^ /SlopeTest.java:13: error: not a statement assertEquals("undefined",s.slope([7,2,-7,4])); ^ /SlopeTest.java:13: error: ';' expected assertEquals("undefined",s.slope([7,2,-7,4])); ^ /SlopeTest.java:14: error: illegal start of expression assertEquals("5",s.slope([10,50,30,150])); ^ /SlopeTest.java:14: error: ')' expected assertEquals("5",s.slope([10,50,30,150])); ^ /SlopeTest.java:14: error: ';' expected assertEquals("5",s.slope([10,50,30,150])); ^ /SlopeTest.java:14: error: not a statement assertEquals("5",s.slope([10,50,30,150])); ^ /SlopeTest.java:14: error: ';' expected assertEquals("5",s.slope([10,50,30,150])); ^ /SlopeTest.java:15: error: illegal start of expression assertEquals("-3",s.slope([15,45,12,60])); ^ /SlopeTest.java:15: error: ')' expected assertEquals("-3",s.slope([15,45,12,60])); ^ /SlopeTest.java:15: error: ';' expected assertEquals("-3",s.slope([15,45,12,60])); ^ /SlopeTest.java:15: error: not a statement assertEquals("-3",s.slope([15,45,12,60])); ^ /SlopeTest.java:15: error: ';' expected assertEquals("-3",s.slope([15,45,12,60])); ^ /SlopeTest.java:16: error: illegal start of expression assertEquals("6",s.slope([10,20,20,80])); ^ /SlopeTest.java:16: error: ')' expected assertEquals("6",s.slope([10,20,20,80])); ^ /SlopeTest.java:16: error: ';' expected assertEquals("6",s.slope([10,20,20,80])); ^ /SlopeTest.java:16: error: not a statement assertEquals("6",s.slope([10,20,20,80])); ^ /SlopeTest.java:16: error: ';' expected assertEquals("6",s.slope([10,20,20,80])); ^ /SlopeTest.java:17: error: illegal start of expression assertEquals("undefined",s.slope([-10,6,-10,3])); ^ /SlopeTest.java:17: error: ')' expected assertEquals("undefined",s.slope([-10,6,-10,3])); ^ /SlopeTest.java:17: error: illegal start of expression assertEquals("undefined",s.slope([-10,6,-10,3])); ^ /SlopeTest.java:17: error: ';' expected assertEquals("undefined",s.slope([-10,6,-10,3]));
are you still having these errors?
Yes, they still persist. It's a syntax error in the example test cases:
Ruby translation submitted :)
thanks a lot :)!(especially for the random cases).
Just ask if you want random tests in JS and Python too :)
This comment has been hidden.
Thank you. I checked the example Test Cases for python, and I found all but One problem : the second test case had the incorrect coordinates. The coordinates should have been
[-7,2,-7,4]
instead of[7,2,-7,4]
Okay.
This comment has been hidden.
I'm on it
Good!
It would be a little difficult(but not impossible) for me to program a random number generator that'd produce integers that when calculated using the slole formula produced only rational numbers. Would you want me to do the random number generator or simply add more
Test Cases
? Also, how manyexample test cases
would you like me to add?This comment has been hidden.
I added 25 test cases to all to all the languages. :)
Your kata is edited and validated. Could you have a look and see if the description suits you?
I think your translation is better. and thank you for approving my kata! :)
The initial code block is not formatted properly - brackets are misaligned.
The unit tests do not test for edge cases; at a minimum, should test for "undefined".
I really have no idea what you're talking about. and there are test cases for undefined. could you elaborate a little more?
"The initial code block is not formatted properly - brackets are misaligned." this also seems like a big non issue.
Ah apologies, I see now that it does test multiple cases. It is misleading because they are all in a single test case, perhaps could split them into separate test cases.
Agreed that the formatting is a very minor issue, just commenting. It is still important on a site focused on practicing code quality.
but why did you categorize it as an "issue?" My honor gets deducted by one everytime you do so.And could you elaborate a little more on what you mean by "they are all in a single test case, perhaps could split them into separate test cases." thank you :)
First beta, didn't realize how the honor system works so thanks for letting me know.
Regarding the unit tests, it would be nice if the different scenarios were each broken out into a separate test case. When your code fails, you just see that you failed one test, but its not clear why (did I forget to handle undefined? is it because of negative numbers? etc.)
If you put associated groups of "assertEquals" into their own @Test methods, the console output to the members will be more informative. For example, you might have:
Thanks again for the kata!
This seems effecient. I'll make amends to my code soon. I'm pretty new here so I wasn't aware that this could be done.
This comment has been hidden.
Given an array of 4 integers (a,b,c,d) (x1,y1,x2,y2), return a String representation of the slope. Slope formula : (y2-y1)/(x2-x1). m=(d-b)/(c-a). I could certainly add about 4 more cases to the 4 I already have, but I couldn't change the calculation since it is correct. Out of the 17 katas turned in, you're the only one who has raised an issue about the calculation.
This comment has been hidden.
thanks for the feedback :)
test should have a double value as expected instead of a int. Because slope is usually presented in double and so "0" != "0.0"
What do you mean when you say "usually?" D: But don't worries about doubles; as the instruction said, "Assume that (a,b,c,d) and the answer are all integers (no irrational numbers!)."