15 lines
230 B
Text
15 lines
230 B
Text
|
|
func identity_matrix(n) {
|
|||
|
|
n.of { |i|
|
|||
|
|
n.of { |j|
|
|||
|
|
i == j ? 1 : 0
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
for n (ARGV ? ARGV.map{.to_i} : [4, 5, 6]) {
|
|||
|
|
say "\n#{n}:"
|
|||
|
|
for row (identity_matrix(n)) {
|
|||
|
|
say row.join(' ')
|
|||
|
|
}
|
|||
|
|
}
|