My Advent of Code solutions in Python. kevinyap.ca/2019/12/going-fast-in-advent-of-code/
advent-of-code python
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Update day18.py

Refactor trap prediction logic into a simple boolean XOR.

+2 -15
+2 -15
2016/day18.py
··· 14 14 next_row = [] 15 15 16 16 for i in range(len(row)): 17 - a, b, c = (is_safe(row, x) for x in range(i-1, i+2)) 18 - next_row.append(predict_safe(a, b, c)) 17 + a, c = is_safe(row, i - 1), is_safe(row, i + 1) 18 + next_row.append(not (a ^ c)) 19 19 20 20 return tuple(next_row) 21 - 22 - 23 - def predict_safe(a, b, c): 24 - if a and b and not c: 25 - return False 26 - elif not a and b and c: 27 - return False 28 - elif a and not b and not c: 29 - return False 30 - elif not a and not b and c: 31 - return False 32 - 33 - return True 34 21 35 22 36 23 if __name__ == '__main__':