summary refs log tree commit diff
path: root/22.14
diff options
context:
space:
mode:
Diffstat (limited to '22.14')
-rw-r--r--22.14/main.py55
1 files changed, 34 insertions, 21 deletions
diff --git a/22.14/main.py b/22.14/main.py
index 5078f4d..e2545bb 100644
--- a/22.14/main.py
+++ b/22.14/main.py
@@ -13,26 +13,39 @@ for line in stdin:
 				solid.add((x, y))
 
 max_y = max([y for x,y in solid])
-print(max_y)
 
-def drop(x, y):
-	while True:
-		while not (x, y+1) in solid:
-			y += 1
-			if max_y < y:
-				return False
-		if not (x-1, y+1) in solid:
-			x -= 1
-			y += 1
-		elif not (x+1, y+1) in solid:
-			x += 1
-			y += 1
-		else:
-			print(x, y)
-			solid.add((x, y))
-			return True
+def partOne(s):
+	def drop(x, y):
+		while True:
+			while not (x, y+1) in s:
+				y += 1
+				if max_y < y:
+					return False
+			if not (x-1, y+1) in s:
+				x -= 1
+				y += 1
+			elif not (x+1, y+1) in s:
+				x += 1
+				y += 1
+			else:
+				s.add((x, y))
+				return True
+	n = 0
+	while drop(500, 0):
+		n += 1
+	return n
 
-n = 0
-while drop(500, 0):
-	n += 1
-print(n)
+def partTwo(s):
+	total = 1
+	last = {500}
+	for y in range(1, max_y + 2):
+		cur = last.copy()
+		cur = cur.union(map(lambda x: x-1, last))
+		cur = cur.union(map(lambda x: x+1, last))
+		cur = set(filter(lambda x: not (x, y) in s, cur))
+		last = cur
+		total += len(cur)
+	return total
+
+print(partOne(solid.copy()))
+print(partTwo(solid.copy()))