packages feed

egison-5.0.0: sample/salesman2.egi

--
-- This file has been auto-generated by egison-translator.
--

def station : Matcher String := string

def price : Matcher Integer := integer

def graph : Matcher [(String, [(String, Integer)])] := multiset (station, multiset (station, price))

def graphData : [(String, [(String, Integer)])] :=
  [ ( "Berlin"
  , [("St. Louis", 14), ("Oxford", 2), ("Nara", 14), ("Vancouver", 13)] )
  , ( "St. Louis"
  , [("Berlin", 14), ("Oxford", 12), ("Nara", 18), ("Vancouver", 6)] )
  , ( "Oxford"
  , [("Berlin", 2), ("St. Louis", 12), ("Nara", 15), ("Vancouver", 10)] )
  , ( "Nara"
  , [("Berlin", 14), ("St. Louis", 18), ("Oxford", 15), ("Vancouver", 12)] )
  , ( "Vancouver"
  , [("Berlin", 13), ("St. Louis", 6), ("Oxford", 10), ("Nara", 12)] ) ]

def trips : [(Integer, [String])] :=
  matchAll graphData as graph with
    | (#"Berlin", ($s_1, $p_1) :: _) :: (loop $i (2, 4, _)
                                           (( #s_(i - 1)
                                           , ($s_i, $p_i) :: _ ) :: ...)
                                           (( #s_4
                                           , ( #"Berlin" & $s_5
                                           , $p_5 ) :: _ ) :: _)) ->
      (sum (map (\i -> p_i) (between 1 5)), s)

def main (args: [String]) : IO () :=
  do print "Route list:"
     each (compose show print) trips
     write "Lowest price:"
     print (show (min (map (\(x, y) -> x) trips)))