Created
December 10, 2014 05:56
-
-
Save douglasnomizo/3e5a69fc8c793305451b 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
| # * question 2. nt (num tuple) | |
| # Here is the definition of the number tuple. Please write a function to decide whether a string is a valid num tuple representation. | |
| # item -> () or [0-9]+ or nt | |
| # nt -> (item,item,item+) | |
| # f(“()”) -> true | |
| # f(“(1,2,988)”) -> true | |
| # f(“(1,23,(4,5),076)”) -> true | |
| class TupleValidation | |
| def self.is_tuple?(string) | |
| return !!(string =~ /\([0-9\,]*|[\(\)]?[0-9\,]*\)/) && | |
| string.count("(") == string.count(")") | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment