diff options
Diffstat (limited to 'challenge-074/walt-mankowski/python')
| -rw-r--r-- | challenge-074/walt-mankowski/python/ch-1.py | 15 | ||||
| -rw-r--r-- | challenge-074/walt-mankowski/python/ch-2.py | 23 |
2 files changed, 38 insertions, 0 deletions
diff --git a/challenge-074/walt-mankowski/python/ch-1.py b/challenge-074/walt-mankowski/python/ch-1.py new file mode 100644 index 0000000000..7af167d60a --- /dev/null +++ b/challenge-074/walt-mankowski/python/ch-1.py @@ -0,0 +1,15 @@ +from sys import argv +from collections import defaultdict + +a = [int(x) for x in argv[1:]] +target = len(a) / 2 +result = -1 +cnt = defaultdict(int) + +for x in a: + cnt[x] += 1 + if cnt[x] > target: + result = x + break + +print(result) diff --git a/challenge-074/walt-mankowski/python/ch-2.py b/challenge-074/walt-mankowski/python/ch-2.py new file mode 100644 index 0000000000..d7aeb7353c --- /dev/null +++ b/challenge-074/walt-mankowski/python/ch-2.py @@ -0,0 +1,23 @@ +from sys import argv + +s = argv[1] +seen = {} +nr = [] +out = '' + +for c in s: + # have we seen c before? + if c not in seen: + # add c to nr + seen[c] = True + nr.append(c) + else: + # remove c from nr + if seen[c]: + nr.remove(c) + seen[c] = False + + # now the FNR is either the last element of nr, or # + out += nr[-1] if nr else '#' + +print(out) |
