File tree Expand file tree Collapse file tree 3 files changed +45
-8
lines changed
Expand file tree Collapse file tree 3 files changed +45
-8
lines changed Original file line number Diff line number Diff line change 1+ # Advent of code Day 05
2+ # https://adventofcode.com/2025/day/5
3+ # 05/12/2025
4+
5+ from collections import defaultdict
6+ from tqdm .auto import tqdm
7+
8+ with open ("input.txt" ) as file :
9+ inp = list (map (str .strip , file .readlines ()))
10+
11+ res1 , res2 = 0 , 0
12+
13+ stop = inp .index ("" )
14+ ranges = list (
15+ map (
16+ lambda x : tuple (map (int , x .split ("-" ))),
17+ inp [:stop ]
18+ )
19+ )
20+
21+ ingredients = list (
22+ map (
23+ int ,
24+ inp [stop + 1 :]
25+ )
26+ )
27+
28+ for ingredient in ingredients :
29+ for l , r in ranges :
30+ if l <= ingredient and ingredient <= r :
31+ res1 += 1
32+ break
33+
34+ ranges = sorted (ranges )
35+ for i in range (len (ranges ) - 1 ):
36+ l , r = ranges [i ]
37+ l1 , r1 = ranges [i + 1 ]
38+ if r >= l1 :
39+ ranges [i + 1 ] = (l , max (r , r1 ))
40+ ranges [i ] = (0 , - 1 )
41+
42+ for l , r in ranges :
43+ res2 += r - l + 1
44+
45+ print (res1 , res2 )
Load Diff This file was deleted.
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments