-
-
Save mb6ockatf/3b58bd826f2661e6e78ebeb86730f6b2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
def is_n_digit(number: int, digits: int) -> bool: | |
return len(str(abs(number))) == digits | |
file = open("17.txt", "r") | |
numbers = list(map(int, file.readlines())) | |
max_strange_num = 0 | |
for element in numbers: | |
if not str(element).endswith("15"): | |
continue | |
max_strange_num = max(max_strange_num, element) | |
valid_triples_num = 0 | |
minimal_sum_num = 0 | |
for i in range(len(numbers) - 2): | |
distance = numbers[i:i + 3] | |
a, b, c = distance | |
total = sum(distance) | |
if list(map(is_n_digit, distance, [4] * 3)).count(True) == 1 and \ | |
total < max_strange_num: | |
valid_triples_num += 1 | |
minimal_sum_num = min(minimal_sum_num, total) | |
print(valid_triples_num, minimal_sum_num) | |
file.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment