1 people like it.

Champions League Round of 16 Draw

  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: 
 60: 
 61: 
 62: 
 63: 
 64: 
 65: 
 66: 
 67: 
 68: 
 69: 
 70: 
 71: 
 72: 
 73: 
 74: 
 75: 
 76: 
 77: 
 78: 
 79: 
 80: 
 81: 
 82: 
 83: 
 84: 
 85: 
 86: 
 87: 
 88: 
 89: 
 90: 
 91: 
 92: 
 93: 
 94: 
 95: 
 96: 
 97: 
 98: 
 99: 
100: 
101: 
102: 
103: 
104: 
105: 
106: 
107: 
108: 
109: 
110: 
111: 
//Declare some types
type Country = 
    |Germany    |Italy      |England    |Spain
    |France     |Portugal   |Turkey     |Scotland
    |Ukraine

type Group = |A|B|C|D|E|F|G|H

type Place = |First |Second

type Team = {
    name : string;
    country : Country;
    group : Group;
    place: Place;
}

//Declare all teams
let PSG = {name ="Paris Saint-Germain"; country=France; group=A;place=First}
let Porto = {name ="FC Porto"; country=Portugal; group=A; place=Second}

let Schalke = {name ="FC Schalke 04"; country=Germany; group=B;place=First}
let Arsenal = {name ="Arcenal FC"; country=England; group=B; place=Second}

let Malaga = {name ="Malaga CF"; country=Spain; group=C;place=First}
let Milan = {name ="AC Miland"; country=Italy; group=C; place=Second}

let Dortmund = {name ="Borussia Dortmund"; country=Germany; group=D;place=First}
let Real = {name ="Real Madrid CF"; country=Spain; group=D; place=Second}

let Juventus  = {name ="Juventus"; country=Italy; group=E;place=First}
let Shakhtar = {name ="FC Shakhtar Donetsk"; country=Ukraine; group=E; place=Second}

let Bayern  = {name ="FC Bayern München"; country=Germany; group=F;place=First}
let Valencia = {name ="Valemcia CF"; country=Spain; group=F; place=Second}

let Barcelona  = {name ="FC Barcelona"; country=Spain; group=G;place=First}
let Celtic = {name ="Celtic FC"; country=Scotland; group=G; place=Second}

let ManchesterU  = {name ="Manchester United FC"; country=England; group=H;place=First}
let Galatasaray = {name ="Galatasaray AŞ"; country=Turkey; group=H; place=Second}

//And put them in a list
let allTeams = [PSG; Porto; Schalke; Arsenal; Malaga; Milan; Dortmund; Real; Juventus;
    Shakhtar; Bayern; Valencia; Barcelona;Celtic;ManchesterU; Galatasaray;]
//Partition the list in group winners and runner ups
let groupWinners, runnerUps = 
    let isGroupWinner team  = (team.place = First)
    List.partition isGroupWinner allTeams;
//I stole this function from stack overflow to generate all permutaions of a list
let rec perms = 
    let distrib e L =
        let rec aux pre post = 
            seq {
                match post with
                | [] -> yield (L @ [e])
                | h::t -> yield (List.rev pre @ [e] @ post)
                          yield! aux (h::pre) t 
            }
        aux [] L
    function 
    | [] -> Seq.singleton []
    | h::t -> Seq.collect (distrib h) (perms t)

//Create all draws by using all permutations of the runner ups and pairing
//them with an unchanged list of gruop winners
let getDraws runnerUps  groupWinners = 
    [for perm in (perms runnerUps) do
        yield List.zip perm groupWinners
    ]

let draws = getDraws runnerUps  groupWinners

//fnction to check if a match is valid
let isValidMatch (footballMatch: Team*Team) = 
    match footballMatch with
    |(teamA,teamB) when teamA.group = teamB.group -> false
    |(teamA,teamB) when teamA.country = teamB.country  ->false
    |_ -> true
//checks if all matches in a draw are valid
let isValidDraw (draw: (Team*Team) list)  = 
    draw
    |>List.map isValidMatch 
    |>List.fold (&&) true
