7 kyu
Is this a triangle?
12,688 of 181,278silentZaika
Loading description...
Mathematics
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.
Terrible description, doesn't elaborate the conditions requried to be a triangle. I mean -ve sides and sides with 0 is understandable but how is 1,2,3 not a scalene triangle???
Not a kata issue. A triangle is a figure with 3 sides, it's common knowledge.
I swear JAVA, compared to Python, has the most poorly written exercises: (In this case, all triangles must have surface greater than 0 to be accepted) 1,2,9 -> false
This is misleading
Seriously, while ranting, you need to explain a bit better what you consider a problem because from all the complaints until now, all I've seen is you saying "this is wrong" about somethign what does not really appear wrong at the first sight. Call me stupid, but how is
1,2,9 -> false
misleading? You cannot have a triangle with sides of 1, 2, and 9, so the expected answer isfalse
. What exactly is wrong with it?The correct formula for a triangle was not specified.
It is not meant to. Figuring out how to put three sticks together to form a triangle is a part of the exercise.
This comment has been deleted.
This comment has been hidden.
This comment has been hidden.
It is not a valid kata suggestion. Additionally, it is a spoiler.
What are you talking about? Please explain your point, I really don't understand what you mean.
I mean that posts labelled as
suggestion
are meant to be used to suggest improvements or changes to a kata or tests. Suggestions should not be used to give hints about solutions. In general, hints about solutions are treated as spoilers and should not be posted at all, and definitely not labeled assuggestion
.You are telling people how to solve the kata, but you shouldn't do that. You should let people solve it on their own. A suggestion is meant to be an idea to improve the kata itself. What you are doing is spoiling the solution, so it is not a valid suggestion.
I don't think you're right. Many people here in chat writes about that and telling other people how to solve the problem. I uses a SPOILER button to indicate that my message contains revealed solution. If someone's trying to solve the problem and open the chat, it means he doesn't know how to do that and needs help. When he sees that my message is marked by a SPOILER button and he reads it anyway, that is not my problem. I solved it on my own and wanted to help someone, so this is my SUGGESTION.
If someone did not solve a kata, they cannot read your message anyway. Spoilers cannot be read without completing the kata,and this makes your "suggestion" mostly useless.
The meaning of the
suggestion
label is documented (for example here: https://docs.codewars.com/community#kata-discourse) and as you can hopefully see, the label is meant to be used for kata suggestions, and not solution suggestions. It is in general recommended to refrain from posting spoilers and solution suggestions of any kind, unless answering a specific question. Users who have problems solving a kata can post questions (and usequestion
label for that), or even better, they can ask for help on CW Discord.PHP translation
This comment has been hidden.
An issue is a bug or problem with the kata. This is not an issue.
How does the Author define a triangle here? Are we supposed to use trig?
This comment has been hidden.
Exactly. I don't understand why JAVA has the most poorly written exercises. Python I've not had such issues with.
This comment has been hidden.
don't you think it's too much of a spoiler?
agree, how can I mark it as a spoiler? EDIT doesn't seam to work. thanks
It already is.
suggestions are meant to propose improvements to a kata, not spoil the solution for other users
wait why is 1,2,3---> False? I mean 1,2,2--->True and 4,2,3---> True, then why is 1,2,3--->False ?
Not a kata issue. See https://docs.codewars.com/training/troubleshooting#post-discourse.
if one side is 3, and the othe are added 3 (1+2) you get a line not a triangle
This comment has been hidden.
This comment has been hidden.
I am not sure I understand the problem completely! Why is "4,2,3" expected to be "true" and "1,2,3" false?
Because when you have sticks with lenghts of 2 inches, 3 inches, and 4 inches, you can build a triangle out of them. But you cannot build a real triangle with sticks of lenghts 1 inch, 2 inches, and 3 inches.
This comment has been hidden.
This comment has been hidden.
This comment has been deleted.
This is really a purely worded Kata.
That was a poorly worded
issue
posting.This is a classic property of triangles one would encounter in elementary school, if not, the results are also easily searchable, so not a kata issue! And giving away too much hints will just make the kata a trivial 8kyu anyways.
I would recommend re-writing this Kata as it severely lacks any sort of clarity in the way it was written.
Can you share what parts exactly you find not clear? I am willing to rewrite the kata as much as necessary, but I need to know what exactly are the problems with it.
severely?
... why?
One issue I see is that negative inputs can be surprising: they are not mentioned in description, and solutions which just implement the triangle inequality theorem can get them wrong. IIRC, some languages also have inputs which trigger overflow. At the very least, ranges of inputs should be specified. Otherwise it's just getting surprised on every ATTEMPT with some new type of input.
This comment has been hidden.
The "detailed requirements" part is an outright spoiler tho. It totally strips the problem out of the problem, and all what is left is typing in a bunch of characters. I think it goes too far.
It doesn't make any sense.
can someone tell me why 1,2,9 -> false
Can you draw a triangle with sides of 1, 2, and 9?
This comment has been hidden.
This comment has been hidden.
if all sides are equal, it is Equilateral triangle. so it is still a triangle
wtf is the formula for this xd?? triangle inequity theorem doeswn't work for me...
This comment has been hidden.
TOS are not against my username
because you need explicite rules to become polite...?
This comment has been hidden.
Your code has a bug, not a kata issue.
This comment has been hidden.
kata hint != kata suggestion
This comment has been hidden.
This comment has been hidden.
Added to all languages
How should the solution behave for (-1,-1,-1)?
Does negative triangle count?
No. It should return
false
.Description is awful, the logic for the failing examples doesn't follow the maths for actually calculating a triangle, gave up...
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
approved
Incredibly ambiguous question. Could atleast include an example so we know what youre even asking.
I've added some examples to the description.
Needs more clarification on the triangle logics,if two values are greather that the third, the anouncment should say ISOSCELES TRIANGLE...
That's not true. If two sides are equal and a third one is not, and you can build a triangle with those sides, then yes, it is an isosceles triangle. Having two sides greater than the third one but all with different size, it can be a scalene triangle. The kata asks if you can or can't build a triangle with those lengths, not to classify them.
you're rigth but how we differenciate a escalene from the isosceles on the announcement? that should be mentionated at least to exclude the equilateral triangle and have 2 sides greater that third
Again, why do you need to know which kind of triangle is it? Any triangle is valid, isosceles, scalene or equilateral.
but not according to the acceptable logic of the details, which in this case the equilateral does not apply
answering your question, because the details are too ambiguous, a lot of people thinks the same in other coments, take a look
I don't know where you see that equilateral triangles aren't acceptable. All equilateral triangles with sides greater than 0 have a surface greater than 0.
i'm not saying shouldn't be acceptable mate, but details of the excercise and the aceptable logic of it, makes this resolution hard to understand and solve, as i said, the anounsment (details) of the excersice is too ambiguous, have a nice one my dude =)
Added random tests to Java and moved to JUnit 5
already done
It is not at all clear which sides should or should not be those that are greater than zero. The example indicates that in one case side 2 or 3 is true, and in others it is false. Please clarify the condition of the problem.
But in a triangle, all of its sides should be greater than 0?
"Falsifiable (after 1 test): 2 3 1 expected: False but got: True"
What is it? Who wrote the test for Haskell? The sum of the two sides of a triangle must ALWAYS be greater than the third!
Well, I'd rather blame the one who wrote the solution.
Youc code fails this test case:
isTriangle 100 1 1 `shouldBe` False
I'm sorry, it's really my mistake.
Same.
this is not programming, it is pure math and have no place in the list of katas
It is too abstract, please give more details
This comment has been hidden.
So is your suggestion to improve the kata ^^
This comment has been hidden.
This comment has been hidden.
you are not allowed to give the solution on the Discourse page. a kata suggestion is an proposal to improve a kata
This comment has been hidden.
If you post a solution in the comment don't forget to mark it as spoiler.
This comment has been hidden.
I wasn't exactly understanding what the prompt was even asking for till I read this comment. It was easy after that lol. Thank you!
This comment has been hidden.
Looks like some test cases doesn't work anymore or doesn't check properly. Even looking into solution and trying to paste the solution, returns an error. Unfortunately.
In what language? What exactly is wrong with the tests?
This comment has been hidden.
Re-raising, and re-wording the below issue -
C++ tests have the additional task of dealing with integer overflow. I gave a quick eyeball through the other translations, they don't, or at least nearly none of them do (if I missed something)
it's the same kata, C++ shouldn't artificially add additional tasks unless the language requires it in order to solve the same problem - which it does not in any way do.
removed the fixed tests with very large int32 and lowered the RNG range
This comment has been hidden.
Context: Duncon Wood's last used language is C++, so presumably that's what they're talking about.
You don't have to. The inputs do fit into int. It's what you're doing that doesn't. And you don't need to do it that way.
However. It's questionable that some translations should have the burden of dealing with overflow when others don't. I do agree that is an issue.
The way you solved the kata is up to you. Tests are correct, and this is not a kata issue. Each language has its features and one must cope with it.
technically correct, that doesn't mean there isn't an issue here
the cpp version intentionally makes people run into this. the haskell one doesn't. is it the same kata or not? that's not how it should be. it's not a difference in language either, it's a difference in what the tests choose to assert, it's a difference in what the user is asked to do.
the description doesn't mention limits on input, what's the original intent? how does this rhyme with it being a 7 kyu kata?
Thank you for the response, I just haven't encountered another kata where I needed to change the given function template for the tests to pass. I understand that this is a good practice for dealing with edge cases though, and I will continue to practice C++!
This comment has been hidden.
Please don't give hints and let people solve the kata by themselves. This is not a suggestion (=suggestion of improvement of the kata).
Ugh this kata fails at math.
As I was not a maths major, can you please explain what you mean? Thank you in advance.
I rescind my comment, it is I who fails at math.
This comment has been hidden.
Which language?
I like this kata but the test cases somehow misleading. I would expect from the solvers to handle the situations properly when the side length valuas are not valid length values so less or equal than zero especially this case: (0,0,0) and (-2,-2,-2).
for now I feel like all the kata are hard, the 8kyu is hard and then it just be more harder in less kyu, but easy, I dont think there is a one I saw for now can be called easy.Am I the only one who felt like this?
Is this kata really an easy level??
This kata doesn't make sense at all.
Why?
This comment has been hidden.
Your logic is wrong, possibly in multiple places. For example, your first line:
does not do what I think you think it does.
All by itself,
if a
meansif a is not zero
, so this line of code is wrong because it Python immediately stops evaluating anything else in that line and returnsFalse
ifa
is non-zero, resulting in your code failing on the very first test.You will likely have to check the logic in a similar way on all remaining lines. I am not sure because I didn't go past that one line to give you an example of what needs to be fixed.
Good luck!
This comment has been hidden.
Nice explanation buddy but what do i have to do?
Which part of the description eludes you?
This comment has been hidden.
If this were a 8kyu, perhaps that sentence could be added. But this is 7kyu, you should be able to figure this out without a description update.
Iam a teacher of history. i dont give a sht about all that geometry stuff.
I bet you talk to us the way your students talk to you ;)
sory bro English is not my language. iam sorry if i was rude or stupid. iam more like humanitarian guy, math and geometry are not my strongest sides
This comment has been hidden.
kata hint != kata suggestion (also, spoiler flag)
Given some of the tests thrown, it should be longs instead of ints
Please specify language.
There is no example output to explain the criteria of the kata
Now there is.
This comment has been hidden.
But now we know how to sum the sides of a triangle.
C translation (author gone)
Approved
A triangle is a triangle if Pythagoras is true but it's not in this kata
Nope. Try drawing this triangle on paper
[2,2,3]
. It should create a valid triangle, even though the three sides can't be applied to pythagoras.The Pythagoras rule applies to Right angle triangles, but this kata is about any triangles.
This comment has been hidden.
The description states:
A degenerate triangle is a line segment which has no area. Whether to include those as valid triangles depends on the use case. In the case of this kata, they are not, and changing that would invalidate thousands of solutions.
I just learned how to make triangles
bro i dont even know our main goals on this kata :/
This comment has been hidden.
Bad kata
Learnt a lot about triangles, thanks :)
This comment has been hidden.
the tests in js do not operate the way you are perceiving, those tests are valid, so you are most likely just misreading the logs
This comment has been hidden.
There are random tests with negative values that don't add to 0.
Agreed, the description should mention this, since negative lengths are meaningless.
This comment has been hidden.
This comment has been hidden.
The tests are fine, why do you say they're not?
You're not doing that.
This comment has been hidden.
The kata states that the area must be greater than zero, so you should be using greater-than, not greater than or equal to.
This comment has been hidden.
Thanks for the hint 😁...save me time
You're a legend
It would be great if the formular was given in the description. Instead i had to look in the internet what the formular is lol.
It would be nice to indicate in the description that negative numbers may be present in the incoming data. The example itself is quite simple, but the paucity of the description is slightly annoying.
This comment has been hidden.
kata hint != kata suggestion
How can there be a triangle with a negative side? Tests require you to return true. Maybe I don't understand something?
Try: 947475225,-20904549,1708642918
Try: 1959134538,-122057015,771594386
Try: 38404172,-42716421,1297137250
Try: 1981844293,1900815050,582146936
Expected: true
Actual: false
The last one of those is the one your code fails.
My python code works correctly, but in C++ it gives an error, although everything is the same there. I don't understand what the problem is :(
It's because integer overflow, read this: https://www.codewars.com/kata/56606694ec01347ce800001b/discuss#618f3e8aed578d000ec17a23
Thanks for the help. I've already figured it out🙏
if you read the question very well, it says the inputs will be greater than zero which is positive
It doesn't say that:
This comment section is filled with drama and I love it. haha
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
kata hint != kata suggestion
There are too many "test" triangles that state they should be true when they are not. According to pythagorean theorum (a^2 + b^2 = c^2), A triangle cannot have to hypotenuses (2 large sides that are equal and 1 small) meaning the triangle 1,2,2 should not be possible. There were also a couple other test triangles that did not satisfy the theorum but claimed to be true when they were not (like 7,2,2)
That theorem is only for triangles with a 90 degrees angle (right triangles), not for all triangles. Source
This comment has been hidden.
I can't believe anyone could think this is advanced maths. This is basic geometry.
couldn't agree more... absolutely rightly put.
This comment has been hidden.
worded my attempts based on Pythagoras' thm and Cosine rule, but did not arrive at an adequate solution (passed only some tests). learnt something new today (or maybe a reminder to review basic geometry? hmm)
Draw it! A triangle with sides 7,2,2 is not possible. Try drawing and you'll see.
(-2,6,6) is telling me it should be false but my result is giving me a positive number
its the only error im getting. any help appreciated
This comment has been hidden.
The solution for this kata is true for all types of triangles.
Not true. Try building a triangle with sides 10, 1 and 1.
Ah okay thanks! Guess I need a refresher on geometry, it's been a minute XD
We could've elaborated on the qualifying validity of the triangle; on the other hand, you often need to look stuff/rules up anyway.
the most useless katas I've ever done
The most useless katas you've ever done... so far!
Not to be pedantic or anything but, according to your kata history, you've already solved Number of trailing zeros of N! which I would argue is actually the most useless kata you've ever done.
You say that until you want to make a triangle and try using popsicle sticks of different lengths just to find out they wont work.........
i'm so sick of those stupid katas that doesent even have a fkg example of correct results and decent description
This comment has been hidden.
Yeah i get your point, but:
"I don't know the formula so I need to find it" is one of the logical chains which can be learnt while solving this kata.
That's not generally true. As a programmer, you usually need to be familiar with the domain your software is bound to. When you work on banking software, you need to be familiar with accounting. When you work on sound processing software, you need to be familiar with music theory, signal processing, and sound engineering. When you work on online bookstore, you need to be familiar with trading mechanisms, delivery methods, and publishing. When you solve a problem related to triangles, you need to be familiar with triangles.
Software almost always is used to solve problems occuring in some domain. To do your programming job well, you need to know the domain. Without learnign and knowing the domain, it's difficult to be a programmer, let alone a good programmer.
It's not a problem with the kata.
One more tme since you don't get it... you don't follow my logic
I don't know the formula so I need to find it" is one of the logical chains which can be learnt while solving this kata.
I am here to learn how to work with: variables, arrays, objects, built in methods and functions ... etc, use logic how to solve the problem with all (JS) tools.
Code Wars === not math wars, not thermodynamic laws and etc... It's all about coding abilities and hone your "Fundamental" in (JS language in my case) with solving kata's.
But we have this kata here which need, google the math formula for triangle to solve it, and use code abilities to wrtire 5-symbols... At the end of solving this kata i get such results to my knowledge:
Math += 1;
JS += 0;
Time wasted on looking for the formula.
Sum up = losed time and learned one math formula, plus to coding = 0;
I don't mind kata's that have math formulas, but i need it in the description, to stay focused only on
coding
and google onlycoding stuff
, to upgrade mycoding skills
.I was wondering to myself who could get so mad when required to simply google "what is a triangle" - the answer: of course, a JavaScript person
@Overhand Have you considered that even though you might detest having to solve anything that requires knowledge other than pure JS, other people might enjoy it. If you look at the satisfaction rating, 4 out of 5 people who have solved this kata enjoyed it! And finally, no one is forcing you to solve this kind of kata, if you see a kata which requires you to look up a formula, why not just find a different kata?
I don't know how to talk with you guys... I have a feeling like you made out of wood
@benjaminzwhite and @Kacarott and others, againts what you are fighting? To make kata descriptions better and that it should contain all info? I don't understand you
just will leave a citate from "About" site docs
Codewars
Codewars is a platform that helps you learn, train, and improve your
coding skills
by solvingprogramming tasks
of many types and difficulty levels. You choose how you would like to learn. Do you want to take on increasingly difficult challenges? Maybe you prefer training through repetition and by improving your solutions. After solving a task, compare your answer with other users and learn from them or help less experienced users by answering their questions.I don't care how hard or easy kata can be, but description need to have all of the infomation and that's that. If description doesen't have all of the information kata should be removed.
I agree with Overhand that a description should be complete. However, trivial domain knowledge should not be explained specifically, unless the domain itself is already very complex.
@Overhand - no one is "fighting against" anything; your initial comment was "i'm so sick of those stupid katas that doesent even have a fkg example of correct results and decent description". Why do you think you should get a positive reply to such a low-effort comment?
Everyone agrees that "descriptions should be good" - it's self-evident - but what we disagree with is the concrete implementation i.e. "how much baseline/common knowledge should we expect a typical programmer to have".
You yourself don't seem to offer a concrete criterion for what you mean when you say "description need to have all of the infomation and that's that".
So here is a concrete question to determine what you think "all of the information" should be:
If you were the author of this kata and decided not to define any of these words: {function, implement, integer, triangle, sides, length, surface} and I wrote in your discourse page "why isn't triangle defined? why isn't length defined? etc. etc." - what would your reply be?
The feeling slowly becomes kind of mutual, actually.
The description is (or, at least, seems to me to be) complete with regard to statement of a problem a user has to solve. Requrements are described (maybe with exception of some tricky inputs, like negative ones), and the problem which has to be solved is stated quite explicitly.
What is not present in the description is explanation how to solve the problem. And this is usually acceptable because, arguably, if it would explain how to solve the problem, there would be nothing more to solve. The task would be solved already. When you look at many other kata, like "find an exit from a maze", or "reverse a string", none of the kata explains how to find an exit or how to reverse a string. The "how" is, in most cases, left for the user to figure out. Because, surprise surprise, it's users who have to solve the problem first, and then write a code which implements the solution.
You still seem to strip the problem solving out of the "problem", and all what is left is writing code. This is a severe oversimplification, because programming is not just writing code. To write a code, you have to figure out how to solve your task. It's not a very common situation to be exactly told what and how to code, in majority of cases programmers are presented with a problem to solve, and not with a code to write or algorithm to implement.
I agree that description could be improved because it does not mention negative inputs. It can be argued that examples should be added. But having a bluntly presented formula or an algorithm is considered not always necessary, especially for domains which are considered common knowledge or close to trivial.
you definitely sound like a cry baby. You made a gutter comment and you trying to play the victim here. Come on your act and your defence is terrible.
This comment has been hidden.
Can anyone help interpret the last test (ChangingSidesTest). I don´t exactly know what that means. Can somebody explain that in different words so I can try to fix my code? Thanks
I added some info to assertion mesages, please check if it's easier for you now to debug your solution.
Scala translation
.
This comment has been hidden.
Both of those are in this line:
Do you mean there are some tests that expect another thing? In which language?
Yes, some tests do not follow these rules. To pass the kata I had to change my solution, because tests form triangles with 0-sides and negative sides (what?)
Javascript language.
That's the point, if some side value is 0 (because of what I quoted before) or is negative it isn't a triangle and those tests expect
false
. Not a kata issue.This comment has been hidden.
invalid triangle? can you define what is invalid triangle?
This comment has been hidden.
hahaha...
it seems that [1,2,3] should be True
#11b39/3qf:0z:vV
visualise that triangle or draw it. you would end up with a flat line not a triangle
This comment has been hidden.
Do such triangles exist? (-1,2,3). 'Math' does not exist in the current context
Obviously sides of a triangle cannot be negative. If you faced with this, there is an issue in the tests (it is possible).
The problem is you forgot:
using System;
can pass all tests need a bit attentive
You just need to learn some laws of triangle world.
teach me
This comment has been hidden.
Nothing to fix.
This comment has been hidden.
Your code returnrs true for a = 100, b = 1 and c = 1.
Oh, thank you! Did not notice that. Just fixed it.
This comment has been hidden.
This comment has been hidden.
Please don't post "solutions" - even if it's not code, it's basically a hint so obvious that it solves the kata.
If you want to make comments like this, you can use the spoiler tag when you post comments (see box below the text box "Mark as having spoiler content").
It doesn't seem to compile at all in TypeScript. Error TS6053.
That was a problem with the sample tests, either delete the first two lines or backup your code and click Reset.
Cheers, that solved it.
This comment has been hidden.
HINT: To solve this, research how triangles can be built with 3 sides.
Before people say this is some kind of spoiler: I just recycled the descriptions content to help understand. The focus of katas shouldn't be math but coding. Without knowing the math, coding won't get you anywhere here.
With that: Please explain the math. Otherwise, people like me, who haven't learnt stuff like this in school yet, have to look it up online and find the missing information to continue.
Thank you :). I recognized something was off
someone give this person a cookie
give em two cookies
Thanks, this was really helpful, I was confused with Pythagoras theorem. xD
The thing is, that's part of the thought process and googling is a way to learn (And if you are into coding, you should have some basic knowledge in math at least) so closing this one
This comment has been hidden.
i'm gonna add a spoiler flag, as this basically gives away the solution
you don't need to comment on discourse to give out blatant hints
part of the fun of using the site is to arrive at the answer on your own ;)
p.s this isn't a hint, its the solution
Not everybody is into math, just take a look at the comments below, a lot of them point about the abstractness of the question, this question deserves that hint.
I think you are confused between a hint and solution. Goodluck :)
one still need to come up with logic to implement all the things I mentioned in the hint. Thanks for your biased opinion anyway!
i dont really understand this question
really nice kata, once you figure it out it makes sense
This kata bewildered me. No pretext about triangle lengths. How do you expect programmers to know this type of stuff?
I don't understand how some of these tests are not triangles (aka return false). A triangle with sides 7, 2, 2 (in one of the JS test cases) is totally possible in real life. So...what exactly is their definition of a triangle in this kata?
No. If you really doubt it, try to draw it.
This comment has been hidden.
kata hint != kata suggestion
I think that you may have misunderstood my message.
To be clear, I made a suggestion saying that it would nice to have, in the kata description, a hint like the one I mentioned.
This comment has been hidden.
I answered you below.
Excuse me for double post, i didn't notice that.
How can be triangle with 1,2,2 sides is true? With legs 1 and 2 hypot is 2.24
You're reasoning with right triangles only.
There is a mistake. This solution can accept float values!
Interesting, did not think of float values... It gives you an error when you input floating point values?
I can
t understand what
s reason for returning FALSE answer ?the problem expects us to use the triangle inequality, but it does not guarantee that a triangle with these means can be formed, but that if the triangle already exists, the measures of the sides respect the triangle inequality rule
This comment has been hidden.
What do you mean by the triangle already exists ? Are we not testing if the triangle could exist in our algo ? Sorry, I'm not fully understanding your question
Unclear issue. The task is clear.
case for all variants on inequality of triangles
Ahhh, nothing better than shit descripted Kata early in the morning!!
This comment has been hidden.
interesting !!
This comment has been hidden.
This comment has been hidden.
very poorly scripted.
This is a bit easier to figure out that the code wars problem regarding interest and taxes on a initial principal
This comment has been hidden.
kata hint != kata suggestion
like someone else said below, for c++ if u are getting errors for big numbers, probably use long
Not a suggestion.
This comment has been hidden.
A line is not a triangle, under the following condition at least:
That's fine, what's your issue about?
About your other question, once it got a reply you can't edit it. I've tried to delete the posts but I could delete this one. So, it'll remain.
A line is not a triangle
Well, abslolutely speaking, it's not that clear: https://en.wikipedia.org/wiki/Triangle#Existence_of_a_triangle
But this kata makes the assumption that three collinear points don't form a triangle, as implies a surface greater than 0, it's not an aberration either.
Edited it. Still, I refuse to call a line a triangle, even a degenerate one :P
COBOL translation (author inactive).
approved
The parameter for initial solution setup in C++ should be
long
No. All the inputs are in
int
range, and tests expect you to properly handle possible overflow.expected false to equal true What does it mean? Should I return false at any case?
Read this: https://docs.codewars.com/training/troubleshooting#print-input
I got it. Any two numbers must be bigger then the third.
This comment has been hidden.
This comment has been hidden.
Does it pass the tests? There's your answer.
How can the lengths be negative?
They can't, if it's a valid triangle. If you're talking about a specific case returning a result you don't expect, make sure you're looking at the correct result.
Ah ok so those are bad inputs. Got it, thanks.
This comment has been hidden.
This comment has been hidden.
Java tests are fine. Troubleshooting-your-solution.
A 2-3-4 triangle
Yes, sorry for my bad knowledge in geometry lmao. Now I understood I applied the logic wrongly. Thanks for the hints.
I would suggest adding the formula to the description of the kata. Or at least a hint regarding triangle theory.
I knew that I got this foruma somewhere in my head, when I was at school 25 years ago. But it was really easy to find it in searcher. Took me about 3 minutes to find just math pattern.
This comment has been hidden.
Given that definition, no, it's not.
This question is a bit confusing in its instructions. But, once you find out that it is a triangle inequality test it becomes very simple, i think it had to be stated in the instructions. Anyway, it's a good Kata for beginners like me, though.
Thank you! I didn´t know about this, and I didn´t know how to look for it.
The description needs to state that the problem can be easily solved using triangle inequality, otherwise this kata is testing knowledge of geometry
thanks for the comment, I was pretty confused before I checked the comments
sTriangle_ValidPostiveNumbers_ReturnsTrue Test Failed Expected: True But was: False
this is the only error i have from all 10 run test. what could go wrong?
is it me or does the question make no sense?
It has 79k solutions, maybe it's you. What's what you're not understanding of it?
I got it, the question shoudl really mention it has to do with triangle inequality. not made too clear
I agree that this problem is lacking a bit in explanation. It necessitates too much knowledge on the mathematical properties of a triangle. I would love to have a bit more information included in the explanation, or at least include a bit more description of the intended task
It's one of the basics of geometry, nothing too much.
i have no idea what the question is asking for
This comment has been hidden.
kata hint != kata suggestion
This comment has been hidden.
update, I sloved it but my solution is absolute crap compared to everyone else.
this is ridiculous, I have made a formula to calculate the area but i get 5 wrong??? even though the test went successfully with 0 wrong!
Well the sample tests might not fully cover the edge cases or random cases, so what error you've encountered and in what language?
No answer after 3 weeks, 26k solutions in Python, closing.
any athor solutions
This comment has been hidden.
Not a suggestion.
This one doesn't make much sense. How can a triangle be built with 3 integers of different lengths? I'm assuming that I just don't understand what the question is asking.
The three integers represent the length of each side. You can play with some rubber band and see for yourself how that's possible.
triangle inequality theorem,but i used that and it still didnt
How can be a triangle with sides 7,2,2??????
It can't. That's why that test expects
False
I need someone to explain why a triangle can't have 7, 2, 2 lengths.
Maybe the other way round: could you explain how to create, or ideally draw, a triangle which has sides of lenghts 7, 2, and 2?
This comment has been hidden.
oh thanks for that hint had no idea how to do this one
That's really it - it's not a coding problem - more of a theorom question.
op tip .lol
This comment has been hidden.
At least for C#, the test cases include tests with negative numbers, and those should return false.
If the version in the language you code in does not have such a test, that is an issue with that translation.
Thanks for the reply! I already was able to solve the kata. I was just wondering that, since the kata description includes "In this case, all triangles must have surface greater than 0 to be accepted" and i didn't do anything about this, but was still able to pass all the tests, what does it mean?
This comment has been hidden.
There are tests with negative values in Python, and the control function would return False for that input. Are you saying there are solutions that need to be revalidated?
the question does not give me much to go about
Any side lengths that are not 0 allow for a constructable triangle; The description of the problem is wrong.
Really? How do you make a triangle with sides 10, 2 and 1?
It has probably to do with language. In my language (and I thought english as well) a triangle is any figure with three straight lines as sides. However this kata means a right triangle, a triangle where one of the angles is 90 degrees. So even after all these people has solved it I would agree that the description should be updated.
No, it means any triangle. The sides can't be any length tho, because they should form a triangle.
You're right :-)
Hey, you would be able to construct it using non-euclidian geometry. If you are interested I can show you what a constructed version for the lengths you suggested would look like.
Edit: It is even possible to construct a triangle with angles between each side with more than 180°
Sorry, but even if it is implied, you work with Euclidean geometry in this kata. That being said, show me, I'm curious.
I was mostly taking a jab on how vague the description is. You should either mention that it is using euclidian geometry or give the definition for a constructable triangle.
This would be a triangle with the lengths 10,2,1: https://i.imgur.com/ei2rdWd.png I am not sure how to visualise the planes with the software I used, but even if they aren't arbitrary in this case, you could just choose arbitrary planes (imagine drawing a straight line over a mountain, then connecting both ends of the line to a point that is on a flat surface nearby).
This comment has been hidden.
kata hint != kata suggestion ~~
I am new here, but thanks
No random tests in
forks available:
C#
Java
F# translation
What is this question even asking? This description is terrible
Agreed. Description is terrible if you are not familiar or don't recall "Triangle Inequality Theorem" from math class.
It should briefly explain Triangle Inequality Theorem in the desc.
Crystal translation
Julia translation
R translation
(author inactive)
^^
This comment has been hidden.
hey :)
I tried using pythagorean theorem which states that c^2 = a^2 + b^2. however it's not covering some of the test scenarios example: (1,2,2) 4 == 1 + 4 which is obviously false but the scenario expects it to be true.. thanks in advance if someone can explain! :)
The question is whether there exists a triangle with sides (a,b,c), but it doesn't need to be a right triangle. In this case, (1,2,2) is an isosceles triangle so you should return true
ahh i see, now i get it.. thank you! :)
The pythagorean theorem only applies to right triangles.
This comment has been hidden.
You are apparently missing the fact that you can make a triangle with sides of 5, 7 and 10 units.
This comment has been hidden.
YAMTFT the kata is not only about pythagorean triangles.
Thanks for the tip, got it now. Late night hours for coding fun = not thinking out of the box...
With all due respect, this is a math problem, not a coding problem.
With all due respect, how do you separate a math problem from a coding problem?
I initially thought you'd need to know some specific formula to figure this one out, but realised addition and logic is the only math necessary for solving this.
https://www.calculator.net/triangle-calculator.html Try 7,2,2 with no degree on this website. I think you will get the idea.
It's both. The description is horrible unless you recall Triangle Inequality Theorem.
This kata should be scrapped unless the description is updated. If the author simply explained that theorem, new coders can focus on how to implement it in code.
The point should not be about trying to discover a math theorem from from scratch.
This is what i meant to say, and shouldn't have tried to phrase it in a clever way. My issue could be address by simply summarizing the theorem in the description.
The kata becomes fairly
This comment has been hidden.
This comment has been hidden.
My bad, I am just kinda dumb and forgot to put ":"
yes that should work.
Swift translation added - https://www.codewars.com/kumite/5f68e1598a3830002fc6564a
Passing all testcases but getting a runtime error:
main.cpp:15:3: warning: control may reach end of non-void function [-Wreturn-type] } ^ 1 warning generated. main.cpp:7:8: runtime error: execution reached the end of a value-returning function without returning a value
Not an issue. That's your solution.
It's not run time, it's compilation time, and it's not error, it's a warning. Also, it originates from your solution, you can fix it by yourself.
Not a kata issue.
okay thanks
so I've passed 15 test but failed the first one in "test:2". How can I see the test my function was given? I tried to console.log(isTriangle()); but nothing.
Inside your function:
console.log(a, b, c);
it'll appear above the test result.I tried that, seems like nothing is appearing above test results. I'm on mobile would this have an affect?
This comment has been hidden.
This comment has been hidden.
With the picture in description, it is to easy for 7 kyu.
have written my code correctly the input is given as (1,2,2) which is not a triangle but expected output is True but my code correctly produce False for that but it shows testcase fail input with expected output is worng
How do you know you have written your code correctly?
Not enough information supplied, almost 20k python completions, and not a suggestion... Rather a question.
Maybe you're reading the logs incorrectly. Assertion messages come AFTER your inputs.
And why do you say that you can't make a triangle with those sides?
triangle rule is that al 3 sides will be equal
no, this kata accepts triangles of varied side lengths.
(1,2,2)
forms an isosceles triangle, for exampleAdded picture in description. Hopes that helps.
Isn't that too much information?
When solving the kata in C++, two of the test cases included long int, which automatically prevents the kata from passing since the default parameters of the function itself is only int.
But how does it prevent kata from passing? That's not really true, kata is perfectly solvable.
It prevented the kata from passing for me because it kept failing the one test case in which the input int was high. It was only when I changed the input parameter from int to long int that it finally passed. I did not change anythinge else in my code.
You encountered the case which causes too naive solutions to overflow. There is a couple of possible ways to handle such situation, and changing the function signature, is, well... one of them, but IMO kata should not allow it. But it does, so if you used it and it worked, then good for you! But it's not the only possible way. And this is perfectly vald situation, kata is not broken in any way.
Most of the solutions I have read, including the most voted one, won't take into account that one of the sides could be a negative number. This would allow the triangle surface to be 0. Kata statement leaves this as a possibility as it doesn't explicitly deny it.
What math book allows negative lengths for the sides of a triangle?
This comment has been hidden.
Not a kata suggestion, don't post solutions in kata discourse, it's forbidden.
This comment has been hidden.
I have made a program to check whether triangles or not with many experiments in C ++ and it works, but ONLY with this one I have a problem because it should return a false value: 1403036012; 1310259536; 186811493. But why do you expect this to be a false value? Do any of your programs return that value as true? thank you.
consider data types in your calculations
This comment has been hidden.
the C++ version used to require handling overflow of 32-bit ints, which was not in scope of a 7-kyu kata. your solution passes the tests now.
So one of the inputs ([4, 9, 16]) is supposed to be false but output expects true. 4, 9, and 16 cannot make a triangle; it's practically impossible. Please fix this!
There is no such test in Javascript (the only language you've trained so far, when reporting an issue, please, mention which language you're talking about if the kata has more than one), neither in sample nor final tests.
This comment has been hidden.
please do not post code without the spoiler tag (I have added the tag)
FYI 1) you're not creating a dictionary with what you assigned to a
dict
(you actually created a set), FYI 2) don't assign anything to reserved words such asdict
This comment has been hidden.
Print the input, see what's wrong with your code.
This comment has been hidden.
Hi guys , all of my sample test are passed but when i click on attempt it says 3 failed task,it aslo says failed in test1 ,can you pls tell me where i can ses the spefictic test1??
here's a nice way to print inputs for this kata:
Hi, guys! Does anybody know why it wasn't added my second solution in the list of all solutions?
Solutions may be cached especially when the grouping of your solution is large. Such issues have already been raised in Github repo.
Is it possible to see all the tests ? I've got majority of them passing but few are still failing and can't see what it is testing so I can edit my solution.
Yes, you can print the input.
Test in this challenge:
Test.assertEquals(isTriangle(7,2,2), false);
I don't understand why it expects false instead of true ??? If I understand this challenge correctly, I'm supposed to return false only when either side of the triangle is 0 or sum of all sides will result in 0. Did I get this right ?
just try to visualize a triangle with sides of lengths 7, 2, and 2
OK, I get it the sides with lengths 2 and 2 would never meet ergo it can't be a triangle.
This comment has been hidden.
This comment has been hidden.
Reraised above with more detail
This comment has been hidden.
This comment has been hidden.
I think some limit cases in C++ were out of 'int' range. So can we manipulate the fn. declaration?
Obviously, if a function accepts
int
s, the arguments can't be out ofint
range, but there can be overflows in solutions. I don't know how appropriate including tests withstd::numeric_limits<int>::max()
is for a 7 kyu kata, but I consider either option correct; it's kata author's fault that the input range is unspecified.Is this a triangle? 🦋👀
I did it right how do you get the points
This comment has been hidden.
I get an exit code: 132, does someone know what does it mean?
This comment has been hidden.
Please mention in what language you're having this problem. Help us help you.
Closing.
(Haskell) These additional 2 tests will break a lot of existing staightforward solutions because of overflow and underflow behavior for Int:
The intent of the kata is not to guard against overflow of native datatypes. This is a 7kyu kata.
Closing.
I'm getting 9 out of 10 tests passed, except for IsAllSidesPositive test. I have concluded that as humans we are not perfect, so Code Ninja has a bug in there code.
Java: Not working. I created a function that returns only true. Grtting an error that expected true but was false.
Actual and Expected were flipped in Sample tests only, click Reset and try again.
All you need to know, and just use comparison operators for fastest efficiency: https://sciencing.com/rules-length-triangle-sides-8606207.html
Beautiful. I couldn't figure out if these were supposed to somehow indicate coordinates but this clarifies my confusion I think
Triangle Inequality Theorem with chained conditionals, everything must be true.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
That's not a kata issue, and mark your post as having spoiler content, you're giving away the solution. Use Question label next time, a comparison gives you a boolean and that's a combination of booleans, that also gives you a boolean.
sorry, for the mistake with the labeling! and thank you very much for your help!
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
OP solved it, closing
My (inelegant) solution would have worked fine if it wasn't for the tests designed to cause integer overflow. How do you handle that while still giving correct results?
By using a bigger data type? ;-)
You can change data type like this bool isTriangle(long a, long b, long c)
I didn't understand the problem at first but this helped :) http://www.summithill.org/FileUploads/TeacherFiles/DeterminingifaTriangleispossible_12_4_2013_9_46_18_AM.ppt