2016-12-05 23:44:36 +01:00
|
|
|
|
func identity_matrix(n) {
|
2017-09-23 10:01:46 +02:00
|
|
|
|
n.of { |i|
|
|
|
|
|
|
n.of { |j|
|
|
|
|
|
|
i == j ? 1 : 0
|
|
|
|
|
|
}
|
2016-12-05 23:44:36 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-09-23 10:01:46 +02:00
|
|
|
|
for n (ARGV ? ARGV.map{.to_i} : [4, 5, 6]) {
|
|
|
|
|
|
say "\n#{n}:"
|
|
|
|
|
|
for row (identity_matrix(n)) {
|
|
|
|
|
|
say row.join(' ')
|
2016-12-05 23:44:36 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|