Class: SomethingLikeThat::TwoDArray

Inherits:
Array
  • Object
show all
Defined in:
lib/something_like_that/two_d_array.rb

Overview

Holds a 2-dimensional numeric array. Unstable. We’re holding out for a better numeric array library…

Instance Method Summary collapse

Constructor Details

#initialize(array) ⇒ TwoDArray

Returns a new instance of TwoDArray.



7
8
9
# File 'lib/something_like_that/two_d_array.rb', line 7

def initialize(array)
  super array
end

Instance Method Details

#lengthsObject



24
25
26
27
28
29
# File 'lib/something_like_that/two_d_array.rb', line 24

def lengths
  x = length
  y = map(&:length).max
  min, max = [x, y].minmax
  OpenStruct.new(x: x, y: y, min: min, max: max)
end

#maximaObject

TODO: rename (incl. corresponding method call in Scorer)



12
13
14
15
16
# File 'lib/something_like_that/two_d_array.rb', line 12

def maxima
  max_vals = Array.new(length)
  double = dup
  max_vals.map.with_index { |_, i| i < lengths.min ? double.pop_max : 0 }
end

#pop_maxObject



18
19
20
21
22
# File 'lib/something_like_that/two_d_array.rb', line 18

def pop_max
  max = flatten.max
  eliminate(coords(max))
  max
end