Sha256: 6795a549101154013973666f972aeedf85ead0130a9d207f0a1c192f0365a65b

Contents?: true

Size: 459 Bytes

Versions: 396

Compression:

Stored size: 459 Bytes

Contents

class Matrix
  attr_reader :rows, :columns
  def initialize(input)
    @rows = extract_rows(input)
    @columns = extract_columns(rows)
  end

  private

  def extract_rows(s)
    s.split("\n").map do |row|
      row.split(' ').map(&:to_i)
    end
  end

  def extract_columns(rows)
    columns = []
    rows.each do |row|
      row.each_with_index do |number, i|
        columns[i] ||= []
        columns[i] << number
      end
    end
    columns
  end
end

Version data entries

396 entries across 396 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/ruby/exercises/matrix/.meta/solutions/matrix.rb
trackler-2.2.1.179 tracks/ruby/exercises/matrix/.meta/solutions/matrix.rb
trackler-2.2.1.178 tracks/ruby/exercises/matrix/.meta/solutions/matrix.rb
trackler-2.2.1.177 tracks/ruby/exercises/matrix/.meta/solutions/matrix.rb
trackler-2.2.1.176 tracks/ruby/exercises/matrix/.meta/solutions/matrix.rb
trackler-2.2.1.175 tracks/ruby/exercises/matrix/.meta/solutions/matrix.rb
trackler-2.2.1.174 tracks/ruby/exercises/matrix/.meta/solutions/matrix.rb
trackler-2.2.1.173 tracks/ruby/exercises/matrix/.meta/solutions/matrix.rb
trackler-2.2.1.172 tracks/ruby/exercises/matrix/.meta/solutions/matrix.rb
trackler-2.2.1.171 tracks/ruby/exercises/matrix/.meta/solutions/matrix.rb
trackler-2.2.1.170 tracks/ruby/exercises/matrix/.meta/solutions/matrix.rb
trackler-2.2.1.169 tracks/ruby/exercises/matrix/.meta/solutions/matrix.rb
trackler-2.2.1.167 tracks/ruby/exercises/matrix/.meta/solutions/matrix.rb
trackler-2.2.1.166 tracks/ruby/exercises/matrix/.meta/solutions/matrix.rb
trackler-2.2.1.165 tracks/ruby/exercises/matrix/.meta/solutions/matrix.rb
trackler-2.2.1.164 tracks/ruby/exercises/matrix/.meta/solutions/matrix.rb
trackler-2.2.1.163 tracks/ruby/exercises/matrix/.meta/solutions/matrix.rb
trackler-2.2.1.162 tracks/ruby/exercises/matrix/.meta/solutions/matrix.rb
trackler-2.2.1.161 tracks/ruby/exercises/matrix/.meta/solutions/matrix.rb
trackler-2.2.1.160 tracks/ruby/exercises/matrix/.meta/solutions/matrix.rb