Determine type of triangle





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















I'm trying the hacker rank type of triangle below where based on the 3 sides it has to be determined if the triangle is equilateral, isosceles, scaelene, or not a triangle.



https://www.hackerrank.com/challenges/what-type-of-triangle/problem



I'm not sure why the code below isn't passing the test case. Unfortunately, I can't download the test case to see why it isn't working.



SELECT CASE WHEN A = B AND B = C AND A = C THEN 'Equilateral' 
WHEN (A = B AND B != C AND A != C) OR (B = C AND A != B AND A != C) OR (A = C AND A != B AND B != C) THEN 'Isosceles'
WHEN ((A + B) < C) OR ((B + C) < A) OR ((C + A) < B) THEN 'Not a triangle'
ELSE 'Scalene' END
FROM Triangles









share|improve this question























  • I changed it to 'Not A Triangle', but it's still giving an error.

    – rds80
    Nov 24 '18 at 4:32











  • ((A + B) < C) should be ((A + B) <= C) etc.

    – Nick
    Nov 24 '18 at 4:36











  • the test case still errors out after making the change

    – rds80
    Nov 24 '18 at 4:38






  • 1





    Your problem is that your code will return Isosceles for e.g. A=5 B=5 C=20 when that is not actually a triangle. Either of the answers below will fix it for you.

    – Nick
    Nov 24 '18 at 4:42













  • Thanks. Missed that use case..

    – rds80
    Nov 24 '18 at 4:44


















0















I'm trying the hacker rank type of triangle below where based on the 3 sides it has to be determined if the triangle is equilateral, isosceles, scaelene, or not a triangle.



https://www.hackerrank.com/challenges/what-type-of-triangle/problem



I'm not sure why the code below isn't passing the test case. Unfortunately, I can't download the test case to see why it isn't working.



SELECT CASE WHEN A = B AND B = C AND A = C THEN 'Equilateral' 
WHEN (A = B AND B != C AND A != C) OR (B = C AND A != B AND A != C) OR (A = C AND A != B AND B != C) THEN 'Isosceles'
WHEN ((A + B) < C) OR ((B + C) < A) OR ((C + A) < B) THEN 'Not a triangle'
ELSE 'Scalene' END
FROM Triangles









share|improve this question























  • I changed it to 'Not A Triangle', but it's still giving an error.

    – rds80
    Nov 24 '18 at 4:32











  • ((A + B) < C) should be ((A + B) <= C) etc.

    – Nick
    Nov 24 '18 at 4:36











  • the test case still errors out after making the change

    – rds80
    Nov 24 '18 at 4:38






  • 1





    Your problem is that your code will return Isosceles for e.g. A=5 B=5 C=20 when that is not actually a triangle. Either of the answers below will fix it for you.

    – Nick
    Nov 24 '18 at 4:42













  • Thanks. Missed that use case..

    – rds80
    Nov 24 '18 at 4:44














0












0








0








I'm trying the hacker rank type of triangle below where based on the 3 sides it has to be determined if the triangle is equilateral, isosceles, scaelene, or not a triangle.



https://www.hackerrank.com/challenges/what-type-of-triangle/problem



I'm not sure why the code below isn't passing the test case. Unfortunately, I can't download the test case to see why it isn't working.



SELECT CASE WHEN A = B AND B = C AND A = C THEN 'Equilateral' 
WHEN (A = B AND B != C AND A != C) OR (B = C AND A != B AND A != C) OR (A = C AND A != B AND B != C) THEN 'Isosceles'
WHEN ((A + B) < C) OR ((B + C) < A) OR ((C + A) < B) THEN 'Not a triangle'
ELSE 'Scalene' END
FROM Triangles









share|improve this question














I'm trying the hacker rank type of triangle below where based on the 3 sides it has to be determined if the triangle is equilateral, isosceles, scaelene, or not a triangle.



https://www.hackerrank.com/challenges/what-type-of-triangle/problem



I'm not sure why the code below isn't passing the test case. Unfortunately, I can't download the test case to see why it isn't working.



SELECT CASE WHEN A = B AND B = C AND A = C THEN 'Equilateral' 
WHEN (A = B AND B != C AND A != C) OR (B = C AND A != B AND A != C) OR (A = C AND A != B AND B != C) THEN 'Isosceles'
WHEN ((A + B) < C) OR ((B + C) < A) OR ((C + A) < B) THEN 'Not a triangle'
ELSE 'Scalene' END
FROM Triangles






