This commit is contained in:
parent
04bbeec472
commit
014a263cd1
9 changed files with 18 additions and 19 deletions
|
@ -2,5 +2,6 @@
|
|||
# C0111: Missing docstring
|
||||
# C0103: snake_case names (and one letter index vars)
|
||||
# R0801: Similar lines in N files
|
||||
disable=R0801,C0111,C0103
|
||||
# C0301: line too long
|
||||
disable=R0801,C0111,C0103,C0301
|
||||
|
||||
|
|
2
2/2.py
2
2/2.py
|
@ -6,7 +6,7 @@ import re
|
|||
x = 0
|
||||
y = 0
|
||||
|
||||
re_parse = re.compile('(forward|up|down) (\d+)')
|
||||
re_parse = re.compile(r'(forward|up|down) (\d+)')
|
||||
|
||||
with open('input.txt') as f:
|
||||
for line in f:
|
||||
|
|
2
2/2_2.py
2
2/2_2.py
|
@ -7,7 +7,7 @@ x = 0
|
|||
y = 0
|
||||
aim = 0
|
||||
|
||||
re_parse = re.compile('(forward|up|down) (\d+)')
|
||||
re_parse = re.compile(r'(forward|up|down) (\d+)')
|
||||
|
||||
with open('input.txt') as f:
|
||||
for line in f:
|
||||
|
|
9
4/4.py
9
4/4.py
|
@ -41,8 +41,7 @@ class Board:
|
|||
for line in range(GRID_SIZE):
|
||||
if self.marked[line][c] == 0:
|
||||
break
|
||||
else:
|
||||
col_sum += 1
|
||||
col_sum += 1
|
||||
if col_sum == GRID_SIZE:
|
||||
return True
|
||||
return False
|
||||
|
@ -64,7 +63,7 @@ def parse_file(file):
|
|||
line = f.readline()
|
||||
while line:
|
||||
board = []
|
||||
for i in range(GRID_SIZE):
|
||||
for _ in range(GRID_SIZE):
|
||||
line = f.readline()
|
||||
m = re_parse.match(line)
|
||||
grid_line = m.groups()
|
||||
|
@ -87,10 +86,10 @@ def play_until_win(boards_list, draws):
|
|||
return board, d
|
||||
|
||||
|
||||
boards, draws = parse_file('input.txt')
|
||||
boards, calls = parse_file('input.txt')
|
||||
print(f'number of boards: {len(boards)}')
|
||||
|
||||
(winning_board, last_num) = play_until_win(boards, draws)
|
||||
(winning_board, last_num) = play_until_win(boards, calls)
|
||||
print(f'last number is: {last_num}')
|
||||
|
||||
board_score = winning_board.calc_unmarked()
|
||||
|
|
9
4/4_2.py
9
4/4_2.py
|
@ -41,8 +41,7 @@ class Board:
|
|||
for line in range(GRID_SIZE):
|
||||
if self.marked[line][c] == 0:
|
||||
break
|
||||
else:
|
||||
col_sum += 1
|
||||
col_sum += 1
|
||||
if col_sum == GRID_SIZE:
|
||||
return True
|
||||
return False
|
||||
|
@ -64,7 +63,7 @@ def parse_file(file):
|
|||
line = f.readline()
|
||||
while line:
|
||||
board = []
|
||||
for i in range(GRID_SIZE):
|
||||
for _ in range(GRID_SIZE):
|
||||
line = f.readline()
|
||||
m = re_parse.match(line)
|
||||
grid_line = m.groups()
|
||||
|
@ -113,11 +112,11 @@ def play(boards_list, draws):
|
|||
return winners
|
||||
|
||||
|
||||
boards, draws = parse_file('input.txt')
|
||||
boards, calls = parse_file('input.txt')
|
||||
print(f'number of boards: {len(boards)}')
|
||||
|
||||
# (winning_board, last_num) = play_until_win(boards, draws)
|
||||
winning_boards = play(boards, draws)
|
||||
winning_boards = play(boards, calls)
|
||||
|
||||
winning_board, last_num = winning_boards[-1]
|
||||
print(f'last number is: {last_num}')
|
||||
|
|
2
5/5_2.py
2
5/5_2.py
|
@ -71,7 +71,7 @@ def draw_diagonal(g, dline):
|
|||
|
||||
lx = x1
|
||||
ly = y1
|
||||
for i in range(abs(x2-x1)+1):
|
||||
for _ in range(abs(x2-x1)+1):
|
||||
g[ly][lx] += 1
|
||||
lx += hdir
|
||||
ly += vdir
|
||||
|
|
4
7/7.py
4
7/7.py
|
@ -10,7 +10,7 @@ def parse_file(file):
|
|||
return list_state
|
||||
|
||||
|
||||
#init_state = parse_file('input_example.txt')
|
||||
# init_state = parse_file('input_example.txt')
|
||||
init_state = parse_file('input.txt')
|
||||
nb_crabs = len(init_state)
|
||||
print(f'Initial state with {nb_crabs} crabs: {init_state}')
|
||||
|
@ -22,7 +22,7 @@ min_fuel = max_h * nb_crabs
|
|||
min_fuel_pos = 0
|
||||
for m in range(max_h):
|
||||
list_diff = [abs(m-x) for x in init_state]
|
||||
if (sum(list_diff) < min_fuel):
|
||||
if sum(list_diff) < min_fuel:
|
||||
min_fuel = sum(list_diff)
|
||||
min_fuel_pos = m
|
||||
|
||||
|
|
4
8/8_2.py
4
8/8_2.py
|
@ -38,7 +38,7 @@ for entry, display in zip(entries, displays):
|
|||
# size 6 pattern that doesn't include 4, nor 1 -> 6
|
||||
# size 6 pattern that includes 4 and 1 -> 9
|
||||
# the remaining size 6 pattern -> 0
|
||||
size_six = set([x for x in words if len(x) == 6])
|
||||
size_six = {x for x in words if len(x) == 6}
|
||||
for s in size_six:
|
||||
if identified_numbers[1].issubset(s) and identified_numbers[4].issubset(s):
|
||||
identified_numbers[9] = s
|
||||
|
@ -54,7 +54,7 @@ for entry, display in zip(entries, displays):
|
|||
# size 5 pattern that includes 7 -> 3
|
||||
# size 5 pattern that only missed one element to be a 9 pattern -> 5
|
||||
# the remaining size 5 pattern -> 2
|
||||
size_five = set([x for x in words if len(x) == 5])
|
||||
size_five = {x for x in words if len(x) == 5}
|
||||
for s in size_five:
|
||||
if identified_numbers[7].issubset(s):
|
||||
identified_numbers[3] = s
|
||||
|
|
Loading…
Reference in a new issue