From 014a263cd1019fb1ee1f8215a58952fa4fb21ca7 Mon Sep 17 00:00:00 2001 From: kleph Date: Sun, 12 Dec 2021 17:23:29 +0100 Subject: [PATCH] Please linter a bit --- .pylintrc | 3 ++- 1/1.py | 2 +- 2/2.py | 2 +- 2/2_2.py | 2 +- 4/4.py | 9 ++++----- 4/4_2.py | 9 ++++----- 5/5_2.py | 2 +- 7/7.py | 4 ++-- 8/8_2.py | 4 ++-- 9 files changed, 18 insertions(+), 19 deletions(-) diff --git a/.pylintrc b/.pylintrc index 9bfc778..a2e46bf 100644 --- a/.pylintrc +++ b/.pylintrc @@ -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 diff --git a/1/1.py b/1/1.py index 9846dc9..e6a4807 100755 --- a/1/1.py +++ b/1/1.py @@ -1,5 +1,5 @@ #!/usr/bin/env python -# 2021 - Advent Of Code 1 +# 2021 - Advent Of Code 1 count = 0 diff --git a/2/2.py b/2/2.py index e675069..0f655cd 100755 --- a/2/2.py +++ b/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: diff --git a/2/2_2.py b/2/2_2.py index c8e6854..d39ed4d 100755 --- a/2/2_2.py +++ b/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: diff --git a/4/4.py b/4/4.py index d96e358..9abf2a8 100755 --- a/4/4.py +++ b/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() diff --git a/4/4_2.py b/4/4_2.py index 8d3c407..d3541be 100755 --- a/4/4_2.py +++ b/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}') diff --git a/5/5_2.py b/5/5_2.py index 66a2e43..8360a15 100755 --- a/5/5_2.py +++ b/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 diff --git a/7/7.py b/7/7.py index 850f1c6..0ac4844 100755 --- a/7/7.py +++ b/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 diff --git a/8/8_2.py b/8/8_2.py index 6b15c3e..c059c3b 100755 --- a/8/8_2.py +++ b/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