diff options
Diffstat (limited to 'challenge-194/sgreen/python')
| -rwxr-xr-x | challenge-194/sgreen/python/ch-1.py | 23 | ||||
| -rwxr-xr-x | challenge-194/sgreen/python/ch-2.py | 39 |
2 files changed, 62 insertions, 0 deletions
diff --git a/challenge-194/sgreen/python/ch-1.py b/challenge-194/sgreen/python/ch-1.py new file mode 100755 index 0000000000..add4e38257 --- /dev/null +++ b/challenge-194/sgreen/python/ch-1.py @@ -0,0 +1,23 @@ +#!/usr/bin/env python3 + +import sys + +def main(time): + value = None + if time[0] == '?': + # 2 if the second hour value is <= 3 else 1 + value = 2 if int(time[1]) <= 3 else 1 + elif time[1] == '?': + # 3 if the first hour value is 2 else 9 + value = 3 if time[0] == '2' else 9 + elif time[3] == '?': + # The maximum first minute value is always 5 + value = 5 + else: + # The maximum second minute value is always 9 + value = 9 + + print(value) + +if __name__ == '__main__': + main(sys.argv[1])
\ No newline at end of file diff --git a/challenge-194/sgreen/python/ch-2.py b/challenge-194/sgreen/python/ch-2.py new file mode 100755 index 0000000000..dfa570c4cf --- /dev/null +++ b/challenge-194/sgreen/python/ch-2.py @@ -0,0 +1,39 @@ +#!/usr/bin/env python3 + +import sys + + +def main(s): + # Calculate the frequency of each letter + letter_freq = {} + for letter in s: + letter_freq[letter] = letter_freq.get(letter, 0) + 1 + + # Calculate the frequency of frequencies :) + freq = {} + for i in letter_freq.values(): + freq[i] = freq.get(i, 0) + 1 + + solution = 0 + # A solution is only possible if there are two different frequencies ... + if len(freq) == 2: + min_freq = min(freq.keys()) + max_freq = max(freq.keys()) + + # ... and the minimum frequency only occurs once, + if min_freq == 1 and freq[1] == 1: + solution = 1 + + # ... or the difference between them is 1, and the higher frequency + # only occurs once. + elif min_freq == max_freq - 1 and freq[max_freq] == 1: + solution = 1 + elif len(freq) == 1 and 1 in freq: + # ... or the only thing we have is single letters + solution = 1 + + print(solution) + + +if __name__ == '__main__': + main(sys.argv[1]) |
