aoc

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

a.py (656B)


      1 # Just estimate if the shape fit basd on the area. I feel like I am
      2 # being pranked, this problem sucks.
      3 
      4 import fileinput
      5 
      6 def present_area(lines5):
      7 	return sum(l.count('#') for l in lines5)
      8 
      9 def region(line):
     10 	wh, n = line[:-1].split(': ')
     11 	wh = tuple(int(i) for i in wh.split('x'))
     12 	c = [int(i) for i in n.split(' ')]
     13 	return wh, c
     14 
     15 def fits(wh, c, areas):
     16 	return wh[0]*wh[1] >= sum(c[i] * areas[i] for i in range(6))
     17 
     18 with fileinput.input() as lines:
     19 	lines = list(lines)
     20 	areas = [present_area(lines[5*i:5*(i+1)]) for i in range(6)]
     21 	regions = [region(line) for line in lines[30:]]
     22 
     23 print(sum(1 if fits(*region, areas) else 0 for region in regions))