summaryrefslogtreecommitdiff
path: root/2024/03b/run.rb
diff options
context:
space:
mode:
Diffstat (limited to '2024/03b/run.rb')
-rwxr-xr-x2024/03b/run.rb24
1 files changed, 24 insertions, 0 deletions
diff --git a/2024/03b/run.rb b/2024/03b/run.rb
new file mode 100755
index 0000000..537a384
--- /dev/null
+++ b/2024/03b/run.rb
@@ -0,0 +1,24 @@
+#!/usr/bin/env ruby
+
+data = File.read("data.txt")
+
+valid = data.scan(/(mul\(\d+,\d+\)|don't\(\)|do\(\))/)
+p valid
+sum = 0;
+
+act = true
+ops = valid.map do |operation|
+ if operation[0] == "don't()"
+ act = false
+ 0
+ elsif operation[0] == "do()"
+ act = true
+ 0
+ elsif act
+ operation[0].gsub(/[^\d*,]/, "").to_s.split(",").map(&:to_i).reduce(&:*)
+ else
+ 0
+ end
+end
+
+p ops.sum