|
@@ -81,7 +81,6 @@ filterDirectories predicate dir = filter (\(_, size) -> predicate size) $ sizeOf
|
81
|
81
|
sumUp :: [(String, Int)] -> Int
|
82
|
82
|
sumUp = sum . map snd
|
83
|
83
|
|
84
|
|
-
|
85
|
84
|
forceRight :: Either a b -> b
|
86
|
85
|
forceRight (Left _) = error "forced Right but got Left"
|
87
|
86
|
forceRight (Right b) = b
|
|
@@ -92,6 +91,16 @@ day7 = do
|
92
|
91
|
putStrLn "Day7"
|
93
|
92
|
let parsed = forceRight $ parseTerminalLines input
|
94
|
93
|
let tree = buildTree parsed
|
95
|
|
- let filtered = filterDirectories (<= 100000) tree
|
96
|
|
- let summed = sumUp filtered
|
97
|
|
- putStrLn ("Sum of those directories is " ++ show summed)
|
|
94
|
+ let small = filterDirectories (<= 100000) tree
|
|
95
|
+ let sumOfSmall = sumUp small
|
|
96
|
+ putStrLn ("Sum of those directories is " ++ show sumOfSmall)
|
|
97
|
+ let rootSize = snd . head $ sizeOfDirectories tree
|
|
98
|
+ putStrLn ("Root size is " ++ show rootSize)
|
|
99
|
+ let freeSpace = 70000000 - rootSize
|
|
100
|
+ let requiredSpace = 30000000 - freeSpace
|
|
101
|
+ putStrLn ("Required space is " ++ show requiredSpace)
|
|
102
|
+ let bigEnough = filterDirectories (>= requiredSpace) tree
|
|
103
|
+ let onlySizes = map snd bigEnough
|
|
104
|
+ let smallest = minimum onlySizes
|
|
105
|
+ putStrLn ("Smallest directory that is still large enough " ++ show smallest)
|
|
106
|
+
|