Task

Build an   identity matrix   of a size known at run-time.



An identity matrix is a square matrix of size n × n,

where the diagonal elements are all 1s (ones),

and all the other elements are all 0s (zeroes).







I

n


=


[



1


0


0


⋯


0




0


1


0


⋯


0




0


0


1


⋯


0




⋮


⋮


⋮


⋱


⋮




0


0


0


⋯


1



]




{\displaystyle I_{n}={\begin{bmatrix}1&0&0&\cdots &0\\0&1&0&\cdots &0\\0&0&1&\cdots &0\\\vdots &\vdots &\vdots &\ddots &\vdots \\0&0&0&\cdots &1\\\end{bmatrix}}}





Related tasks

   Spiral matrix
   Zig-zag matrix 
   Ulam_spiral_(for_primes)


default {
	state_entry() {
		llListen(PUBLIC_CHANNEL, "", llGetOwner(), "");
		llOwnerSay("Please Enter a Dimension for an Identity Matrix.");
	}
	listen(integer iChannel, string sName, key kId, string sMessage) {
		llOwnerSay("You entered "+sMessage+".");
		list lMatrix = [];
		integer x = 0;
		integer n = (integer)sMessage;
		for(x=0 ; x<n*n ; x++) {
			lMatrix += [(integer)(((x+1)%(n+1))==1)];
		}
		//llOwnerSay("["+llList2CSV(lMatrix)+"]");
		for(x=0 ; x<n ; x++) {
			llOwnerSay("["+llList2CSV(llList2ListStrided(lMatrix, x*n, (x+1)*n-1, 1))+"]");
		}
	}
}