aoc2023/day_1/impl.rb

20 lines
369 B
Ruby
Raw Permalink Normal View History

2023-12-01 10:00:04 +01:00
#prepare the input which is a string containing new lines
def parse(input)
data = []
input.each_line do |line|
data << line.gsub(/[a-zA-Z]/,"").chomp
end
data
end
# result should a single string or integer
def calculate(data)
result = 0
data.each do |d|
d = d.chars.to_a
num = "#{d.first}"+"#{d.last}"
result += num.to_i
end
result
end