-
Notifications
You must be signed in to change notification settings - Fork 0
/
day3prog1.py
136 lines (120 loc) · 4.24 KB
/
day3prog1.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
"""--- Day 3: No Matter How You Slice It ---
The Elves managed to locate the chimney-squeeze prototype fabric for Santa's suit (thanks to someone who helpfully wrote its box IDs on the wall of the warehouse in the middle of the night). Unfortunately, anomalies are still affecting them - nobody can even agree on how to cut the fabric.
The whole piece of fabric they're working on is a very large square - at least 1000 inches on each side.
Each Elf has made a claim about which area of fabric would be ideal for Santa's suit. All claims have an ID and consist of a single rectangle with edges parallel to the edges of the fabric. Each claim's rectangle is defined as follows:
The number of inches between the left edge of the fabric and the left edge of the rectangle.
The number of inches between the top edge of the fabric and the top edge of the rectangle.
The width of the rectangle in inches.
The height of the rectangle in inches.
A claim like #123 @ 3,2: 5x4 means that claim ID 123 specifies a rectangle 3 inches from the left edge, 2 inches from the top edge, 5 inches wide, and 4 inches tall. Visually, it claims the square inches of fabric represented by # (and ignores the square inches of fabric represented by .) in the diagram below:
...........
...........
...#####...
...#####...
...#####...
...#####...
...........
...........
...........
The problem is that many of the claims overlap, causing two or more claims to cover part of the same areas. For example, consider the following claims:
#1 @ 1,3: 4x4
#2 @ 3,1: 4x4
#3 @ 5,5: 2x2
Visually, these claim the following areas:
........
...2222.
...2222.
.11XX22.
.11XX22.
.111133.
.111133.
........
The four square inches marked with X are claimed by both 1 and 2. (Claim 3, while adjacent to the others, does not overlap either of them.)
If the Elves all proceed with their own plans, none of them will have enough fabric. How many square inches of fabric are within two or more claims?"""
def render(array):
#print('\n'.join([''.join(['{:4}'.format(item) for item in row])
# for row in array]))
#print each row with a newline
for i in fabric:
print()
#print each collumn with no newline
for j in i:
print(j, end='')
def fill(array):
args=array.split()
# print(args)
wh = args[3].split("x")
# print(wh)
w = int(wh[0])
# print(w)
h = int(wh[1])
# print(h)
# extract x and y and format
xy = args[2].split(",")
# convert x and y
x = int(xy[0].replace(":",""))
y = int(xy[1].replace(":",""))
#def fill(x,y,w,h):
#fill in the fabric with a 'plan'
#TODO use the format they give
for g in range(0,w):
for r in range(0,h):
if fabric[r+y][g+x] == "X" or fabric[r+y][g+x] == "#":
fabric[r+y][g+x] = "X"
else:
fabric[r+y][g+x] = '#'
def countdup(array):
conflict=0
for g in range(0,len(array[0])):
for r in range(0,len(array)):
if fabric[g][r] == "X":
conflict=conflict+1
print(str(conflict) + " conflicts")
def overlapping(array):
args=array.split()
# print(args)
wh = args[3].split("x")
# print(wh)
w = int(wh[0])
# print(w)
h = int(wh[1])
# print(h)
# extract x and y and format
xy = args[2].split(",")
# convert x and y
x = int(xy[0].replace(":",""))
y = int(xy[1].replace(":",""))
#def fill(x,y,w,h):
#fill in the fabric with a 'plan'
#TODO use the format they give
overlap=0
for g in range(0,w):
for r in range(0,h):
if fabric[r+y][g+x] == "X":
overlap=1
if overlap==0:
print(args[0] + "had no overlap")
print("hello day3 puzzle3")
pats = open("day3input",'r')
##TODO: loop through lines
patshapes = pats.readlines()
##temp size
width = 1000
height = 1000
##input :
input1 = "#1 @ 1,3: 4x4"
input2 = "#2 @ 3,1: 4x4"
input3 = "#3 @ 5,5: 2x2"
#array will likely be 1000inches on all sides
fabric = [["."]*width for i in range(height)]
#too much spacing but it works to show the state of the array
for pat in patshapes:
fill(pat)
for pat in patshapes:
overlapping(pat)
print()
#render(fabric)
print()
#print(len(fabric[0]))
#print(len(fabric))
countdup(fabric)