aoc

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

a.py (669B) [raw]


      1 #!/usr/bin/env python3
      2 import sys
      3 import pdb
      4 from collections import defaultdict
      5 
      6 grid = defaultdict(lambda: defaultdict(int))
      7 
      8 def bigrange(a, b):
      9     if a > b:
     10         return range(b, a + 1)
     11     else:
     12         return range(a, b + 1)
     13 
     14 for l in sys.stdin:
     15     a, arrow, b = l.split()
     16     x1, y1 = [int(x) for x in a.split(',')]
     17     x2, y2 = [int(x) for x in b.split(',')]
     18     if x1 == x2:
     19         for y in bigrange(y1, y2):
     20             grid[x1][y] += 1
     21     elif y1 == y2:
     22         for x in bigrange(x1, x2):
     23             grid[x][y1] += 1
     24         
     25 count = 0
     26 for x in grid.keys():
     27     for y in grid[x].keys():
     28         if grid[x][y] > 1:
     29             count += 1
     30 
     31 print(count)