Created
July 27, 2017 05:04
-
-
Save jianminchen/fefe6e44c45b2d55a3f9192867c318e2 to your computer and use it in GitHub Desktop.
Triangle algorithm - code review after 8 years, conducted on Oct. 2009
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
namespace TriangleAlgorithm | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
} | |
/// <summary> | |
/// Code review: | |
/// 10/13/2009 | |
/// | |
/// Imagine you are given three integers, each representing a side of a triangle. | |
/// Write a function that determines whether the triangle is isoscoles, equilateral or scalene. | |
/// 3 3 3 e 1 | |
/// 3 3 4 iso 2 | |
/// 3 4 5 scalens 3 | |
/// </summary> | |
/// <param name="x"></param> | |
/// <param name="y"></param> | |
/// <param name="z"></param> | |
/// <returns></returns> | |
public static int test(int x, int y, int z) | |
{ | |
if (x <= 0 || y < 0 || z <= 0) | |
{ | |
return -1; | |
} | |
if (x == y) | |
{ | |
if (x == z) | |
return 1; /// 3 3 3 | |
else | |
{ // x not z | |
// if(y==z) return 2; // delete line | |
return 2; // 3 3 4 | |
} | |
} | |
else | |
{ | |
if (x == z) return 2; // 3, 4, 3 4th case | |
else if (y == z) return 2; // 3 4 4 | |
else return 3; // 3 4 5 } | |
} | |
// unreachable code | |
//return -1; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment