diff options
| author | 冯昶 <fengchang@novel-supertv.com> | 2022-12-21 09:57:58 +0800 |
|---|---|---|
| committer | 冯昶 <fengchang@novel-supertv.com> | 2022-12-21 09:57:58 +0800 |
| commit | dd2a89a7880a924c4e3df167d71c34b4ed89a3fe (patch) | |
| tree | b208bd6dc97a7b4f025f62c78401dae7a796362c /challenge-195/deadmarshal/python | |
| parent | 7de47c639d3bc4fef60d8df2128c14049f47b1fd (diff) | |
| parent | d05040719c41d928cb4663bac89448f14fd74268 (diff) | |
| download | perlweeklychallenge-club-dd2a89a7880a924c4e3df167d71c34b4ed89a3fe.tar.gz perlweeklychallenge-club-dd2a89a7880a924c4e3df167d71c34b4ed89a3fe.tar.bz2 perlweeklychallenge-club-dd2a89a7880a924c4e3df167d71c34b4ed89a3fe.zip | |
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'challenge-195/deadmarshal/python')
| -rw-r--r-- | challenge-195/deadmarshal/python/ch1.py | 10 | ||||
| -rw-r--r-- | challenge-195/deadmarshal/python/ch2.py | 14 |
2 files changed, 24 insertions, 0 deletions
diff --git a/challenge-195/deadmarshal/python/ch1.py b/challenge-195/deadmarshal/python/ch1.py new file mode 100644 index 0000000000..b48d310af1 --- /dev/null +++ b/challenge-195/deadmarshal/python/ch1.py @@ -0,0 +1,10 @@ +def special_integers(n): + count = 0 + for i in range(1,n+1): + digits = [int(x) for x in str(i)] + if len(digits) == len(set(digits)): count += 1 + return count + +print(special_integers(15)) +print(special_integers(35)) + diff --git a/challenge-195/deadmarshal/python/ch2.py b/challenge-195/deadmarshal/python/ch2.py new file mode 100644 index 0000000000..783f93555b --- /dev/null +++ b/challenge-195/deadmarshal/python/ch2.py @@ -0,0 +1,14 @@ +from functools import reduce + +def most_frequent_even(arr): + if all(map(lambda n: n % 2 != 0, arr)): return -1 + d = {} + for i in arr: + if i % 2 == 0: d[i] = d.get(i, 0) + 1 + if len(d.values()) == len(set(d.values())): return min(d) + return reduce(lambda a,b:a if d[a] > d[b] else b, d.keys()) + +print(most_frequent_even([1,1,2,6,2])) +print(most_frequent_even([1,3,5,7])) +print(most_frequent_even([6,4,4,6,1])) + |
