As a father of a growing pre-teen boy, I am supposed to take at least some interest in sports. Particularly when the whole world is afire about FIFA world cup.
So, yesterday, I sat beside my son watching the match between Japan and Senegal, picking Senegal as the team I supported (as my son supported Japan). Thank God! The match ended in a draw!
It was a nice experience. I did find the match interesting. But, it would have been too much to expect me to concentrate on the game all the while. While the match on, I fiddled with my laptop, and did a little program to calculate the importance of the remaining matches in the opening round.
I have pasted the output (with some edits to include the dates and times) at the end of the source code within comments.
The program has some simple illustration of how the library higher order functions List.map and List.sort can be used. There's also a higher order function rate_match implemented.
Hope you find it helpful in deciding which matches in the opening round you would like to watch, and in the process get a bit familiar with functional programming with OCaml.
Hope you find it helpful in deciding which matches in the opening round you would like to watch, and in the process get a bit familiar with functional programming with OCaml.
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 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 | let teams = [ "Germany"; "Brazil"; "Belgium"; "Portugal"; "Argentina"; "Switzerland"; "France"; "Poland"; "Chile"; "Spain"; "Peru"; "Denmark"; "England"; "Uruguay"; "Mexico"; "Colombia"; "Netherlands"; "Wales"; "Italy"; "Croatia"; "Tunisia"; "Iceland"; "Costa Rica"; "Sweden"; "United States"; "Austria"; "Senegal"; "Slovakia"; "Northern Ireland"; "Romania"; "Republic of Ireland"; "Paraguay"; "Venezuela"; "Serbia"; "Ukraine"; "Australia"; "Iran"; "Turkey"; "Congo DR"; "Bosnia-Herzegovina"; "Morocco"; "Scotland"; "Montenegro"; "Greece"; "Egypt"; "Czech Republic"; "Ghana"; "Nigeria"; "Bulgaria"; "Cameroon"; "Hungary"; "Burkina Faso"; "Norway"; "Jamaica"; "Panama"; "Slovenia"; "Korea Republic"; "Albania"; "Bolivia"; "Ecuador"; "Japan"; "Honduras"; "Finland"; "Mali"; "Cape Verde Islands"; "Algeria"; "Saudi Arabia"; "Côte d'Ivoire"; "Guinea"; "Russia"; "FYR Macedonia"; "El Salvador"; "Syria"; "South Africa"; "China PR"; "Zambia"; "UAE"; "Belarus"; "Lebanon"; "Canada"; "Curaçao"; "Uganda"; "Congo"; "Oman"; "Gabon"; "Luxembourg"; "Cyprus"; "Benin"; "Iraq"; "Faroe Islands"; "Trinidad and Tobago"; "Kyrgyzstan"; "Israel"; "Estonia"; "Uzbekistan"; "Georgia"; "India"; "Qatar"; "Palestine"; "Armenia"; "Libya"; "Vietnam"; "Niger"; "Haiti"; "Azerbaijan"; "Madagascar"; "Mauritania"; "Korea DPR"; "Central African Republic"; "Jordan"; "Sierra Leone"; "Kenya"; "Bahrain"; "Mozambique"; "Philippines"; "Namibia"; "Kazakhstan"; "Zimbabwe"; "Tajikistan"; "New Zealand"; "Guinea-Bissau"; "Thailand"; "Malawi"; "Chinese Taipei"; "Togo"; "Lithuania"; "Antigua and Barbuda"; "Sudan"; "Latvia"; "Turkmenistan"; "Andorra"; "Nicaragua"; "Yemen"; "Swaziland"; "St. Kitts and Nevis"; "Rwanda"; "Angola"; "Myanmar"; "Botswana"; "Tanzania"; "Kosovo"; "Hong Kong"; "Equatorial Guinea"; "Solomon Islands"; "Afghanistan"; "Guatemala"; "Lesotho"; "Burundi"; "Comoros"; "Maldives"; "Ethiopia"; "Dominican Republic"; "Suriname"; "New Caledonia"; "Mauritius"; "South Sudan"; "Tahiti"; "Liberia"; "Kuwait"; "Barbados"; "Nepal"; "Vanuatu"; "Belize"; "Indonesia"; "Fiji"; "Cambodia"; "Papua New Guinea"; "Grenada"; "Singapore"; "St. Lucia"; "Malaysia"; "Gambia"; "St. Vincent / Grenadines"; "Puerto Rico"; "Chad"; "Moldova"; "Dominica"; "Bermuda"; "Laos"; "Liechtenstein"; "Cuba"; "Guyana"; "Bhutan"; "Malta"; "Macao"; "Mongolia"; "São Tomé e Príncipe"; "Seychelles"; "Aruba"; "Guam"; "Timor-Leste"; "American Samoa"; "Cook Islands"; "Bangladesh"; "Gibraltar"; "Brunei"; "Djibouti"; "Samoa"; "US Virgin Islands"; "Sri Lanka"; "Pakistan"; "Cayman Islands"; "San Marino"; "British Virgin Islands"; "Montserrat"; "Turks and Caicos Islands"; "Anguilla"; "Bahamas"; "Eritrea"; "Somalia"; "Tonga"; ] let matches = [ ("Japan", "Senegal"); ("Poland", "Colombia"); ("Uruguay", "Russia"); ("Saudi Arabia", "Egypt"); ("Spain", "Morocco"); ("Iran", "Portugal"); ("Australia", "Peru"); ("Denmark", "France"); ("Nigeria", "Argentina"); ("Iceland", "Croatia"); ("Korea Republic", "Germany"); ("Mexico", "Sweden"); ("Serbia", "Brazil"); ("Switzerland", "Costa Rica"); ("Japan", "Poland"); ("Senegal", "Colombia"); ("Panama", "Tunisia"); ("England", "Belgium"); ] exception My_Not_found of string let find x l = let rec iter i = function [] -> raise (My_Not_found x) | h :: t -> if h = x then i else iter (i + 1) t in iter 1 l let rate_match (t1, t2) imp = imp (find t1 teams) (find t2 teams) let rate_matches ms = let rates = List.map (fun m -> (m, rate_match m (fun x y -> x * y))) ms in List.sort (fun (_, r1) (_, r2) -> if r1 < r2 then -1 else if r1 = r2 then 0 else 1) rates (* By using 'addition' as the joining function [ (("England", "Belgium"), 14); June 28 11.30 PM (("Denmark", "France"), 17); June 26 7.30 PM (("Poland", "Colombia"), 22); June 24 11.30 PM (("Switzerland", "Costa Rica"), 27); June 27 11.30 PM (("Serbia", "Brazil"), 34); June 27 11.30 PM (("Mexico", "Sweden"), 37); June 27 7.30 PM (("Iran", "Portugal"), 39); June 25 7.30 PM (("Iceland", "Croatia"), 40); June 26 11.30 PM (("Senegal", "Colombia"), 41); June 28 7.30 PM (("Australia", "Peru"), 45); June 26 7.30 PM (("Spain", "Morocco"), 49); June 25 11.30 PM (("Nigeria", "Argentina"), 51); June 26 11.30 PM (("Korea Republic", "Germany"), 56); June 27 7.30 PM (("Japan", "Poland"), 67); June 28 7.30 PM (("Panama", "Tunisia"), 74); June 28 11.30 PM (("Uruguay", "Russia"), 82); June 25 7.30 PM (("Japan", "Senegal"), 86); June 24 8.30 PM (("Saudi Arabia", "Egypt"), 110) June 25 7.30 PM ] By using 'multiplication' as the joining function [ (("England", "Belgium"), 39); (("Korea Republic", "Germany"), 57); (("Serbia", "Brazil"), 68); (("Denmark", "France"), 84); (("Poland", "Colombia"), 128); (("Switzerland", "Costa Rica"), 138); (("Iran", "Portugal"), 148); (("Nigeria", "Argentina"), 240); (("Mexico", "Sweden"), 360); (("Australia", "Peru"), 396); (("Spain", "Morocco"), 410); (("Senegal", "Colombia"), 432); (("Iceland", "Croatia"), 440); (("Japan", "Poland"), 488); (("Uruguay", "Russia"), 980); (("Panama", "Tunisia"), 1155); (("Japan", "Senegal"), 1647); (("Saudi Arabia", "Egypt"), 3015) ] *) |
No comments:
Post a Comment