Skip to content

Instantly share code, notes, and snippets.

@oieioi
Created July 10, 2015 08:46
Show Gist options
  • Save oieioi/8e8ee0164381821d041e to your computer and use it in GitHub Desktop.
Save oieioi/8e8ee0164381821d041e to your computer and use it in GitHub Desktop.
inputs = []
while str = STDIN.gets.chomp
break if str.empty?
inputs.push str.split(',').collect {|i|i.to_i}
end
class Amida
def initialize (yokobous)
@yokobous = yokobous.clone
@amida_length = @yokobous[0].length + 1
@lines = []
end
def resolve
(1..@amida_length).each do |count|
line = Line.new count
@yokobous.each {|yokobou| line.next yokobou}
@lines.push line
end
@lines.collect{|line| line.x}.join(',')
end
end
class Line
attr_accessor :x
def initialize(x)
@x = x
@level = 0
end
def next(yokobou)
@level += 1
if yokobou.empty? then
return @x
end
left_index = @x - 2
right_index = @x - 1
if left_index >= 0 and yokobou[left_index] == 1 then
@x -= 1
elsif yokobou[right_index] == 1 then
@x += 1
end
end
end
amida = Amida.new inputs
puts amida.resolve()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment