Skip to content

Instantly share code, notes, and snippets.

@abo-elleef
Forked from hkilis/anding_bool_matrices.rb
Last active September 15, 2018 08:36
Show Gist options
  • Save abo-elleef/c3c13784da78462acf68580374e9f680 to your computer and use it in GitHub Desktop.
Save abo-elleef/c3c13784da78462acf68580374e9f680 to your computer and use it in GitHub Desktop.
class Matrix
def &(matrix)
Matrix.Raise ErrDimensionMismatch, "Matrix dimension mismatch" unless (row_count == matrix.row_count && column_count == matrix.column_count)
rows = Array.new(row_count) {|i|
Array.new(column_count) {|j|
self[i, j] & matrix[i, j]
}
}
new_matrix rows, matrix.column_count
end
end
a = Matrix.rows [[true, false], [true, true], [false, false], [false, true]]
b = Matrix.rows [[false, true], [false, true], [true, false], [true, true]]
a & b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment