Skip to content

Commit 383bb52

Browse files
committed
Refactoring on init strengths method
1 parent 652acaa commit 383bb52

1 file changed

Lines changed: 6 additions & 11 deletions

File tree

horse_racing.rb

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,18 @@
11
# Solution for https://www.codingame.com/ide/puzzle/horse-racing-duals
22
class HorseRacing
3-
attr_accessor :horses_number
3+
attr_accessor :horses_count
44

55
def initialize
6-
@horses_number = gets.to_i
6+
@horses_count = gets.to_i
77
end
88

99
def find_difference
10-
strenghts = init_strenghts
11-
strenghts.each_cons(2).map { |a, b| (b - a).abs }.min
10+
strengths = init_strengths
11+
strengths.each_cons(2).map { |a, b| (b - a).abs }.min
1212
end
1313

14-
def init_strenghts
15-
strenghts_array = []
16-
horses_number.times do
17-
horse_strenght = gets.to_i
18-
strenghts_array << horse_strenght
19-
end
20-
strenghts_array.sort
14+
def init_strengths
15+
horses_count.times.each_with_object([]) { |_, result| result << gets.to_i }.sort
2116
end
2217

2318
def start

0 commit comments

Comments
 (0)