bench-rejected-impls/01_report_repair.rb
# Just some quick checks to make sure it's not because filter_map or combinations are slow.
# This does help a little, but not enough to catch up to find_over_input_range.
Just some quick checks to make sure it's not because filter_map or combinations are slow.
This does help a little, but not enough to catch up to find_over_input_range.
Just some quick checks to make sure it ' s not because filter_map or combinations are slow . This does help a little but not enough to catch up to find_over_input_range .
def find_by_combination_no_filter_map(input, input_tally)
  ans = [p1 = [], p2 = []]
  input.each { |x|
    needed = 2020 - x
    next if needed < x
    required_count = x == needed ? 2 : 1
    p1 << x * needed if input_tally[needed] &.>= required_count
  }
  input.combination(2) { |x, y|
    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
  }
  ans
end
def find_by_combination_no_filter_map ( input , input_tally ) ans = [ p1 = [ ] , p2 = [ ] ] input . each { | x | needed = 2020 - x next if needed < x required_count = x == needed ? 2 : 1 p1 << x * needed if input_tally [ needed ] &. >= required_count } input . combination ( 2 ) { | x , y | 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 } ans end
Just some quick checks to make sure it's not because filter_map or combinations are slow.
Just some quick checks to make sure it ' s not because filter_map or combinations are slow .
input
<not_specific>
input_tally
<not_specific>