mirror of
https://github.com/onyx-and-iris/aoc2025.git
synced 2025-12-08 11:47:47 +00:00
29 lines
512 B
Ruby
Executable File
29 lines
512 B
Ruby
Executable File
#!/usr/bin/env ruby
|
|
# frozen_string_literal: true
|
|
|
|
class Main
|
|
def run
|
|
ranges = []
|
|
ingredient_ids = Hash.new(0)
|
|
$stdin.each_line do |line|
|
|
arr = line.chomp.split("-").map(&:to_i)
|
|
if arr.size == 2
|
|
ranges << (arr[0]..arr[1])
|
|
elsif arr.size == 1
|
|
ingredient_ids[arr[0]] += 1
|
|
end
|
|
end
|
|
|
|
@sum = 0
|
|
ingredient_ids.each do |id, count|
|
|
if ranges.any? { |r| r.include?(id) }
|
|
@sum += count
|
|
end
|
|
end
|
|
|
|
puts @sum
|
|
end
|
|
end
|
|
|
|
Main.new.run
|