From febc516b17330d666235537273a1327f9ea7fc75 Mon Sep 17 00:00:00 2001 From: mms Date: Tue, 3 Dec 2024 10:06:02 +0100 Subject: feat: 2024@3b --- 2024/03b/run.rb | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100755 2024/03b/run.rb (limited to '2024/03b/run.rb') 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 -- cgit v1.2.3