[2024][ruby][7.1]

main
Alpha Chen 5 days ago
parent 5f7e2f9713
commit 485fe6be3b
Signed by: alpha
SSH Key Fingerprint: SHA256:3fOT8fiYQG/aK9ntivV3Bqtg8AYQ7q4nV6ZgihOA20g

@ -0,0 +1,25 @@
input = DATA.readlines
.map {|line|
nums = line.scan(/\d+/).map(&:to_i)
[nums.shift, nums]
}
pp input.filter_map {|val, vars|
vals = vars.inject {|n,x|
%i[ + * ].flat_map {|op|
Array(n).map { _1.send(op, x) }
}
}
vals.include?(val) && val
}.sum
__END__
190: 10 19
3267: 81 40 27
83: 17 5
156: 15 6
7290: 6 8 6 15
161011: 16 10 13
192: 17 8 14
21037: 9 7 18 13
292: 11 6 16 20
Loading…
Cancel
Save