Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 12 additions & 15 deletions Training/Easy/horse_racing.rb
Original file line number Diff line number Diff line change
@@ -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