diff options
Diffstat (limited to '2024/03a/run.rb')
-rwxr-xr-x | 2024/03a/run.rb | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/2024/03a/run.rb b/2024/03a/run.rb new file mode 100755 index 0000000..1effb9b --- /dev/null +++ b/2024/03a/run.rb @@ -0,0 +1,12 @@ +#!/usr/bin/env ruby + +data = File.read("data.txt") + +valid = data.scan(/mul\(\d*,\d*\)/) +sum = 0; + +ops = valid.map do |operation| + operation.gsub(/[^\d*,]/, "").to_s.split(",").map(&:to_i).reduce(&:*) +end + +p ops.sum |