aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-011/khalid/perl6/ch-2.p611
1 files changed, 11 insertions, 0 deletions
diff --git a/challenge-011/khalid/perl6/ch-2.p6 b/challenge-011/khalid/perl6/ch-2.p6
new file mode 100644
index 0000000000..6bd045c9e1
--- /dev/null
+++ b/challenge-011/khalid/perl6/ch-2.p6
@@ -0,0 +1,11 @@
+sub identity-matrix($n) {
+ my @id;
+ for flat ^$n X ^$n -> $i, $j { #0 0 , 0 1 , 0 2 , 0 3 , 0 4 etc..
+ @id[$i][$j] = ($i == $j).Int; #the matrix element takes value of '1' if (i=j)
+ #because the Identity matrix has ones on the main diagonal and zeros elsewhere.
+ }
+ @id;
+}
+say "Rows : " ,identity-matrix(@*ARGS[0]).perl;
+say "Formated Matrix : ";
+.say for identity-matrix(@*ARGS[0]).map: "\t\t|" ~ * ~ '|'