Created
May 16, 2015 21:22
-
-
Save theimowski/3420badfa65f778a993a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let (|Contains|_|) xs input = | |
let rec contains xs' input' acc = | |
match xs', input' with | |
| [], after -> | |
let length = List.length acc - List.length xs | |
let before = acc |> List.rev |> Seq.take length |> List.ofSeq | |
Some (before, after) | |
| _, [] -> None | |
| h1 :: t1, h2 :: t2 when h1 = h2 -> | |
contains t1 t2 (h2 :: acc) | |
| h1 :: t1, h2 :: t2 -> | |
contains xs t2 (h2 :: acc) | |
contains xs input [] | |
match [0;0;7;6;7;1;3;7;6;7;0;0] with | |
| Contains [7;6;7] (before,after) -> printfn "before: %A; after: %A" before after | |
| _ -> printfn "does not contain" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment