 ## ¿Dónde iniciar la carrera?en Haskell

por josejuan hace 6 años

El problema consiste en parsear los datos...

Resuelve el problema de elección del inicio de la carrera escolar (C)

 `1` `2` `3` `4` `5` `6` `7` `8` `9` `10` `11` `12` `13` `14` `15` `16` `17` `18` `19` `20` `21` `22` `23` `24` `25` `26` `27` `28` `29` `30` `31` `32` `33` `34` `35` `36` `37` `38` `39` `40` `41` `42` `43` `44` `45` `46` `47` `48` `49` `50` `51` `52` `53` `54` `55` `56` `57` `58` `59`
 ``{-# LANGUAGE TupleSections #-} `` ``import Data.Graph.Inductive.Graph `` ``import Data.Graph.Inductive.Tree `` ``import Data.Graph.Inductive.Query.SP `` ``import Data.Maybe `` ``import Data.List (sortBy) `` `` `` ``solveSchoolProblem :: String -> Int `` ``solveSchoolProblem ds = `` `` `` `` let (a:as) = lines ds `` `` (nnodes:nedges:_) = map readInt \$ words a `` `` `` `` cityMap :: Gr () Int `` `` cityMap = mkGraph (map (,()) [1..nnodes]) `` `` (map (\(a:b:c:_) -> (a,b,c)) \$ map (map readInt.words) \$ take nedges as) `` `` `` `` schools = map readInt \$ words \$ head \$ drop (nedges + 1) as `` `` stadium = readInt \$ head \$ drop (nedges + 2) as `` `` `` `` in head \$ sortBy (\a b -> (spLength stadium a cityMap) `compare` `` `` (spLength stadium b cityMap)) schools `` `` `` `` `` ``readInt :: String -> Int `` ``readInt = read `` `` `` `` `` ``{-- `` `` `` ``Por ejemplo, con el archivo de entrada: `` `` `` ``sampleData = unlines ["9 14" `` `` ,"1 2 2" `` `` ,"1 3 3" `` `` ,"2 3 1" `` `` ,"2 4 5" `` `` ,"2 5 2" `` `` ,"3 5 3" `` `` ,"3 6 3" `` `` ,"4 5 2" `` `` ,"5 6 1" `` `` ,"4 7 1" `` `` ,"4 8 2" `` `` ,"5 8 1" `` `` ,"6 8 3" `` `` ,"6 9 2" `` `` ,"3" `` `` ,"7 8 9" `` `` ,"1" `` `` ] `` `` `` ``Resultaría `` `` `` ``*Main> solveSchoolProblem sampleData `` ``8 `` `` `` `` `` ``--} ``

### Comenta la solución

Tienes que identificarte para poder publicar tu comentario.