「🎉」 init(2025): day 1
This commit is contained in:
24
2024/day03/part2.rb
Normal file
24
2024/day03/part2.rb
Normal file
@@ -0,0 +1,24 @@
|
||||
if File.exists?("input.txt")
|
||||
file = File.open("input.txt")
|
||||
file_data = file.read
|
||||
file.close
|
||||
else
|
||||
file_data = "xmul(2,4)&mul[3,7]!^don't()_mul(5,5)+mul(32,64](mul(11,8)undo()?mul(8,5))"
|
||||
end
|
||||
|
||||
#puts file_data
|
||||
sane_data = file_data.gsub(/don\'t\(\).*?do\(\)/m, "").scan(/mul\(\d+,\d+\)/)
|
||||
#puts sane_data.inspect
|
||||
|
||||
numbers = sane_data.map do |item|
|
||||
item.scan(/\d+/).map(&:to_i)
|
||||
end
|
||||
#puts numbers.inspect
|
||||
|
||||
result = 0
|
||||
|
||||
for mul in numbers do
|
||||
result = result + mul[0] * mul[1]
|
||||
end
|
||||
|
||||
puts result
|
||||
Reference in New Issue
Block a user