Class: SomethingLikeThat::TwoDArray
- Inherits:
-
Array
- Object
- Array
- SomethingLikeThat::TwoDArray
- 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
-
#initialize(array) ⇒ TwoDArray
constructor
A new instance of TwoDArray.
- #lengths ⇒ Object
-
#maxima ⇒ Object
TODO: rename (incl. corresponding method call in Scorer).
- #pop_max ⇒ Object
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
#lengths ⇒ Object
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 |
#maxima ⇒ Object
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_max ⇒ Object
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 |