Browse Source

Day 6 update

master
Noëlle 3 years ago
parent
commit
bc56944ca3
No known key found for this signature in database
6 changed files with 15 additions and 17 deletions
  1. 0
    4
      aoc4-1.py
  2. 1
    5
      aoc4-2.py
  3. 1
    2
      aoc5-1.py
  4. 11
    4
      aoc5-2.py
  5. 0
    1
      aoc6-1.py
  6. 2
    1
      aoc6-2.py

+ 0
- 4
aoc4-1.py View File

self.marks.append([0]*self.boardsize) self.marks.append([0]*self.boardsize)


def mark(self, digit): def mark(self, digit):
import pdb
# if self.boardnum == 1:
# pdb.set_trace()
for i, line in enumerate(self.lines): for i, line in enumerate(self.lines):
if digit in line: if digit in line:
y = i y = i
outstr += f"{' '.join([str(el).rjust(2) for el in self.lines[i]])} {' '.join([str(el).rjust(2) for el in self.marks[i]])}\n" outstr += f"{' '.join([str(el).rjust(2) for el in self.lines[i]])} {' '.join([str(el).rjust(2) for el in self.marks[i]])}\n"
return outstr return outstr



def main(): def main():
with open("aoc4-1.txt", "r") as file: with open("aoc4-1.txt", "r") as file:
lines = [line.strip() for line in file.readlines()] lines = [line.strip() for line in file.readlines()]

+ 1
- 5
aoc4-2.py View File

self.marks.append([0]*self.boardsize) self.marks.append([0]*self.boardsize)


def mark(self, digit): def mark(self, digit):
import pdb
# if self.boardnum == 1:
# pdb.set_trace()
for i, line in enumerate(self.lines): for i, line in enumerate(self.lines):
if digit in line: if digit in line:
y = i y = i
outstr += f"{' '.join([str(el).rjust(2) for el in self.lines[i]])} {' '.join([str(el).rjust(2) for el in self.marks[i]])}\n" outstr += f"{' '.join([str(el).rjust(2) for el in self.lines[i]])} {' '.join([str(el).rjust(2) for el in self.marks[i]])}\n"
return outstr return outstr



def main(): def main():
with open("aoc4-1.txt", "r") as file: with open("aoc4-1.txt", "r") as file:
lines = [line.strip() for line in file.readlines()] lines = [line.strip() for line in file.readlines()]
i += 6 i += 6
for el in firstline: for el in firstline:
print(el) print(el)
is_to_pop = []
is_to_pop = [] # that's the plural of "i"
for i, board in enumerate(boards): for i, board in enumerate(boards):
board.mark(el) board.mark(el)
if board.check(): if board.check():

+ 1
- 2
aoc5-1.py View File

# For 5-1, only care about the ones where, of x1,y1 -> x2,y2, x1 == x2 or y1 == y2 # For 5-1, only care about the ones where, of x1,y1 -> x2,y2, x1 == x2 or y1 == y2
# i.e. only horizontal or vertical # i.e. only horizontal or vertical
lines = [line for line in lines if line[0][0] == line[1][0] or line[0][1] == line[1][1]] lines = [line for line in lines if line[0][0] == line[1][0] or line[0][1] == line[1][1]]
# god, this feels goofy
# god, this feels goofy, but it works
size_x = max([max(line[0][0], line[1][0]) for line in lines]) size_x = max([max(line[0][0], line[1][0]) for line in lines])
size_y = max([max(line[0][1], line[1][1]) for line in lines]) size_y = max([max(line[0][1], line[1][1]) for line in lines])
board_map = FloorMap(size_x, size_y) board_map = FloorMap(size_x, size_y)
board_map.add_line(*line) board_map.add_line(*line)
print(board_map.count_inters()) print(board_map.count_inters())



if __name__ == "__main__": if __name__ == "__main__":
main() main()

+ 11
- 4
aoc5-2.py View File

self.board.append([0]*(size_x+1)) self.board.append([0]*(size_x+1))


def add_line(self, start_pos, end_pos): def add_line(self, start_pos, end_pos):
if start_pos[0] == end_pos[0]:
if start_pos[0] == end_pos[0]: # Vertical line: X stays constant, Y changes
if start_pos[1] > end_pos[1]: if start_pos[1] > end_pos[1]:
start_pos, end_pos = end_pos, start_pos start_pos, end_pos = end_pos, start_pos
for i in range(start_pos[1], end_pos[1]+1): for i in range(start_pos[1], end_pos[1]+1):
self.board[i][start_pos[0]] = self.board[i][start_pos[0]] + 1 self.board[i][start_pos[0]] = self.board[i][start_pos[0]] + 1
elif start_pos[1] == end_pos[1]:
elif start_pos[1] == end_pos[1]: # Horizontal line: Y stays constant, X changes
if start_pos[0] > end_pos[0]: if start_pos[0] > end_pos[0]:
start_pos, end_pos = end_pos, start_pos start_pos, end_pos = end_pos, start_pos
for i in range(start_pos[0], end_pos[0]+1): for i in range(start_pos[0], end_pos[0]+1):
self.board[start_pos[1]][i] = self.board[start_pos[1]][i] + 1 self.board[start_pos[1]][i] = self.board[start_pos[1]][i] + 1
else:
else: # Diagonal line: X and Y both change
# These are only ever 45° angles, so each changes by 1 per iteration.
if start_pos[0] > end_pos[0]: if start_pos[0] > end_pos[0]:
start_pos, end_pos = end_pos, start_pos start_pos, end_pos = end_pos, start_pos
i, j = start_pos i, j = start_pos
end_i, end_j = end_pos[0], end_pos[1] end_i, end_j = end_pos[0], end_pos[1]
# I've arranged this so X always increases. Y can either increase or decrease.
# I don't like that so much repeats.
# What I WANT to do here is be able to set a toggle variable so that
# if Y decreases, the second condition flips from <= to >=,
# and then j += dir, which is either 1 or -1.
# But I can't find a way to do it without eval() bullshit.
if j <= end_j: # there should be no cases where they're equal, but... if j <= end_j: # there should be no cases where they're equal, but...
while i <= end_i and j <= end_j: while i <= end_i and j <= end_j:
self.board[j][i] = self.board[j][i] + 1 self.board[j][i] = self.board[j][i] + 1
lines = [line.strip() for line in file.readlines()] lines = [line.strip() for line in file.readlines()]
# Each line is a pair of x,y coordinates...es separated by " -> " # Each line is a pair of x,y coordinates...es separated by " -> "
lines = [[list(map(int, el.split(","))) for el in line.split(" -> ")] for line in lines] lines = [[list(map(int, el.split(","))) for el in line.split(" -> ")] for line in lines]
# god, this feels goofy
# god, this feels goofy, but it works
size_x = max([max(line[0][0], line[1][0]) for line in lines]) size_x = max([max(line[0][0], line[1][0]) for line in lines])
size_y = max([max(line[0][1], line[1][1]) for line in lines]) size_y = max([max(line[0][1], line[1][1]) for line in lines])
board_map = FloorMap(size_x, size_y) board_map = FloorMap(size_x, size_y)

+ 0
- 1
aoc6-1.py View File

print(len(fishes)) print(len(fishes))
return len(fishes) return len(fishes)



if __name__ == "__main__": if __name__ == "__main__":
main() main()

+ 2
- 1
aoc6-2.py View File

self.time_left["ttr"] = 0 self.time_left["ttr"] = 0
if self.school_size() >= self.size_base: if self.school_size() >= self.size_base:
print(f"School size now {self.school_size()}.") print(f"School size now {self.school_size()}.")
self.size_base += self.size_inc


def school_size(self): def school_size(self):
total = 0 total = 0
return total return total


def main(): def main():
# The old version gets untenable above about 100 days.
# The 6-1 version gets untenable above about 100 days.
# Trying a different approach. # Trying a different approach.
num_days = 256 num_days = 256
with open("aoc6-1.txt", "r") as file: with open("aoc6-1.txt", "r") as file:

Loading…
Cancel
Save