You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
421 B
28 lines
421 B
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|
|
|
Array(n).flat_map {[
|
|
_1 + x,
|
|
_1 * x,
|
|
"#{_1}#{x}".to_i,
|
|
]}
|
|
}
|
|
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
|