
Untitled
By: a guest on
May 2nd, 2012 | syntax:
None | size: 0.69 KB | hits: 12 | expires: Never
type Trip = (String, Integer, Float)
type Tour = [Trip]
shortenTour :: Tour -> String -> String -> Trip -> Tour
shortenTour tour from to trip = _shortenTour tour from to trip False
_shortenTour :: Tour -> String -> String -> Trip -> Bool -> Tour
_shortenTour [] _ _ _ _ = []
_shortenTour ((t,x,y):tour) from to trip inside
|not inside && t==from = [trip] ++ _shortenTour tour from to trip (t==from)
|inside = _shortenTour tour from to trip (t/=to)
|otherwise = [(t,x,y)] ++ _shortenTour tour from to trip True
--shortenTour [("a", 2, 1.1), ("b", 2, 2.3), ("g", 3, 4.4), ("f", 3, 11.0)] "a" "g" ("g", 3, 4.4)