Guest User

Untitled

a guest
Aug 15th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. {-
  2.  
  3.  
  4. Construcao do Conhecimento
  5.  
  6.  
  7. Times do Campeonato Amazonense:
  8.  
  9. Codigo Nome
  10.  
  11. 00     Nacional
  12. 01     Sao Raimundo
  13. 02     Gremio Coariense
  14. 03     Rio Negro
  15. 04     Fast
  16. 05     Libermorro
  17. 06     America
  18. 07     Sulamerica
  19.  
  20. Entrada:
  21.  
  22. [
  23. [codigo_time_1, codigo_time2, gols_time1, gols_time2, turno_da_partida]
  24. ...
  25. ]
  26.  
  27. Exemplo de entrada:
  28.  
  29. [[1, 2, 0, 2, 1], [1, 3, 3, 1, 1], ...]
  30.  
  31. -}
  32.  
  33. get_team_name cod =
  34.     if (cod == 0) then
  35.         "Nacional"
  36.     else
  37.     if (cod == 1) then
  38.         "Sao Raimundo"
  39.     else
  40.     if (cod == 2) then
  41.         "Gremio Coariense"
  42.     else
  43.     if (cod == 3) then
  44.         "Rio Negro"
  45.     else
  46.     if (cod == 4) then
  47.         "Fast"
  48.     else
  49.     if (cod == 5) then
  50.         "Libermorro"
  51.     else
  52.     if (cod == 6) then
  53.         "America"
  54.     else
  55.     if (cod == 7) then
  56.         "Sulamerica"
  57.     else
  58.         ""
  59.  
  60. evaluate_match match =
  61.     if (team1_goals_scored == team2_goals_scored) then
  62.         [team1_cod, team2_cod, 1, 1, turn]
  63.     else
  64.     if (team1_goals_scored > team2_goals_scored) then
  65.         [team1_cod, team2_cod, 3, -1, turn]
  66.     else
  67.         [team1_cod, team2_cod, -1, 3, turn]
  68.  
  69.     where
  70.         [team1_cod, team2_cod, team1_goals_scored, team2_goals_scored, turn] = match
  71.  
  72. calc_team_score matches team_code turn =
  73.     foldl aux_f 0 matches
  74.  
  75.     where
  76.         aux_f team_total_points match =
  77.             if (turn == match_info !! 4) then
  78.                 if (team_code == match_info !! 0) then
  79.                     team_total_points + (match_info !! 2)
  80.                 else
  81.                 if (team_code == match_info !! 1) then
  82.                     team_total_points + (match_info !! 3)
  83.                 else
  84.                     team_total_points
  85.             else
  86.                 team_total_points
  87.            
  88.             where
  89.                 match_info = evaluate_match match
  90.  
  91. show_scoreboard names scores =
  92.     [(names !! i, scores !! i) | i <- [0, 1..7]]
  93.  
  94. am_soccer_championship_scoreboard matches =
  95.     [
  96.     show_scoreboard teams_names turn1_points,
  97.     show_scoreboard teams_names turn2_points,
  98.     show_scoreboard teams_names total_points
  99.     ]
  100.  
  101.     where
  102.         turn1_points = [(calc_team_score matches team_code 1) | team_code <- [0, 1..7]]
  103.         turn2_points = [(calc_team_score matches team_code 2) | team_code <- [0, 1..7]]
  104.         total_points = [((turn1_points !! i) + (turn2_points !! i)) | i <- [0, 1..7]]
  105.         teams_names = [(get_team_name i) | i <- [0, 1..7]]
Add Comment
Please, Sign In to add comment