Day 7, part 1
This commit is contained in:
parent
e910558507
commit
a58f59b31f
2
5.hs
2
5.hs
|
@ -15,7 +15,7 @@ next f (steps, i, jumps) =
|
|||
|
||||
getExitSteps :: Length -> Update -> State -> Int
|
||||
getExitSteps len f (steps, i, jumps) =
|
||||
if i >= len then steps else getExitSteps len f $ next f (steps, i, jumps)
|
||||
if i >= len then steps else getExitSteps len f $! next f (steps, i, jumps)
|
||||
|
||||
main :: IO ()
|
||||
main = do
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
import Data.HashSet (Set, fromList, delete)
|
||||
import Data.List.Split
|
||||
import Debug.Trace
|
||||
|
||||
type Weight = Int
|
||||
type Program = String
|
||||
type Programs = [Program]
|
||||
--type Tree = Map Program (Weight, Programs)
|
||||
|
||||
discardEmpty :: [String] -> [String]
|
||||
discardEmpty [""] = []
|
||||
discardEmpty xs = xs
|
||||
|
||||
parseLine :: String -> (Program, Weight, Programs)
|
||||
parseLine line =
|
||||
let nameAndWeight : programsString : _ = splitOn ")" line
|
||||
programs = discardEmpty $ splitOn ", " $ last $ splitOn " -> " programsString
|
||||
name : weight : _ = splitOn " (" nameAndWeight
|
||||
in (name, read weight, programs)
|
||||
|
||||
main :: IO ()
|
||||
main = do
|
||||
input <- readFile "7.txt"
|
||||
let list = map parseLine $ lines input
|
||||
names = fromList $ map (\(name, _, _) -> name) list
|
||||
bottom = foldr (\(name, _, programs) set ->
|
||||
case programs of
|
||||
[] -> delete name set
|
||||
ps -> foldr delete set ps)
|
||||
names list
|
||||
print $ bottom
|
Loading…
Reference in New Issue