Files
advent-of-code/2025/day-03/part-one.py
2025-12-03 14:27:14 +01:00

44 lines
1.1 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 += findHighestPair(line)
logger.info("Output: " + str(output))
# print(findHighestPair("818181911112111")) # Should return 5
def findHighestPair(x):
i1 = findHighestNumberIndex(x[:len(x) - 1])
# print(i1)
i2 = findHighestNumberIndex(x[i1 + 1:])
# print(i2)
# print("Highest pair in " + x + " : " + x[i1] + x[i1 + 1 + i2])
return int(x[i1] + x[i1 + 1 + i2])
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()