sql sql-server sql-server-2012






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 24 '18 at 3:50









rds80rds80

1469




1469













  • I changed it to 'Not A Triangle', but it's still giving an error.

    – rds80
    Nov 24 '18 at 4:32











  • ((A + B) < C) should be ((A + B) <= C) etc.

    – Nick
    Nov 24 '18 at 4:36











  • the test case still errors out after making the change

    – rds80
    Nov 24 '18 at 4:38






  • 1





    Your problem is that your code will return Isosceles for e.g. A=5 B=5 C=20 when that is not actually a triangle. Either of the answers below will fix it for you.

    – Nick
    Nov 24 '18 at 4:42













  • Thanks. Missed that use case..

    – rds80
    Nov 24 '18 at 4:44



















  • I changed it to 'Not A Triangle', but it's still giving an error.

    – rds80
    Nov 24 '18 at 4:32











  • ((A + B) < C) should be ((A + B) <= C) etc.

    – Nick
    Nov 24 '18 at 4:36











  • the test case still errors out after making the change

    – rds80
    Nov 24 '18 at 4:38






  • 1





    Your problem is that your code will return Isosceles for e.g. A=5 B=5 C=20 when that is not actually a triangle. Either of the answers below will fix it for you.

    – Nick
    Nov 24 '18 at 4:42













  • Thanks. Missed that use case..

    – rds80
    Nov 24 '18 at 4:44

















I changed it to 'Not A Triangle', but it's still giving an error.

– rds80
Nov 24 '18 at 4:32





I changed it to 'Not A Triangle', but it's still giving an error.

– rds80
Nov 24 '18 at 4:32













((A + B) < C) should be ((A + B) <= C) etc.

– Nick
Nov 24 '18 at 4:36





((A + B) < C) should be ((A + B) <= C) etc.

– Nick
Nov 24 '18 at 4:36













the test case still errors out after making the change

– rds80
Nov 24 '18 at 4:38





the test case still errors out after making the change

– rds80
Nov 24 '18 at 4:38




1




1





Your problem is that your code will return Isosceles for e.g. A=5 B=5 C=20 when that is not actually a triangle. Either of the answers below will fix it for you.

– Nick
Nov 24 '18 at 4:42







Your problem is that your code will return Isosceles for e.g. A=5 B=5 C=20 when that is not actually a triangle. Either of the answers below will fix it for you.

– Nick
Nov 24 '18 at 4:42















Thanks. Missed that use case..

– rds80
Nov 24 '18 at 4:44





Thanks. Missed that use case..

– rds80
Nov 24 '18 at 4:44












2 Answers
2






active

oldest

votes


















2














Try something like this:



SELECT 
CASE
WHEN A + B > C AND A + C > B AND B + C > A THEN
CASE
WHEN A = B AND B = C THEN 'Equilateral'
WHEN A = B OR B = C OR A = C THEN 'Isosceles'
ELSE 'Scalene' END
ELSE 'Not A Triangle' END
FROM TRIANGLES


Only test for the type of triangle when it is a triangle.






share|improve this answer
























  • I saw this as an answer from another post. But I don't understand why the code I wrote doesn't work.

    – rds80
    Nov 24 '18 at 4:35






  • 1





    Beause, you are not checking for the condition of whether it is a triangle before declaring it as Scalene

    – Jonathan Van Dam
    Nov 24 '18 at 4:36






  • 2





    @JonathanVanDam actually he's not checking if it's a triangle before calling it Isosceles

    – Nick
    Nov 24 '18 at 4:43











  • Thanks @Nick I misspoke on that.

    – Jonathan Van Dam
    Nov 24 '18 at 4:46



















2














Try this :



SELECT CASE WHEN A + B > C AND A+C>B AND B+C>A THEN 
CASE WHEN A = B AND B = C THEN 'Equilateral'
WHEN A = B OR B = C OR A = C THEN 'Isosceles'
WHEN A != B OR B != C OR A != C THEN 'Scalene'
END
ELSE 'Not A Triangle' END FROM TRIANGLES;


