diff --git a/2017/18/solution.py b/2017/18/solution.py index 66c0cf8..24287f3 100644 --- a/2017/18/solution.py +++ b/2017/18/solution.py @@ -14,22 +14,79 @@ part = 1 ######################################### def parse_input(input_str): - pattern = r"^(s(\d+)|x(\d+)/(\d+)|p([a-zA-Z])/([a-zA-Z]))$" + pattern = r"^([a-zA-Z]{3})\s{1}(\w)?\s?(-?\w+)$" match = re.match(pattern, input_str) if match: if match.group(2): - return ('s', int(match.group(2))) - elif match.group(3) and match.group(4): - return ('x', int(match.group(3)), int(match.group(4))) - elif match.group(5) and match.group(6): - return ('p', match.group(5), match.group(6)) + return match.group(1),match.group(2),match.group(3) + else: + return match.group(1),match.group(3) + return None +instructions = [] + +sets = {} + +last_sound = 0 + if part == 1: with open(input_f) as file: for line in file: + instructions.append(list(parse_input(line.rstrip()))) + x = 0 + + while True: + i = instructions[x] + print(i) + + if i[0] == 'set': + sets[i[1]] = i[2] + + elif i[0] == 'add': + sets[i[1]] = int(sets[i[1]]) + int(i[2]) + + elif i[0] == 'mul': + if i[2] in sets: + sets[i[1]] = int(sets[i[1]]) * int(sets[i[2]]) + else: + sets[i[1]] = int(sets[i[1]]) * int(i[2]) + + elif i[0] == 'mod': + sets[i[1]] = int(sets[i[1]]) % int(i[2]) + + elif i[0] == 'snd': + last_sound = sets[i[1]] + + elif i[0] == 'rcv': + if sets[i[1]] != 0: + sets[i[1]] = int(sets[i[1]]) + else: + print('skipped') + + if i[0] == 'jgz': + if isinstance(i[2], str): + if sets[i[1]] > 0: + + x += int(sets[i[2]]) + else: + x += int(i[2]) + else: + x += 1 + else: + x += 1 + + + + print(x,sets,last_sound) + input() + #print(programs) + #print(instructions) + #print(len(instructions)) + + #for idx,i in enumerate(instructions):