commit
This commit is contained in:
parent
3e6abd1ea1
commit
bb4cf6a9c6
6 changed files with 14585 additions and 0 deletions
46
lib/foobar.ml
Normal file
46
lib/foobar.ml
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
type match' =
|
||||
string (* home team *) * int (* goal difference *) * string (* away team *)
|
||||
|
||||
let matches =
|
||||
[
|
||||
("foo", 1, "car");
|
||||
("foo", 0, "bar");
|
||||
("foo", 1, "far");
|
||||
("car", 1, "bar");
|
||||
("foo", ~-1, "bar");
|
||||
("tar", 1, "fir");
|
||||
("bar", 1, "qux");
|
||||
("jor", ~-1, "far");
|
||||
("xir", 1, "kar");
|
||||
("car", ~-1, "qux");
|
||||
("far", 1, "qux");
|
||||
("car", 1, "foo");
|
||||
]
|
||||
|
||||
let way a b =
|
||||
let rec aux (at : string) (visited : string list) (accum : match' list) =
|
||||
if at = b then [ List.rev accum ]
|
||||
else
|
||||
let matches =
|
||||
matches |> List.filter (function _, score, _ -> score <> 0)
|
||||
in
|
||||
let h =
|
||||
matches
|
||||
|> List.filter (function home, score, away ->
|
||||
score > 0 && home = at && not (List.exists (( = ) away) visited))
|
||||
|> List.map (function (_, _, away) as x ->
|
||||
aux away (at :: visited) (x :: accum))
|
||||
|> List.concat
|
||||
in
|
||||
let a =
|
||||
matches
|
||||
|> List.filter (function home, score, away ->
|
||||
score < 0 && away = at && not (List.exists (( = ) home) visited))
|
||||
|> List.map (function (home, _, _) as x ->
|
||||
aux home (at :: visited) (x :: accum))
|
||||
|> List.concat
|
||||
in
|
||||
a @ h
|
||||
in
|
||||
aux a [] []
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue