Skip to content

Instantly share code, notes, and snippets.

@douglasnomizo
Created December 10, 2014 05:56
Show Gist options
  • Select an option

  • Save douglasnomizo/3e5a69fc8c793305451b to your computer and use it in GitHub Desktop.

Select an option

Save douglasnomizo/3e5a69fc8c793305451b to your computer and use it in GitHub Desktop.
# * 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