Skip to content

Instantly share code, notes, and snippets.

@Shinpeim
Created February 16, 2014 17:49
Show Gist options
  • Save Shinpeim/9037973 to your computer and use it in GitHub Desktop.
Save Shinpeim/9037973 to your computer and use it in GitHub Desktop.
class Solver
def initialize(open_char, close_char)
@open_char = open_char
@close_char = close_char
@count = 0
end
def run(string)
chars = string.split("")
chars.each do |char|
case char
when @open_char
open
when @close_char
close
else
raise "invalid charactor detected"
end
end
if @count == 0
p "対応がとれている"
else
p "対応がとれていない"
end
end
def open
@count += 1
end
def close
@count -= 1
if @count < 0
raise "invalid format"
end
end
end
Solver.new("「", "」").run("「」「「「」「」」「」「「「」」「」「「「」」「」」「「」「「」」「「」「「」」」「「」「「」「「「」」「」」」」」」」")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment