Advertisement
Guest User

Untitled

a guest
Jul 29th, 2015
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. inputs = []
  2. while str = STDIN.gets.chomp
  3. break if str.empty?
  4. inputs.push str.split(',').collect {|i|i.to_i}
  5. end
  6.  
  7. class Amida
  8. def initialize (yokobous)
  9. @yokobous = yokobous.clone
  10. @amida_length = @yokobous[0].length + 1
  11. @lines = []
  12. end
  13.  
  14. def resolve
  15. (1..@amida_length).each do |count|
  16. line = Line.new count
  17. @yokobous.each {|yokobou| line.next yokobou}
  18. @lines.push line
  19. end
  20. @lines.collect{|line| line.x}.join(',')
  21. end
  22.  
  23. end
  24.  
  25. class Line
  26. attr_accessor :x
  27.  
  28. def initialize(x)
  29. @x = x
  30. @level = 0
  31. end
  32.  
  33. def next(yokobou)
  34. @level += 1
  35.  
  36. if yokobou.empty? then
  37. return @x
  38. end
  39.  
  40. left_index = @x - 2
  41. right_index = @x - 1
  42. if left_index >= 0 and yokobou[left_index] == 1 then
  43. @x -= 1
  44. elsif yokobou[right_index] == 1 then
  45. @x += 1
  46. end
  47. end
  48.  
  49. end
  50.  
  51. amida = Amida.new inputs
  52. puts amida.resolve()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement