bench-rejected-impls/01_report_repair.rb
# And this helps a little more, but find_over_input_range is still better,
# so sorting is really the way to go here.
And this helps a little more, but find_over_input_range is still better,
so sorting is really the way to go here.
And this helps a little more but find_over_input_range is still better so sorting is really the way to go here .
def find_by_combination_no_combination(input, input_tally)
  input.each_with_index.with_object([[], []]) { |(x, i), (p1, p2)|
    needed = 2020 - x
    if needed >= x
      required_count = x == needed ? 2 : 1
      p1 << x * needed if input_tally[needed] &.>= required_count
    end
    ((i + 1)...input.size).each { |j|
      y = input[j]
      needed = 2020 - x - y
      next if needed < x || needed < y
      required_count = (x == needed ? 1 : 0) + (y == needed ? 1 : 0) + 1
      p2 << x * y * needed if input_tally[needed] &.>= required_count
    }
  }
end
def find_by_combination_no_combination ( input , input_tally ) input . each_with_index . with_object ( [ [ ] , [ ] ] ) { | ( x , i ) , ( p1 , p2 ) | needed = 2020 - x if needed >= x required_count = x == needed ? 2 : 1 p1 << x * needed if input_tally [ needed ] &. >= required_count end ( ( i + 1 ) ... input . size ) . each { | j | y = input [ j ] needed = 2020 - x - y next if needed < x || needed < y required_count = ( x == needed ? 1 : 0 ) + ( y == needed ? 1 : 0 ) + 1 p2 << x * y * needed if input_tally [ needed ] &. >= required_count } } end
And this helps a little more, but find_over_input_range is still better,
so sorting is really the way to go here.
And this helps a little more but find_over_input_range is still better so sorting is really the way to go here .
input
<not_specific>
input_tally
<not_specific>