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

+5 -11
+5 -11
2016/day18.py
··· 1 1 import fileinput 2 2 3 3 4 - def is_safe(row, x): 4 + def is_safe(row, i): 5 5 """Helper function to read out-of-bounds tiles as safe.""" 6 - if x < 0 or x >= len(row): 7 - return True 6 + if 0 <= i < len(row): 7 + return row[i] 8 8 9 - return row[x] 9 + return True 10 10 11 11 12 12 def predict_next_row(row): 13 13 """Given a row, returns the predicted following row.""" 14 - next_row = [] 15 - 16 - for i in range(len(row)): 17 - a, c = is_safe(row, i - 1), is_safe(row, i + 1) 18 - next_row.append(not (a ^ c)) 19 - 20 - return tuple(next_row) 14 + return [not (is_safe(row, i-1) ^ is_safe(row, i+1)) for i in range(len(row))] 21 15 22 16 23 17 if __name__ == '__main__':