Day 7, part 1 - minor adjustments

This commit is contained in:
Jonathan Chan 2017-12-06 22:26:30 -08:00
parent a58f59b31f
commit 91d0fb46bc
1 changed files with 4 additions and 6 deletions

6
7.hs
View File

@ -1,11 +1,9 @@
import Data.HashSet (Set, fromList, delete) import Data.HashSet (Set, fromList, delete)
import Data.List.Split import Data.List.Split
import Debug.Trace
type Weight = Int type Weight = Int
type Program = String type Program = String
type Programs = [Program] type Programs = [Program]
--type Tree = Map Program (Weight, Programs)
discardEmpty :: [String] -> [String] discardEmpty :: [String] -> [String]
discardEmpty [""] = [] discardEmpty [""] = []
@ -22,10 +20,10 @@ main :: IO ()
main = do main = do
input <- readFile "7.txt" input <- readFile "7.txt"
let list = map parseLine $ lines input let list = map parseLine $ lines input
names = fromList $ map (\(name, _, _) -> name) list nameSet = fromList $ map (\(name, _, _) -> name) list
bottom = foldr (\(name, _, programs) set -> bottom = foldr (\(name, _, programs) set ->
case programs of case programs of
[] -> delete name set [] -> delete name set
ps -> foldr delete set ps) ps -> foldr delete set ps)
names list nameSet list
print $ bottom print $ bottom