diff options
Diffstat (limited to 'challenge-328/sgreen/python/ch-1.py')
| -rwxr-xr-x | challenge-328/sgreen/python/ch-1.py | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/challenge-328/sgreen/python/ch-1.py b/challenge-328/sgreen/python/ch-1.py new file mode 100755 index 0000000000..16e539b9b1 --- /dev/null +++ b/challenge-328/sgreen/python/ch-1.py @@ -0,0 +1,37 @@ +#!/usr/bin/env python3 + +import sys + + +def replace_all_questions(input_string: str) -> str: + solution = '' + for idx, char in enumerate(input_string): + if char != '?': + solution += char + continue + + # Get the surrounding characters + letters = [] + if idx > 0: + letters.append(input_string[idx - 1]) + if idx < len(input_string) - 1: + letters.append(input_string[idx + 1]) + + # Replace '?' with 'a', 'b', or 'c' based on surrounding characters + if 'a' not in letters: + solution += 'a' + elif 'b' not in letters: + solution += 'b' + else: + solution += 'c' + + return solution + + +def main(): + result = replace_all_questions(sys.argv[1]) + print('"' + result + '"') + + +if __name__ == '__main__': + main() |
