commit 6614890562975a2d5fe38315d0dd8cd745af12c2
parent 506eb0488e149527292b08544d92b074e75ba2db
Author: bsandro <email@bsandro.tech>
Date: Wed, 7 Dec 2022 08:09:21 +0000
Day 07 part 2
Diffstat:
1 file changed, 15 insertions(+), 7 deletions(-)
diff --git a/day07/main.go b/day07/main.go
@@ -101,17 +101,25 @@ func day07(input_file string) {
sort.Sort(dirs)
const sizeLimit = 100000
- var dirsFiltered Dirs
- size := 0
+ const fsSize = 70000000
+ const updSize = 30000000
+
+ totalSize := 0
+ delSize := -1
+ freeSpace := fsSize - dirs[0].Size
+ clearSpace := updSize - freeSpace
for _, d := range dirs {
if d.Size < 100000 {
- dirsFiltered = append(dirsFiltered, d)
- size += d.Size
+ totalSize += d.Size
+ }
+ if delSize == -1 {
+ delSize = d.Size
+ } else if d.Size >= clearSpace && d.Size < delSize {
+ delSize = d.Size
}
}
- //fmt.Println("---Dirs---")
- //fmt.Println(dirsFiltered)
- fmt.Printf("size: %d\n", size)
+ fmt.Printf("Part 1: %d\n", totalSize)
+ fmt.Printf("Part 2: %d\n", delSize)
//fmt.Printf("max: %d\n", getMaxSize(dirsFiltered, 100000))
}