From b45b32b35c292a7fc26fa15084cd56065b804ae9 Mon Sep 17 00:00:00 2001 From: "Arghya Sarkar (ASRA)" <67339217+sarkarghya@users.noreply.github.com> Date: Mon, 9 Aug 2021 23:23:26 +0530 Subject: [PATCH 1/5] Create check_polygon.py --- maths/check_polygon.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 maths/check_polygon.py diff --git a/maths/check_polygon.py b/maths/check_polygon.py new file mode 100644 index 000000000000..f4ad81b118fe --- /dev/null +++ b/maths/check_polygon.py @@ -0,0 +1,28 @@ +from typing import List + + +def check_polygon(nums: List) -> bool: + """ + Takes list of possible sidelengths and determines whether a two-dimensional polygon with such sidelengths can exist. + Return a boolean value for the < comparison of the largest sidelength with sum of the rest. + Wiki: https://en.wikipedia.org/wiki/Triangle_inequality + + >>> check_polygon([6, 10, 5]) + True + >>> check_polygon([3, 7, 13, 2]) + False + >>> check_polygon([]) + Traceback (most recent call last): + ... + ValueError: List is invalid + """ + if not nums: + raise ValueError("List is invalid") + nums.sort() + return nums.pop() < sum(nums) + + +if __name__ == "__main__": + import doctest + + doctest.testmod() From f57caf57e39b8d8b4417ff6525b827532740db8d Mon Sep 17 00:00:00 2001 From: "Arghya Sarkar (ASRA)" <67339217+sarkarghya@users.noreply.github.com> Date: Mon, 13 Sep 2021 18:09:49 +0530 Subject: [PATCH 2/5] Update check_polygon.py --- maths/check_polygon.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/maths/check_polygon.py b/maths/check_polygon.py index f4ad81b118fe..e88f0d3d2949 100644 --- a/maths/check_polygon.py +++ b/maths/check_polygon.py @@ -6,7 +6,7 @@ def check_polygon(nums: List) -> bool: Takes list of possible sidelengths and determines whether a two-dimensional polygon with such sidelengths can exist. Return a boolean value for the < comparison of the largest sidelength with sum of the rest. Wiki: https://en.wikipedia.org/wiki/Triangle_inequality - + >>> check_polygon([6, 10, 5]) True >>> check_polygon([3, 7, 13, 2]) From 2fbde5b77e925ce64463191fe7d0674419a42157 Mon Sep 17 00:00:00 2001 From: John Law Date: Wed, 29 Sep 2021 13:54:32 +0800 Subject: [PATCH 3/5] Update maths/check_polygon.py --- maths/check_polygon.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/maths/check_polygon.py b/maths/check_polygon.py index e88f0d3d2949..f0a28d79c4c3 100644 --- a/maths/check_polygon.py +++ b/maths/check_polygon.py @@ -3,8 +3,11 @@ def check_polygon(nums: List) -> bool: """ - Takes list of possible sidelengths and determines whether a two-dimensional polygon with such sidelengths can exist. - Return a boolean value for the < comparison of the largest sidelength with sum of the rest. + Takes list of possible side lengths and determines whether a + two-dimensional polygon with such side lengths can exist. + + Returns a boolean value for the < comparison + of the largest side length with sum of the rest. Wiki: https://en.wikipedia.org/wiki/Triangle_inequality >>> check_polygon([6, 10, 5]) From 5a4652132c41f7c5b1e77ee564516dc8c34ad33b Mon Sep 17 00:00:00 2001 From: John Law Date: Wed, 29 Sep 2021 15:23:59 +0800 Subject: [PATCH 4/5] Update check_polygon.py --- maths/check_polygon.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/maths/check_polygon.py b/maths/check_polygon.py index f0a28d79c4c3..160ab196537b 100644 --- a/maths/check_polygon.py +++ b/maths/check_polygon.py @@ -5,7 +5,7 @@ def check_polygon(nums: List) -> bool: """ Takes list of possible side lengths and determines whether a two-dimensional polygon with such side lengths can exist. - + Returns a boolean value for the < comparison of the largest side length with sum of the rest. Wiki: https://en.wikipedia.org/wiki/Triangle_inequality From c7a58fd32fa9d8960d1032edb801569c0ca24520 Mon Sep 17 00:00:00 2001 From: John Law Date: Wed, 29 Sep 2021 15:32:40 +0800 Subject: [PATCH 5/5] Update check_polygon.py --- maths/check_polygon.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/maths/check_polygon.py b/maths/check_polygon.py index 160ab196537b..0e771197331f 100644 --- a/maths/check_polygon.py +++ b/maths/check_polygon.py @@ -6,7 +6,7 @@ def check_polygon(nums: List) -> bool: Takes list of possible side lengths and determines whether a two-dimensional polygon with such side lengths can exist. - Returns a boolean value for the < comparison + Returns a boolean value for the < comparison of the largest side length with sum of the rest. Wiki: https://en.wikipedia.org/wiki/Triangle_inequality