diff options
author | mms <git@sapka.me> | 2024-12-03 10:06:02 +0100 |
---|---|---|
committer | mms <git@sapka.me> | 2024-12-03 10:06:02 +0100 |
commit | febc516b17330d666235537273a1327f9ea7fc75 (patch) | |
tree | c2601cd427f7939fc59a662d9739afd7ce6dcb02 /2024/03b/run.rb | |
parent | 1ea90d8757b788e8711b961b818f41671049d7ae (diff) |
feat: 2024@3b
Diffstat (limited to '2024/03b/run.rb')
-rwxr-xr-x | 2024/03b/run.rb | 24 |
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 |