The condition for scalene triangle does not include the following condition in your original query : Side 1 + Side 2 <= Side 3






share|improve this answer


























  • Nick, Thanks for the formatting.

    – Tina Sebastian
    Nov 24 '18 at 5:03












Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53455009%2fdetermine-type-of-triangle%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









2














Try something like this:



SELECT 
CASE
WHEN A + B > C AND A + C > B AND B + C > A THEN
CASE
WHEN A = B AND B = C THEN 'Equilateral'
WHEN A = B OR B = C OR A = C THEN 'Isosceles'
ELSE 'Scalene' END
ELSE 'Not A Triangle' END
FROM TRIANGLES


Only test for the type of triangle when it is a triangle.






share|improve this answer
























  • I saw this as an answer from another post. But I don't understand why the code I wrote doesn't work.

    – rds80
    Nov 24 '18 at 4:35






  • 1





    Beause, you are not checking for the condition of whether it is a triangle before declaring it as Scalene

    – Jonathan Van Dam
    Nov 24 '18 at 4:36






  • 2





    @JonathanVanDam actually he's not checking if it's a triangle before calling it Isosceles

    – Nick
    Nov 24 '18 at 4:43











  • Thanks @Nick I misspoke on that.

    – Jonathan Van Dam
    Nov 24 '18 at 4:46
















2














Try something like this:



SELECT 
CASE
WHEN A + B > C AND A + C > B AND B + C > A THEN
CASE
WHEN A = B AND B = C THEN 'Equilateral'
WHEN A = B OR B = C OR A = C THEN 'Isosceles'
ELSE 'Scalene' END
ELSE 'Not A Triangle' END
FROM TRIANGLES


Only test for the type of triangle when it is a triangle.






share|improve this answer
























  • I saw this as an answer from another post. But I don't understand why the code I wrote doesn't work.

    – rds80
    Nov 24 '18 at 4:35






  • 1





    Beause, you are not checking for the condition of whether it is a triangle before declaring it as Scalene

    – Jonathan Van Dam
    Nov 24 '18 at 4:36






  • 2





    @JonathanVanDam actually he's not checking if it's a triangle before calling it Isosceles

    – Nick
    Nov 24 '18 at 4:43











  • Thanks @Nick I misspoke on that.

    – Jonathan Van Dam
    Nov 24 '18 at 4:46














2












2








2







Try something like this:



SELECT 
CASE
WHEN A + B > C AND A + C > B AND B + C > A THEN
CASE
WHEN A = B AND B = C THEN 'Equilateral'
WHEN A = B OR B = C OR A = C THEN 'Isosceles'
ELSE 'Scalene' END
ELSE 'Not A Triangle' END
FROM TRIANGLES


Only test for the type of triangle when it is a triangle.






share|improve this answer













Try something like this:



SELECT 
CASE
WHEN A + B > C AND A + C > B AND B + C > A THEN
CASE
WHEN A = B AND B = C THEN 'Equilateral'
WHEN A = B OR B = C OR A = C THEN 'Isosceles'
ELSE 'Scalene' END
ELSE 'Not A Triangle' END
FROM TRIANGLES


Only test for the type of triangle when it is a triangle.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 24 '18 at 4:33









Jonathan Van DamJonathan Van Dam

386416




386416













  • I saw this as an answer from another post. But I don't understand why the code I wrote doesn't work.

    – rds80
    Nov 24 '18 at 4:35






  • 1





    Beause, you are not checking for the condition of whether it is a triangle before declaring it as Scalene

    – Jonathan Van Dam
    Nov 24 '18 at 4:36






  • 2





    @JonathanVanDam actually he's not checking if it's a triangle before calling it Isosceles

    – Nick
    Nov 24 '18 at 4:43











  • Thanks @Nick I misspoke on that.

    – Jonathan Van Dam
    Nov 24 '18 at 4:46



















  • I saw this as an answer from another post. But I don't understand why the code I wrote doesn't work.

    – rds80
    Nov 24 '18 at 4:35






  • 1





    Beause, you are not checking for the condition of whether it is a triangle before declaring it as Scalene

    – Jonathan Van Dam
    Nov 24 '18 at 4:36






  • 2





    @JonathanVanDam actually he's not checking if it's a triangle before calling it Isosceles

    – Nick
    Nov 24 '18 at 4:43











  • Thanks @Nick I misspoke on that.

    – Jonathan Van Dam
    Nov 24 '18 at 4:46

















I saw this as an answer from another post. But I don't understand why the code I wrote doesn't work.

– rds80
Nov 24 '18 at 4:35





I saw this as an answer from another post. But I don't understand why the code I wrote doesn't work.

– rds80
Nov 24 '18 at 4:35




1




1





Beause, you are not checking for the condition of whether it is a triangle before declaring it as Scalene

– Jonathan Van Dam
Nov 24 '18 at 4:36





Beause, you are not checking for the condition of whether it is a triangle before declaring it as Scalene

– Jonathan Van Dam
Nov 24 '18 at 4:36




2




2





@JonathanVanDam actually he's not checking if it's a triangle before calling it Isosceles

– Nick
Nov 24 '18 at 4:43





@JonathanVanDam actually he's not checking if it's a triangle before calling it Isosceles

– Nick
Nov 24 '18 at 4:43













Thanks @Nick I misspoke on that.

– Jonathan Van Dam
Nov 24 '18 at 4:46





Thanks @Nick I misspoke on that.

– Jonathan Van Dam
Nov 24 '18 at 4:46













2














Try this :



SELECT CASE WHEN A + B > C AND A+C>B AND B+C>A THEN 
CASE WHEN A = B AND B = C THEN 'Equilateral'
WHEN A = B OR B = C OR A = C THEN 'Isosceles'
WHEN A != B OR B != C OR A != C THEN 'Scalene'
END
ELSE 'Not A Triangle' END FROM TRIANGLES;


The condition for scalene triangle does not include the following condition in your original query : Side 1 + Side 2 <= Side 3






share|improve this answer


























  • Nick, Thanks for the formatting.

    – Tina Sebastian
    Nov 24 '18 at 5:03
















2














Try this :



SELECT CASE WHEN A + B > C AND A+C>B AND B+C>A THEN 
CASE WHEN A = B AND B = C THEN 'Equilateral'
WHEN A = B OR B = C OR A = C THEN 'Isosceles'
WHEN A != B OR B != C OR A != C THEN 'Scalene'
END
ELSE 'Not A Triangle' END FROM TRIANGLES;


The condition for scalene triangle does not include the following condition in your original query : Side 1 + Side 2 <= Side 3






share|improve this answer


























  • Nick, Thanks for the formatting.

    – Tina Sebastian
    Nov 24 '18 at 5:03














2












2








2







Try this :



SELECT CASE WHEN A + B > C AND A+C>B AND B+C>A THEN 
CASE WHEN A = B AND B = C THEN 'Equilateral'
WHEN A = B OR B = C OR A = C THEN 'Isosceles'
WHEN A != B OR B != C OR A != C THEN 'Scalene'
END
ELSE 'Not A Triangle' END FROM TRIANGLES;


The condition for scalene triangle does not include the following condition in your original query : Side 1 + Side 2 <= Side 3






share|improve this answer















Try this :



SELECT CASE WHEN A + B > C AND A+C>B AND B+C>A THEN 
CASE WHEN A = B AND B = C THEN 'Equilateral'
WHEN A = B OR B = C OR A = C THEN 'Isosceles'
WHEN A != B OR B != C OR A != C THEN 'Scalene'
END
ELSE 'Not A Triangle' END FROM TRIANGLES;


The condition for scalene triangle does not include the following condition in your original query : Side 1 + Side 2 <= Side 3







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 24 '18 at 4:35









Nick

39.9k132443




39.9k132443










answered Nov 24 '18 at 4:32









Tina SebastianTina Sebastian

362




362













  • Nick, Thanks for the formatting.

    – Tina Sebastian
    Nov 24 '18 at 5:03



















  • Nick, Thanks for the formatting.

    – Tina Sebastian
    Nov 24 '18 at 5:03

















Nick, Thanks for the formatting.

– Tina Sebastian
Nov 24 '18 at 5:03





Nick, Thanks for the formatting.

– Tina Sebastian
Nov 24 '18 at 5:03


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53455009%2fdetermine-type-of-triangle%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

Tangent Lines Diagram Along Smooth Curve

Yusuf al-Mu'taman ibn Hud

Zucchini