//filter the draws so we only keep the valid ones
let validDraws = List.filter isValidDraw draws
//Calculates the probability of a match by looking how many of the draws
//contain the match and dividing by the total amount of matches
let matchProbability (footballMatch:Team*Team) =  
    let occurences = 
        validDraws 
        |> List.filter (List.exists (fun (x:Team*Team) -> x= footballMatch)) 
        |> List.length

    (float occurences)*100.0/(float <| List.length validDraws)
//Gets a list of tupples where each tuple consist of the match and it respective probability           
let getProbabilities runnerUps groupWinners = 
    [for runnerUp in runnerUps do
        for adversary in groupWinners do
        let footbalMatch = (runnerUp,adversary)
        yield (footbalMatch, matchProbability footbalMatch)
    ]

let probabilities = getProbabilities runnerUps groupWinners

//a function to print a probability
let printProbability probabilities = 
    match probabilities with
    |((teamA,teamB),probability) -> printfn "%s  \t  %s   \t  %F%% " teamA.name teamB.name probability
//print all probabilities
List.iter printProbability probabilities
union case Country.Germany: Country
union case Country.Italy: Country
union case Country.England: Country
union case Country.Spain: Country
union case Country.France: Country
union case Country.Portugal: Country
union case Country.Turkey: Country
union case Country.Scotland: Country
union case Country.Ukraine: Country
type Group =
  | A
  | B
  | C
  | D
  | E
  | F
  | G
  | H

Full name: Script.Group
union case Group.A: Group
union case Group.B: Group
union case Group.C: Group
union case Group.D: Group
union case Group.E: Group
union case Group.F: Group
union case Group.G: Group
union case Group.H: Group
type Place =
  | First
  | Second

Full name: Script.Place
union case Place.First: Place
union case Place.Second: Place
type Team =
  {name: string;
   country: Country;
   group: Group;
   place: Place;}

Full name: Script.Team
Team.name: string
Multiple items
val string : value:'T -> string

Full name: Microsoft.FSharp.Core.Operators.string

--------------------
type string = System.String

Full name: Microsoft.FSharp.Core.string
Team.country: Country
type Country =
  | Germany
  | Italy
  | England
  | Spain
  | France
  | Portugal
  | Turkey
  | Scotland
  | Ukraine

Full name: Script.Country
Team.group: Group
Team.place: Place
val PSG : Team

Full name: Script.PSG
val Porto : Team

Full name: Script.Porto
val Schalke : Team

Full name: Script.Schalke
val Arsenal : Team

Full name: Script.Arsenal
val Malaga : Team

Full name: Script.Malaga
val Milan : Team

Full name: Script.Milan
val Dortmund : Team

Full name: Script.Dortmund
val Real : Team

Full name: Script.Real
val Juventus : Team

Full name: Script.Juventus
val Shakhtar : Team

Full name: Script.Shakhtar
val Bayern : Team

Full name: Script.Bayern
val Valencia : Team

Full name: Script.Valencia
val Barcelona : Team

Full name: Script.Barcelona
val Celtic : Team

Full name: Script.Celtic
val ManchesterU : Team

Full name: Script.ManchesterU
val Galatasaray : Team

Full name: Script.Galatasaray
val allTeams : Team list

Full name: Script.allTeams
val groupWinners : Team list

Full name: Script.groupWinners
val runnerUps : Team list

Full name: Script.runnerUps
val isGroupWinner : (Team -> bool)
val team : Team
Multiple items
module List

from Microsoft.FSharp.Collections

--------------------
type List<'T> =
  | ( [] )
  | ( :: ) of Head: 'T * Tail: 'T list
  interface IEnumerable
  interface IEnumerable<'T>
  member Head : 'T
  member IsEmpty : bool
  member Item : index:int -> 'T with get
  member Length : int
  member Tail : 'T list
  static member Cons : head:'T * tail:'T list -> 'T list
  static member Empty : 'T list

