Skip to content

Commit a329225

Browse files
authored
Add files via upload
1 parent 7646918 commit a329225

File tree

2 files changed

+53
-18
lines changed

2 files changed

+53
-18
lines changed

5a.py

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,32 +21,18 @@
2121

2222
# [3, 4] : [1, 4] # xy1[0] xy1[1] : xy2[0] xy2[1] : [x1, y1] [x2, y2]
2323
def incrRange(xy1, xy2):
24-
x1 = xy1[0]
25-
y1 = xy1[1]
26-
x2 = xy2[0]
27-
y2 = xy2[1]
24+
x1,y1,x2,y2 = xy1[0],xy1[1],xy2[0],xy2[1]
2825
if x1==x2:
29-
if y2 > y1:
30-
start = y1
31-
end = y2
32-
else:
33-
start = y2
34-
end = y1
26+
start, end = min(y1,y2), max(y1,y2)
3527
for y in range(start, end+1):
3628
grid[x1][y] += 1
3729
elif y1==y2:
38-
if x2 > x1:
39-
start = x1
40-
end = x2
41-
else:
42-
start = x2
43-
end = x1
30+
start, end = min(x1,x2), max(x1,x2)
4431
for x in range(start, end+1):
4532
grid[x][y1] += 1
4633
else:
4734
print(f"SKIP diag, {line}")
4835

49-
#eg: 0,9 -> 5,9
5036
for line in a_list:
5137
xy = line.split(" -> ")
5238
xy1str = xy[0].split(",")
@@ -61,5 +47,4 @@ def incrRange(xy1, xy2):
6147
for y in range(0, max_y):
6248
if grid[x][y] >= 2:
6349
count += 1
64-
6550
print(f"count = {count}")

5b.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#Advent of code 2021
2+
# 12/11/21 day 5b
3+
# Joe McFarland
4+
# import sys
5+
# import re
6+
# import copy
7+
8+
#max_x = 10
9+
#max_y = 10
10+
max_x = 1000
11+
max_y = 1000
12+
grid = [[0]*max_x for _ in range(max_y)]
13+
filename = "data5.txt"
14+
15+
file = open(filename)
16+
filestr = file.read()
17+
a_list = filestr.split("\n")
18+
maxrows = len(a_list)
19+
print(a_list)
20+
#maxcols = len(a_list[0])
21+
22+
# [3, 4] : [1, 4] # xy1[0] xy1[1] : xy2[0] xy2[1] : [x1, y1] [x2, y2]
23+
def incrRange(xy1, xy2):
24+
x1,y1,x2,y2 = xy1[0],xy1[1],xy2[0],xy2[1]
25+
if x1==x2:
26+
start, end = min(y1,y2), max(y1,y2)
27+
for y in range(start, end+1):
28+
grid[x1][y] += 1
29+
elif y1==y2:
30+
start, end = min(x1,x2), max(x1,x2)
31+
for x in range(start, end+1):
32+
grid[x][y1] += 1
33+
else:
34+
print(f"SKIP diag, {line}")
35+
36+
for line in a_list:
37+
xy = line.split(" -> ")
38+
xy1str = xy[0].split(",")
39+
xy1 = [int(elem) for elem in xy1str]
40+
xy2str = xy[1].split(",")
41+
xy2 = [int(elem) for elem in xy2str]
42+
print(f"{xy1} : {xy2}")
43+
incrRange(xy1, xy2)
44+
45+
count = 0
46+
for x in range(0, max_x):
47+
for y in range(0, max_y):
48+
if grid[x][y] >= 2:
49+
count += 1
50+
print(f"count = {count}")

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy