diff options
| author | deadmarshal <adeadmarshal@gmail.com> | 2022-11-20 10:46:28 +0330 |
|---|---|---|
| committer | deadmarshal <adeadmarshal@gmail.com> | 2022-11-20 10:46:28 +0330 |
| commit | 4a6109910c67852630b4d5b50d2a1bf465cfbeaa (patch) | |
| tree | 6e42048916f594d7761bf110717780a31e556b05 /challenge-191/deadmarshal/python | |
| parent | bde0adaf7b8dfe99c4e494c932d8702eb8cf9a56 (diff) | |
| download | perlweeklychallenge-club-4a6109910c67852630b4d5b50d2a1bf465cfbeaa.tar.gz perlweeklychallenge-club-4a6109910c67852630b4d5b50d2a1bf465cfbeaa.tar.bz2 perlweeklychallenge-club-4a6109910c67852630b4d5b50d2a1bf465cfbeaa.zip | |
Challenge191
Diffstat (limited to 'challenge-191/deadmarshal/python')
| -rw-r--r-- | challenge-191/deadmarshal/python/ch1.py | 10 | ||||
| -rw-r--r-- | challenge-191/deadmarshal/python/ch2.py | 15 |
2 files changed, 25 insertions, 0 deletions
diff --git a/challenge-191/deadmarshal/python/ch1.py b/challenge-191/deadmarshal/python/ch1.py new file mode 100644 index 0000000000..c889abe734 --- /dev/null +++ b/challenge-191/deadmarshal/python/ch1.py @@ -0,0 +1,10 @@ +def twice_largest(arr): + arr.sort(reverse=True) + if arr[0] >= (2 * arr[1]): return 1 + return -1 + +print(f"{twice_largest([1,2,3,4]):>2}") +print(f"{twice_largest([1,2,0,5]):>2}") +print(f"{twice_largest([2,6,3,1]):>2}") +print(f"{twice_largest([4,5,2,3]):>2}") + diff --git a/challenge-191/deadmarshal/python/ch2.py b/challenge-191/deadmarshal/python/ch2.py new file mode 100644 index 0000000000..30ac0b9f78 --- /dev/null +++ b/challenge-191/deadmarshal/python/ch2.py @@ -0,0 +1,15 @@ +from itertools import permutations + +def is_cute(arr): + for i in range(1,len(arr)+1): + if i % arr[i-1] != 0 and arr[i-1] % i != 0: return False + return True + +def cute_list(n): + arr = list(range(1,n+1)) + count = 0 + for perm in permutations(arr): + if is_cute(perm): count += 1 + return count + +print(cute_list(2)) |
