project_euler.problem_145.sol1

Project Euler problem 145: https://projecteuler.net/problem=145 Author: Vineet Rao, Maxim Smolskiy Problem statement:

Some positive integers n have the property that the sum [ n + reverse(n) ] consists entirely of odd (decimal) digits. For instance, 36 + 63 = 99 and 409 + 904 = 1313. We will call such numbers reversible; so 36, 63, 409, and 904 are reversible. Leading zeroes are not allowed in either n or reverse(n).

There are 120 reversible numbers below one-thousand.

How many reversible numbers are there below one-billion (10^9)?

Attributes

EVEN_DIGITS

ODD_DIGITS

Functions

benchmark(→ None)

Benchmarks

reversible_numbers(→ int)

Count the number of reversible numbers of given length.

slow_reversible_numbers(→ int)

Count the number of reversible numbers of given length.

slow_solution(→ int)

To evaluate the solution, use solution()

solution(→ int)

To evaluate the solution, use solution()

Module Contents

project_euler.problem_145.sol1.benchmark() None

Benchmarks

project_euler.problem_145.sol1.reversible_numbers(remaining_length: int, remainder: int, digits: list[int], length: int) int

Count the number of reversible numbers of given length. Iterate over possible digits considering parity of current sum remainder. >>> reversible_numbers(1, 0, [0], 1) 0 >>> reversible_numbers(2, 0, [0] * 2, 2) 20 >>> reversible_numbers(3, 0, [0] * 3, 3) 100

project_euler.problem_145.sol1.slow_reversible_numbers(remaining_length: int, remainder: int, digits: list[int], length: int) int

Count the number of reversible numbers of given length. Iterate over possible digits considering parity of current sum remainder. >>> slow_reversible_numbers(1, 0, [0], 1) 0 >>> slow_reversible_numbers(2, 0, [0] * 2, 2) 20 >>> slow_reversible_numbers(3, 0, [0] * 3, 3) 100

project_euler.problem_145.sol1.slow_solution(max_power: int = 9) int

To evaluate the solution, use solution() >>> slow_solution(3) 120 >>> slow_solution(6) 18720 >>> slow_solution(7) 68720

project_euler.problem_145.sol1.solution(max_power: int = 9) int

To evaluate the solution, use solution() >>> solution(3) 120 >>> solution(6) 18720 >>> solution(7) 68720

project_euler.problem_145.sol1.EVEN_DIGITS = [0, 2, 4, 6, 8]
project_euler.problem_145.sol1.ODD_DIGITS = [1, 3, 5, 7, 9]