aboutsummaryrefslogtreecommitdiff
path: root/day02/part2
blob: 5d05da2c79178b68e9e6ac1fc5377b99c483e5a7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#!/usr/bin/env ruby

def findpair(nums)
  (0...nums.length).each do |i|
    (0...nums.length).each do |j|
      next if j == i
      pair = [nums[i], nums[j]]
      return pair if pair.max % pair.min == 0
    end
  end
end

cs = 0

input = $stdin.readlines.map(&:chomp)

input.each do |line|
  nums = line.split.map(&:to_i)
  pair = findpair(nums)
  cs += pair.max / pair.min
end

puts cs