aoc

Advent of Code Solutions
git clone git://git.alexkarle.com.com/aoc
Log | Files | Refs | README | LICENSE

b.py (755B) [raw]


      1 #!/usr/bin/env python3
      2 import sys
      3 from collections import defaultdict
      4 
      5 seen = {}
      6 grid = []
      7 
      8 for l in sys.stdin:
      9     grid.append([int(x) for x in l.strip()])
     10 
     11 
     12 def search(r, c, color):
     13     if (r, c) in seen or grid[r][c] == 9:
     14         return
     15 
     16     seen[(r, c)] = color
     17     if r > 0:
     18         search(r - 1, c, color)
     19     if c > 0:
     20         search(r, c - 1, color)
     21     if c < 99:
     22         search(r, c + 1, color)
     23     if r < 99:
     24         search(r + 1, c, color)
     25 
     26 
     27 # Search from each point (no-op once seen once)!
     28 i = 1
     29 for r in range(100):
     30     for c in range(100):
     31         search(r, c, i)
     32         i += 1
     33 
     34 # Finally, count the colors
     35 G = defaultdict(int)
     36 for v in seen.values():
     37     G[v] += 1
     38 
     39 top = sorted(G.values(), reverse=True)
     40 print(top[0] * top[1] * top[2])