File tree Expand file tree Collapse file tree 2 files changed +35
-0
lines changed Expand file tree Collapse file tree 2 files changed +35
-0
lines changed Original file line number Diff line number Diff line change 8
8
| [ Day 4: Camp Cleanup] ( https://adventofcode.com/2022/day/4 ) | [ py] ( /day04/main.py ) |
9
9
| [ Day 5: Supply Stacks] ( https://adventofcode.com/2022/day/5 ) | [ py] ( /day05/main.py ) |
10
10
| [ Day 6: Tuning Trouble] ( https://adventofcode.com/2022/day/6 ) | [ py] ( /day06/main.py ) , [ alt] ( /day06/alt.py ) |
11
+ | [ Day 7: No Space Left On Device] ( https://adventofcode.com/2022/day/7 ) | [ py] ( /day07/main.py ) |
11
12
12
13
My solutions from previous years:
13
14
* [ r0f1/adventofcode2020] ( https://github.com/r0f1/adventofcode2020 )
Original file line number Diff line number Diff line change
1
+ with open ("input.txt" ) as f :
2
+ lines = [x .strip ().split () for x in f ]
3
+
4
+ root = {".name" : "/" , ".type" : "d" }
5
+ cwd = None
6
+ path = []
7
+ for t in lines :
8
+ if t [0 ] == "$" :
9
+ if t [1 ] == "cd" :
10
+ if t [2 ] == "/" : cwd = root
11
+ elif t [2 ] == ".." : cwd = path .pop ()
12
+ else : path .append (cwd ); cwd = cwd [t [2 ]]
13
+ elif t [0 ] == "dir" : cwd [t [1 ]] = {".name" : t [1 ], ".type" : "d" }
14
+ else : cwd [t [1 ]] = {".name" : t [1 ], ".type" : "f" , ".size" : int (t [0 ])}
15
+
16
+ def get_size (n ):
17
+ if n [".type" ] == "f" : return n [".size" ]
18
+ return sum (get_size (v ) for k , v in n .items () if not k .startswith ("." ))
19
+
20
+ def create_size_list (cwd , all_sizes ):
21
+ all_sizes .append (get_size (cwd ))
22
+ for k , v in cwd .items ():
23
+ if not k .startswith ("." ) and v [".type" ] == "d" :
24
+ create_size_list (v , all_sizes )
25
+
26
+ all_sizes = []
27
+ create_size_list (root , all_sizes )
28
+ print (sum ([s for s in all_sizes if s < 100_000 ]))
29
+
30
+ size_free = 70_000_000 - all_sizes [0 ]
31
+ for d in sorted (all_sizes ):
32
+ if size_free + d >= 30_000_000 :
33
+ print (d )
34
+ break
You can’t perform that action at this time.
0 commit comments