Skip to content

Commit 8d62816

Browse files
committed
Switch to ruff check and ruff format
1 parent 316d7d2 commit 8d62816

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+165
-221
lines changed

python/GNUmakefile

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11

2-
SRCS := .gitignore solve.py README.md
32
SUBDIRS = euler tests
43

54
.PHONY: usage
@@ -27,14 +26,11 @@ clean-all:
2726

2827
.PHONY: lint
2928
lint:
30-
flake8 .
31-
isort --check --diff .
32-
black --check --diff .
29+
ruff check
3330

3431
.PHONY: format
3532
format:
36-
isort .
37-
black .
33+
ruff format --diff
3834

3935
.PHONY: list
4036
list:

python/euler/bin/p0003.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44

55

66
def compute(num: int) -> str:
7-
return str(factorize(num)[-1][0]) # [(b1,e1), (b2,e2), ...] (b{i}<b{j} when i<j)
7+
# [(b1,e1), (b2,e2), ...] (b{i}<b{j} when i<j)
8+
return str(factorize(num)[-1][0])
89

910

1011
def solve() -> str:

python/euler/bin/p0004.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def compute(digits: int) -> str:
2828
if answer:
2929
return str(max(answer))
3030

31-
assert False, 'unreachable!'
31+
raise RuntimeError('unreachable!')
3232

3333

3434
def solve() -> str:

python/euler/bin/p0011.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
# fmt: off
66
grid_arr = [
7-
[ 8, 2, 22, 97, 38, 15, 0, 40, 0, 75, 4, 5, 7, 78, 52, 12, 50, 77, 91, 8], # noqa: E201
7+
[ 8, 2, 22, 97, 38, 15, 0, 40, 0, 75, 4, 5, 7, 78, 52, 12, 50, 77, 91, 8],
88
[49, 49, 99, 40, 17, 81, 18, 57, 60, 87, 17, 40, 98, 43, 69, 48, 4, 56, 62, 0],
99
[81, 49, 31, 73, 55, 79, 14, 29, 93, 71, 40, 67, 53, 88, 30, 3, 49, 13, 36, 65],
1010
[52, 70, 95, 23, 4, 60, 11, 42, 69, 24, 68, 56, 1, 32, 56, 71, 37, 2, 36, 91],
@@ -18,12 +18,12 @@
1818
[16, 39, 5, 42, 96, 35, 31, 47, 55, 58, 88, 24, 0, 17, 54, 24, 36, 29, 85, 57],
1919
[86, 56, 0, 48, 35, 71, 89, 7, 5, 44, 44, 37, 44, 60, 21, 58, 51, 54, 17, 58],
2020
[19, 80, 81, 68, 5, 94, 47, 69, 28, 73, 92, 13, 86, 52, 17, 77, 4, 89, 55, 40],
21-
[ 4, 52, 8, 83, 97, 35, 99, 16, 7, 97, 57, 32, 16, 26, 26, 79, 33, 27, 98, 66], # noqa: E201
21+
[ 4, 52, 8, 83, 97, 35, 99, 16, 7, 97, 57, 32, 16, 26, 26, 79, 33, 27, 98, 66],
2222
[88, 36, 68, 87, 57, 62, 20, 72, 3, 46, 33, 67, 46, 55, 12, 32, 63, 93, 53, 69],
23-
[ 4, 42, 16, 73, 38, 25, 39, 11, 24, 94, 72, 18, 8, 46, 29, 32, 40, 62, 76, 36], # noqa: E201
23+
[ 4, 42, 16, 73, 38, 25, 39, 11, 24, 94, 72, 18, 8, 46, 29, 32, 40, 62, 76, 36],
2424
[20, 69, 36, 41, 72, 30, 23, 88, 34, 62, 99, 69, 82, 67, 59, 85, 74, 4, 36, 16],
2525
[20, 73, 35, 29, 78, 31, 90, 1, 74, 31, 49, 71, 48, 86, 81, 16, 23, 57, 5, 54],
26-
[ 1, 70, 54, 71, 83, 51, 54, 69, 16, 92, 33, 48, 61, 43, 52, 1, 89, 19, 67, 48], # noqa: E201
26+
[ 1, 70, 54, 71, 83, 51, 54, 69, 16, 92, 33, 48, 61, 43, 52, 1, 89, 19, 67, 48],
2727
]
2828
# fmt: on
2929

@@ -47,7 +47,7 @@ def product(row: int, col: int, dir: Dir) -> int:
4747
case Dir.DOWN_RIGHT:
4848
v *= grid_arr[row + i][col + i]
4949
case _:
50-
assert False, 'Direction Error'
50+
raise AssertionError('Direction Error')
5151

5252
return v
5353

python/euler/bin/p0014.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ def compute(limit: int) -> str:
55
cache = [0] * limit
66
cache[1] = 1
77

8-
for cur in range(limit // 2, limit):
8+
for n in range(limit // 2, limit):
9+
cur = n
910
if cache[cur] != 0:
1011
continue
1112

python/euler/bin/p0018.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,13 @@
2121
[70, 11, 33, 28, 77, 73, 17, 78, 39, 68, 17, 57],
2222
[91, 71, 52, 38, 17, 14, 91, 43, 58, 50, 27, 29, 48],
2323
[63, 66, 4, 68, 89, 53, 67, 30, 73, 16, 69, 87, 40, 31],
24-
[ 4, 62, 98, 27, 23, 9, 70, 98, 73, 93, 38, 53, 60, 4, 23] # noqa
24+
[ 4, 62, 98, 27, 23, 9, 70, 98, 73, 93, 38, 53, 60, 4, 23]
2525
]
2626
# fmt: on
2727

2828

2929
def compute(fn: Callable[..., int], nums: list[list[int]]) -> str:
30-
return str(
31-
reduce(lambda x, y: list(map(add, map(fn, pairwise(x)), y)), reversed(nums))[0]
32-
)
30+
return str(reduce(lambda x, y: list(map(add, map(fn, pairwise(x)), y)), reversed(nums))[0])
3331

3432

3533
def solve() -> str:

python/euler/bin/p0021.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@
66
def compute(num: int) -> str:
77
tbl = aliquot_sum_tbl(num - 1)
88

9-
return str(
10-
sum(x + tbl[x] for x in range(2, len(tbl)) if x > tbl[x] and tbl[tbl[x]] == x)
11-
)
9+
return str(sum(x + tbl[x] for x in range(2, len(tbl)) if x > tbl[x] and tbl[tbl[x]] == x))
1210

1311

1412
def solve() -> str:

python/euler/bin/p0026.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def find_repetend_length(d: int) -> int:
2828
if pow(10, k, d) == 1:
2929
return k
3030

31-
assert False, 'unreachable!'
31+
raise RuntimeError('unreachable!')
3232

3333

3434
def compute(limit: int) -> str:

python/euler/bin/p0027.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@ def compute() -> str:
2929
max_len = 0
3030
max_tpl = (0, 0)
3131
for b in filter(lambda x: x < 1000, p_lst[1:]):
32-
for a in map(
33-
lambda x: x - b - 1, filter(lambda x: abs(x - b - 1) < 1000, p_lst)
34-
):
32+
for a in map(lambda x: x - b - 1, filter(lambda x: abs(x - b - 1) < 1000, p_lst)):
3533
if (length := count_consecutive(a, b)) > max_len:
3634
max_len = length
3735
max_tpl = (a, b)

python/euler/bin/p0030.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,7 @@ def aux(n: int) -> list[int]:
5555

5656
# The chain.from_iterable() method is not used for readability here.
5757
for ndigits in range(2, 7):
58-
for tpl in combinations_with_replacement(
59-
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], ndigits
60-
):
58+
for tpl in combinations_with_replacement([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], ndigits):
6159
n = sum(map(lambda x: pow_tbl[x], tpl))
6260
if to_digit_tpl(n) == tpl:
6361
acc += n

0 commit comments

Comments
 (0)