Skip to content

Perl6 Challenge #2 Solution #219

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 4, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions challenge-011/khalid/perl6/ch-2.p6
Original file line number Diff line number Diff line change
@@ -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|" ~ * ~ '|'