aoc

My solutions for the Advent of Code
git clone https://git.tronto.net/aoc
Download | Log | Files | Refs | README

b.py (515B)


      1 import fileinput
      2 
      3 def neigh(a, i, j):
      4 	return [
      5 		a[i-1][j-1], a[i-1][j], a[i-1][j+1],
      6 		a[i][j-1],              a[i][j+1],
      7 		a[i+1][j-1], a[i+1][j], a[i+1][j+1],
      8 	].count('@')
      9 
     10 with fileinput.input() as lines:
     11 	a = [
     12 		['.'] * 200,
     13 		*[['.'] + list(line.replace('\n', '.')) for line in lines],
     14 		['.'] * 200,
     15 	]
     16 
     17 s = 0
     18 rem = True
     19 while rem:
     20 	rem = False
     21 	for i in range(1,len(a)-1):
     22 		for j in range(1,len(a[1])-1):
     23 			if a[i][j] == '@' and neigh(a, i, j) < 4:
     24 				s += 1
     25 				rem = True
     26 				a[i][j] = '.'
     27 print(s)