[2023][ruby][19.1]

main
Alpha Chen 1 year ago
parent 48b7acdcea
commit 2364abf76a
Signed by: alpha
SSH Key Fingerprint: SHA256:3fOT8fiYQG/aK9ntivV3Bqtg8AYQ7q4nV6ZgihOA20g

@ -0,0 +1,20 @@
workflows, parts = ARGF.read.split("\n\n")
Part = Data.define(:x, :m, :a, :s)
parts = parts.lines(chomp: true).map { Part.new(**eval(_1.gsub(?=, ?:))) }
workflows = workflows.scan(/(\w+)\{((?~}))\}/).to_h {|name, rules|
rules = rules.split(?,).map {|rule|
rule.include?(?:) ? rule.split(?:) : ["true", rule]
}
[name, rules]
}
pp parts.select {|part|
workflow = "in"
until %w[A R].include?(workflow) do
workflow = workflows.fetch(workflow).find {|cond,_| part.instance_eval(cond) }.last
end
workflow == ?A
}.sum { _1.instance_eval { x + m + a + s }}
Loading…
Cancel
Save