solved day 5a, removed useless day 4 code

kwout 2 years ago
parent 1e87a2eb67
commit 6cd6caa420
  1. 8
      2021/day4/4.py
  2. 29
      2021/day5/5a.py
  3. 10
      2021/day5/input.txt.sample

@ -4,8 +4,6 @@ boards = []
for s in range(2, len(lines),6): for s in range(2, len(lines),6):
boards.append([[int(j) for j in lines[i].split()] for i in range(s,s+5)]) boards.append([[int(j) for j in lines[i].split()] for i in range(s,s+5)])
earliestWin = len(draw)
winBoard = 0
winsOn = [-1] * len(boards) winsOn = [-1] * len(boards)
# i should really make an attempt to optimize this # i should really make an attempt to optimize this
@ -19,9 +17,6 @@ for b in range(0, len(boards)):
drawIndex = draw.index(boards[b][i][j]) drawIndex = draw.index(boards[b][i][j])
if drawIndex > latest: if drawIndex > latest:
latest = drawIndex latest = drawIndex
if latest < earliestWin and latest != 0:
earliestWin = latest
winBoard = b
if winsOn[b] == -1 or winsOn[b] > latest: if winsOn[b] == -1 or winsOn[b] > latest:
winsOn[b] = latest winsOn[b] = latest
latest = 0 latest = 0
@ -31,9 +26,6 @@ for b in range(0, len(boards)):
drawIndex = draw.index(boards[b][j][i]) drawIndex = draw.index(boards[b][j][i])
if drawIndex > latest: if drawIndex > latest:
latest = drawIndex latest = drawIndex
if latest < earliestWin and latest != 0:
earliestWin = latest
winBoard = b
if winsOn[b] > latest : if winsOn[b] > latest :
winsOn[b] = latest winsOn[b] = latest

@ -0,0 +1,29 @@
lines = []
for l in open("input.txt", 'r').read().splitlines():
p = l.split(" -> ")
q = []
q.append(p[0].split(","))
q.append(p[1].split(","))
lines.append([[int(q[0][0]),int(q[0][1])],[int(q[1][0]), int(q[1][1])]])
grid = [[0 for i in range(1000)] for j in range(1000)]
print(lines)
for l in lines:
if l[0][0] == l[1][0]:
if l[0][1] > l[1][1]:
l = (l[1],l[0])
for i in range(l[0][1], l[1][1]+1):
grid[l[0][0]][i] += 1
if l[0][1] == l[1][1]:
if l[0][0] > l[1][0]:
l = (l[1],l[0])
for i in range(l[0][0], l[1][0]+1):
grid[i][l[0][1]] += 1
overlaps=0
for m in grid:
print(m)
for n in m:
if n > 1:
overlaps += 1
print(overlaps)

@ -0,0 +1,10 @@
0,9 -> 5,9
8,0 -> 0,8
9,4 -> 3,4
2,2 -> 2,1
7,0 -> 7,4
6,4 -> 2,0
0,9 -> 2,9
3,4 -> 1,4
0,0 -> 8,8
5,5 -> 8,2
Loading…
Cancel
Save