Jump to content

Identity matrix: Difference between revisions

Add Red
(→‎{{header|AppleScript}}: Added simple alternative.)
(Add Red)
Line 3,096:
[1, |(0 xx $n-1)], *.rotate(-1) ... *[*-1]
}</lang>
 
=={{header|Red}}==
<lang rebol>Red[]
 
identity-matrix: function [size][
matrix: copy []
repeat i size [
append/only matrix append/dup copy [] 0 size
matrix/:i/:i: 1
]
matrix
]
 
probe identity-matrix 5</lang>
{{out}}
<pre>
[[1 0 0 0 0] [0 1 0 0 0] [0 0 1 0 0] [0 0 0 1 0] [0 0 0 0 1]]
</pre>
 
=={{header|REXX}}==
1,808

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.