Files
AdventOfCode2025/Problem5_1.py
2025-12-06 10:56:26 -05:00

58 lines
941 B
Python

def isInRange(num: int) -> bool:
for r in ranges :
if num >= r[0] and num <= r[1] :
return True
return False
testInput = [
"3-5",
"10-14",
"16-20",
"12-18",
"",
"1",
"5",
"8",
"11",
"17",
"32"
]
def readFile() :
ary = []
with open("files/Problem5.txt", "r") as file :
for line in file :
ary.append(line.replace("\n", ""))
return ary
def parseInput(input: list[str]):
ranges = []
numbers = []
readingRanges = True
for line in input:
if line == "":
readingRanges = False
continue
if readingRanges:
parts = line.split("-")
ranges.append((int(parts[0]), int(parts[1])))
else:
numbers.append(int(line))
return ranges, numbers
#rawInput = testInput
rawInput = readFile()
ranges, numbers = parseInput(rawInput)
freshCount = 0
spoiledCount = 0
for number in numbers :
if isInRange(number):
freshCount += 1
else:
spoiledCount += 1
print(f"Fresh count: {freshCount}")
#Fresh count: 848