From 1ea90d8757b788e8711b961b818f41671049d7ae Mon Sep 17 00:00:00 2001 From: mms Date: Tue, 3 Dec 2024 08:52:26 +0100 Subject: feat: 2024@3a --- 2024/03a/run.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100755 2024/03a/run.rb (limited to '2024/03a/run.rb') 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 -- cgit v1.2.3