diff options
| author | Lubos Kolouch <lubos@kolouch.net> | 2022-03-19 10:17:40 +0100 |
|---|---|---|
| committer | Lubos Kolouch <lubos@kolouch.net> | 2022-03-19 10:17:40 +0100 |
| commit | b9ec2195aa1d4d05416d73c4c4dcdfa6b54f0262 (patch) | |
| tree | ae20639bd029a6a62ee297426a59be3fd5ac32d5 | |
| parent | d8fadfce927ded515784f96676111b3c1f93ec37 (diff) | |
| download | perlweeklychallenge-club-b9ec2195aa1d4d05416d73c4c4dcdfa6b54f0262.tar.gz perlweeklychallenge-club-b9ec2195aa1d4d05416d73c4c4dcdfa6b54f0262.tar.bz2 perlweeklychallenge-club-b9ec2195aa1d4d05416d73c4c4dcdfa6b54f0262.zip | |
feat(challenge-156/lubos-kolouch/python/ch-2.py): Challenge 156 Task 2 Python LK
| -rw-r--r-- | challenge-156/lubos-kolouch/python/ch-2.py | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/challenge-156/lubos-kolouch/python/ch-2.py b/challenge-156/lubos-kolouch/python/ch-2.py new file mode 100644 index 0000000000..aa62e4cbe1 --- /dev/null +++ b/challenge-156/lubos-kolouch/python/ch-2.py @@ -0,0 +1,27 @@ +""" Challenge 156 Task 2 LK """ +from itertools import combinations + +from sympy import divisors + + +def is_weird(what: int) -> bool: + """Check if the number is weird""" + + all_divisors = divisors(what) + + # remove the number itself from the list + del all_divisors[-1] + + if sum(all_divisors) <= what: + return False + + for i in range(1, len(all_divisors) + 1): + all_combs = combinations(all_divisors, i) + for comb in all_combs: + if sum(comb) == what: + return False + return True + + +assert is_weird(12) == 0 +assert is_weird(70) == 1 |
