Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement