diff --git a/Training/Easy/horse_racing.rb b/Training/Easy/horse_racing.rb index 6580aa8..cdf59a9 100644 --- a/Training/Easy/horse_racing.rb +++ b/Training/Easy/horse_racing.rb @@ -1,24 +1,21 @@ # Solution for https://www.codingame.com/ide/puzzle/horse-racing-duals class HorseRacing - def find_difference - strenghts = init_strenghts - strenghts.each_cons(2).map { |a, b| (b - a).abs }.min + attr_reader :horses_count, :strengths + + def initialize(horses_count) + @horses_count = horses_count + @strengths = init_strengths end - def init_strenghts - n = gets.to_i - strenghts_array = [] - n.times do - pi = gets.to_i - strenghts_array << pi - end - strenghts_array.sort + def init_strengths + Array.new(horses_count) { gets.to_i }.sort end - def start - puts find_difference + def find_difference + strengths.each_cons(2).map { |a, b| (b - a).abs }.min end end -obj = HorseRacing.new -obj.start +horses_count = gets.to_i +obj = HorseRacing.new(horses_count) +puts obj.find_difference