Sha256: 82c66c9dad325abeea195b852ca9c7d662decb277008fb19e8620882fcd24ac4
Contents?: true
Size: 682 Bytes
Versions: 33
Compression:
Stored size: 682 Bytes
Contents
#import "TriangleExample.h" @implementation Triangle + (TriangleKind)kindForSides:(double)a :(double)b :(double)c { if (a <= 0 || b <= 0 || c <= 0) { @throw [NSException exceptionWithName:@"Invalid triangle" reason:@"All lengths must be positive" userInfo:nil]; } else if (a + b <= c || b + c <= a || a + c <= b) { @throw [NSException exceptionWithName:@"Invalid triangle" reason:@"Violation of triangle inequality" userInfo:nil]; } if (a == b && b == c) { return TriangleKindEquilateral; } else if (a == b || b == c || a == c) { return TriangleKindIsosceles; } else { return TriangleKindScalene; } } @end
Version data entries
33 entries across 33 versions & 1 rubygems