aboutsummaryrefslogtreecommitdiff
path: root/challenge-328/sgreen/python/ch-1.py
blob: 16e539b9b19c603e7da56399e30c1c5349fdd8a0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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()