Created
August 11, 2015 19:47
-
-
Save hudo/6425c5ebe7b6fabfe66b to your computer and use it in GitHub Desktop.
This file contains hidden or 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 matches (pattern : string) (x : string) : bool = | |
| let rec matchesL pattern x = | |
| match pattern, x with | |
| | [], [] -> true | |
| | '?'::pTail, xHead::xTail -> matchesL pTail xTail || matchesL pTail x | |
| | '*'::pTail, xHead::xTail -> matchesL pTail xTail || matchesL pTail x || matchesL pattern xTail | |
| | pHead::pTail, xHead::xTail when pHead = xHead -> matchesL pTail xTail | |
| | _ -> false | |
| matchesL (Seq.toList pattern) (Seq.toList x) | |
| let findMatches (pattern : string) (xs : seq<string>) : seq<string> = | |
| Seq.where (matches pattern) xs | |
| [<EntryPoint>] | |
| let main argv = | |
| ["crisis"; "cristian"; "cris"; "acris"; "crielikeababis"; "criesd"] | |
| |> findMatches "*a?" | |
| |> String.concat "," | |
| |> printfn "Result is %s" | |
| System.Console.ReadLine() |> ignore | |
| 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment