Skip to content

Instantly share code, notes, and snippets.

@rshea303
Created May 26, 2015 21:39
Show Gist options
  • Save rshea303/ec8f0dfa7c7383ee2003 to your computer and use it in GitHub Desktop.
Save rshea303/ec8f0dfa7c7383ee2003 to your computer and use it in GitHub Desktop.
Markus and Rich (All tests passing)
class WellFormed
attr_reader :input, :collector
BRACES = { ']' => '[', ')' => '(', '}' => '{' }
def initialize(input)
@input = input
@collector = []
end
def valid?
input.chars.each do |char|
if BRACES.values.include?(char)
@collector << char
elsif BRACES.keys.include?(char)
if @collector.last == BRACES[char]
@collector.pop
else
return false
end
end
end
return true
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment