[2020][ruby][9.x] refactor

pull/2/head
Alpha Chen 4 years ago
parent 95b912211d
commit 7f46f39d8d

@ -2,19 +2,17 @@ N = 25
data = ARGF.read.scan(/\d+/).map(&:to_i) data = ARGF.read.scan(/\d+/).map(&:to_i)
i = (N..).find {|i| invalid = data.each_cons(N+1).filter_map {|range|
!data[i-N,N].combination(2).map(&:sum).include?(data[i]) n = range.pop
} range.combination(2).map(&:sum).include?(n) ? nil : n
invalid = data[i] }.first
(0..).each do |start| weakness = (0..).lazy.flat_map {|start|
(2..data.size-start-1).each do |len| (2..data.size-start-1).map {|len|
sum = data[start, len].sum data[start, len]
if sum == invalid }
p data[start, len].minmax.sum }.filter_map {|range|
exit range.sum == invalid && range.minmax.sum
elsif sum > invalid }.first
next
end p weakness
end
end

Loading…
Cancel
Save