Full name: Microsoft.FSharp.Collections.List<_>
val partition : predicate:('T -> bool) -> list:'T list -> 'T list * 'T list

Full name: Microsoft.FSharp.Collections.List.partition
val perms : ('a list -> seq<'a list>)

Full name: Script.perms
val distrib : ('b -> 'b list -> seq<'b list>)
val e : 'b
val L : 'b list
val aux : ('b list -> 'b list -> seq<'b list>)
val pre : 'b list
val post : 'b list
Multiple items
val seq : sequence:seq<'T> -> seq<'T>

Full name: Microsoft.FSharp.Core.Operators.seq

--------------------
type seq<'T> = System.Collections.Generic.IEnumerable<'T>

Full name: Microsoft.FSharp.Collections.seq<_>
val h : 'b
val t : 'b list
val rev : list:'T list -> 'T list

Full name: Microsoft.FSharp.Collections.List.rev
module Seq

from Microsoft.FSharp.Collections
val singleton : value:'T -> seq<'T>

Full name: Microsoft.FSharp.Collections.Seq.singleton
val h : 'a
val t : 'a list
val collect : mapping:('T -> #seq<'U>) -> source:seq<'T> -> seq<'U>

Full name: Microsoft.FSharp.Collections.Seq.collect
val getDraws : runnerUps:'a list -> groupWinners:'b list -> ('a * 'b) list list

Full name: Script.getDraws
val runnerUps : 'a list
val groupWinners : 'b list
val perm : 'a list
val zip : list1:'T1 list -> list2:'T2 list -> ('T1 * 'T2) list

Full name: Microsoft.FSharp.Collections.List.zip
val draws : (Team * Team) list list

Full name: Script.draws
val isValidMatch : Team * Team -> bool

Full name: Script.isValidMatch
val footballMatch : Team * Team
val teamA : Team
val teamB : Team
val isValidDraw : draw:(Team * Team) list -> bool

Full name: Script.isValidDraw
val draw : (Team * Team) list
type 'T list = List<'T>

Full name: Microsoft.FSharp.Collections.list<_>
val map : mapping:('T -> 'U) -> list:'T list -> 'U list

Full name: Microsoft.FSharp.Collections.List.map
val fold : folder:('State -> 'T -> 'State) -> state:'State -> list:'T list -> 'State

Full name: Microsoft.FSharp.Collections.List.fold
val validDraws : (Team * Team) list list

Full name: Script.validDraws
val filter : predicate:('T -> bool) -> list:'T list -> 'T list

Full name: Microsoft.FSharp.Collections.List.filter
val matchProbability : Team * Team -> float

Full name: Script.matchProbability
val occurences : int
val exists : predicate:('T -> bool) -> list:'T list -> bool

Full name: Microsoft.FSharp.Collections.List.exists
val x : Team * Team
val length : list:'T list -> int

Full name: Microsoft.FSharp.Collections.List.length
Multiple items
val float : value:'T -> float (requires member op_Explicit)

Full name: Microsoft.FSharp.Core.Operators.float

--------------------
type float = System.Double

Full name: Microsoft.FSharp.Core.float

--------------------
type float<'Measure> = float

Full name: Microsoft.FSharp.Core.float<_>
val getProbabilities : runnerUps:seq<Team> -> groupWinners:seq<Team> -> ((Team * Team) * float) list

Full name: Script.getProbabilities
val runnerUps : seq<Team>
val groupWinners : seq<Team>
val runnerUp : Team
val adversary : Team
val footbalMatch : Team * Team
val probabilities : ((Team * Team) * float) list

Full name: Script.probabilities
val printProbability : (Team * Team) * float -> unit

Full name: Script.printProbability
val probabilities : (Team * Team) * float
val probability : float
val printfn : format:Printf.TextWriterFormat<'T> -> 'T

Full name: Microsoft.FSharp.Core.ExtraTopLevelOperators.printfn
val iter : action:('T -> unit) -> list:'T list -> unit

Full name: Microsoft.FSharp.Collections.List.iter
Raw view New version

More information

Link:http://fssnip.net/g2
Posted:3 years ago
Author:
Tags: