2019/day19.rb
# Scan a row using this principle:
#
# If a previous row was known to be WIDTH wide starting from PREV_LEFT,
# then assume this row is also at least WIDTH wide starting from l > PREV_LEFT.
# That means if we scan every WIDTH squares starting from PREV_LEFT, we'll find it.
#
# Detetermines the left and width of this row.
Scan a row using this principle:
If a previous row was known to be WIDTH wide starting from PREV_LEFT,
then assume this row is also at least WIDTH wide starting from l > PREV_LEFT.
That means if we scan every WIDTH squares starting from PREV_LEFT, we'll find it.

Detetermines the left and width of this row.
Scan a row using this principle : If a previous row was known to be WIDTH wide starting from PREV_LEFT then assume this row is also at least WIDTH wide starting from l > PREV_LEFT . That means if we scan every WIDTH squares starting from PREV_LEFT we ' ll find it . Detetermines the left and width of this row .
def scan_row(y, min_x, min_width)
  near_left_x = min_x.step(by: min_width).find { |x| pull?(y, x) }
  left_x = ((near_left_x - min_width + 1)...near_left_x).bsearch { |x| pull?(y, x) } || near_left_x
  max_width = 1.step { |power|
    width = min_width << power
    break width if !pull?(y, left_x + width)
  }
  {
    left_x: left_x,
    width: ((max_width / 2)..max_width).bsearch { |width| !pull?(y, left_x + width) },
  }.freeze
end
def scan_row ( y , min_x , min_width ) near_left_x = min_x . step ( by : min_width ) . find { | x | pull? ( y , x ) } left_x = ( ( near_left_x - min_width + 1 ) ... near_left_x ) . bsearch { | x | pull? ( y , x ) } || near_left_x max_width = 1 . step { | power | width = min_width << power break width if ! pull? ( y , left_x + width ) } { left_x : left_x , width : ( ( max_width / 2 ) .. max_width ) . bsearch { | width | ! pull? ( y , left_x + width ) } , } . freeze end
Scan a row using this principle:
If a previous row was known to be WIDTH wide starting from PREV_LEFT,
then assume this row is also at least WIDTH wide starting from l > PREV_LEFT.
Scan a row using this principle : If a previous row was known to be WIDTH wide starting from PREV_LEFT then assume this row is also at least WIDTH wide starting from l > PREV_LEFT .
y
min_x
min_width