add 2025 day 3 part 2

This commit is contained in:
2025-12-03 15:50:52 +01:00
parent 780dbc96ca
commit cc044cfc2f

44
2025/day-03/part-two.py Normal file
View File

@@ -0,0 +1,44 @@
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()