45 lines
1.2 KiB
Python
45 lines
1.2 KiB
Python
import logging
|
|
import sys
|
|
|
|
# Logger setup
|
|
logger = logging.getLogger(__name__)
|
|
logger.setLevel(logging.INFO)
|
|
stream_handler = logging.StreamHandler()
|
|
logger.addHandler(stream_handler)
|
|
|
|
def main():
|
|
output = 0
|
|
logger.debug("Init output with value: " + str(output))
|
|
with open("input.txt", "r") as input:
|
|
for line in input:
|
|
line = line.strip()
|
|
output += findHighestCombination(line, 12)
|
|
logger.info("Output: " + str(output))
|
|
|
|
def findHighestCombination(x, n):
|
|
output = []
|
|
returnVal = 0
|
|
output.append(findHighestNumberIndex(x[:len(x) - n]))
|
|
returnVal = x[output[0]]
|
|
for i in range(1, n):
|
|
h_i = findHighestNumberIndex(x[output[i - 1] + 1:len(x) - n + i + 1])
|
|
output.append(h_i + output[i - 1] + 1)
|
|
returnVal += x[output[i]]
|
|
return int(returnVal)
|
|
|
|
def findHighestNumberIndex(x):
|
|
logger.debug("findHighestNumberIndex(" + x + ")")
|
|
highest = 0
|
|
index = -1
|
|
for i in range(len(x)):
|
|
val = int(x[i])
|
|
if(val > highest):
|
|
highest = val
|
|
index = i
|
|
if(highest == 9):
|
|
break
|
|
return index
|
|
|
|
if __name__ == "__main__":
|
|
main()
|