egison-5.0.0: sample/five-color.egi
--
-- This file has been auto-generated by egison-translator.
--
def node {a} : Matcher (Integer, Maybe a) := (integer, maybe integer)
def graph {a, b} : Matcher [((Integer, Maybe a), [(Integer, Maybe a)])] := set (node, multiset node)
def colors : [Integer] := between 1 5
def graphData : [((Integer, Maybe Integer), [(Integer, Maybe Integer)])] :=
[((1, Nothing), [(2, Nothing)]), ((2, Nothing), [(1, Nothing)])]
def main (graphData: [((Integer, Maybe Integer), [(Integer, Maybe Integer)])]) : [((Integer, Maybe Integer), [(Integer, Maybe Integer)])] :=
match (colors, graphData) as (set integer, graph) with
| ($c :: _, (($id, nothing), !((_, just #c) :: _)) :: _) ->
main (assignColor id c graphData)
| ( _
, ( ($id, nothing)
, ($nid_1, just $c_1) :: ($nid_2, just $c_2) :: ( $nid_3
, just $c_3 ) :: ($nid_4, just $c_4) :: ( $nid_5
, just $c_5 ) :: [] ) :: _ ) -> undefined
| _ -> graphData
def assignColor (id: Integer) (c: Integer) (graphData: [((Integer, Maybe Integer), [(Integer, Maybe Integer)])]) : [((Integer, Maybe Integer), [(Integer, Maybe Integer)])] :=
map
(\(nodeData, neighbors) ->
(rewriteNode id c nodeData, map (\n -> rewriteNode id c n) neighbors))
graphData
def rewriteNode (id: Integer) (c: Integer) (n: (Integer, Maybe Integer)) : (Integer, Maybe Integer) :=
match n as node with
| (#id, nothing) -> (id, Just c)
| _ -> n
rewriteNode 1 5 (1, Nothing)
assignColor 1 5 graphData
main graphData