Last active
December 20, 2015 15:38
-
-
Save scottoasis/6155644 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
object PlayWithString { | |
def isMatching(pat: String)(str: String): Boolean = | |
/* | |
-- termination -- | |
*/ | |
if (pat == "*" || (pat.isEmpty && str.isEmpty)) true | |
else if ((pat.isEmpty && !str.isEmpty) || (str.isEmpty)) false | |
/* | |
-- induction -- | |
*/ | |
else if (pat startsWith "*") | |
if (isMatching(pat.tail)(str)) true | |
else isMatching(pat)(str.tail) | |
else if (pat startsWith "?") isMatching(pat.tail)(str.tail) | |
else (str startsWith pat.head.toString) && isMatching(pat.tail)(str.tail) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment