From 491eb89201a1e3adf559eb932c08837e2fad3707 Mon Sep 17 00:00:00 2001 From: Daniele Fucini Date: Sun, 10 Nov 2024 10:09:39 +0100 Subject: [PATCH] Add type hints in problems 51-53 --- Python/p051.py | 15 ++++++++------- Python/p052.py | 3 ++- Python/p053.py | 2 +- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/Python/p051.py b/Python/p051.py index 361b251..b420465 100644 --- a/Python/p051.py +++ b/Python/p051.py @@ -17,7 +17,7 @@ N = 1000000 primes = sieve(N) -def count_digit(n, d): +def count_digit(n: int, d: int) -> int: count = 0 while n > 0: @@ -28,10 +28,10 @@ def count_digit(n, d): return count -def replace(n): +def replace(n: int) -> int: n_string = list(str(n)) l = len(n_string) - max_ = 0 + _max = 0 for i in range(l-3): for j in range(i+1, l-2): @@ -54,16 +54,16 @@ def replace(n): if primes[n_replaced] == 1: if count == 0 and n_replaced != n: continue + count = count + 1 - if count > max_: - max_ = count + _max = max(_max, count) - return max_ + return _max @timing -def p051(): +def p051() -> None: # Checking only odd numbers with at least 4 digits. i = 1001 @@ -78,6 +78,7 @@ def p051(): count_digit(i, 2) >= 3: if primes[i] == 1 and replace(i) == 8: break + i = i + 2 print('Project Euler, Problem 51') diff --git a/Python/p052.py b/Python/p052.py index 5db0958..fc72233 100644 --- a/Python/p052.py +++ b/Python/p052.py @@ -8,7 +8,7 @@ from projecteuler import timing @timing -def p052(): +def p052() -> None: i = 1 # Brute force approach, try every integer number until the desired one is found. @@ -19,6 +19,7 @@ def p052(): ''.join(sorted(str(i))) == ''.join(sorted(str(5*i))) and\ ''.join(sorted(str(i))) == ''.join(sorted(str(6*i))): break + i = i + 1 print('Project Euler, Problem 52') diff --git a/Python/p053.py b/Python/p053.py index 1cb1342..8d2d434 100644 --- a/Python/p053.py +++ b/Python/p053.py @@ -18,7 +18,7 @@ from projecteuler import timing @timing -def p053(): +def p053() -> None: LIMIT = 1000000 count = 0