File tree Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Original file line number Diff line number Diff line change
1
+ from typing import List
2
+
3
+
4
+ def check_polygon (nums : List ) -> bool :
5
+ """
6
+ Takes list of possible side lengths and determines whether a
7
+ two-dimensional polygon with such side lengths can exist.
8
+
9
+ Returns a boolean value for the < comparison
10
+ of the largest side length with sum of the rest.
11
+ Wiki: https://en.wikipedia.org/wiki/Triangle_inequality
12
+
13
+ >>> check_polygon([6, 10, 5])
14
+ True
15
+ >>> check_polygon([3, 7, 13, 2])
16
+ False
17
+ >>> check_polygon([])
18
+ Traceback (most recent call last):
19
+ ...
20
+ ValueError: List is invalid
21
+ """
22
+ if not nums :
23
+ raise ValueError ("List is invalid" )
24
+ nums .sort ()
25
+ return nums .pop () < sum (nums )
26
+
27
+
28
+ if __name__ == "__main__" :
29
+ import doctest
30
+
31
+ doctest .testmod ()
You can’t perform that action at this time.
0 commit comments