From b47374a1e63dd70f4c56ec80ba3bb304cef60f80 Mon Sep 17 00:00:00 2001 From: Khaled Mohamed Elborey <37024839+khalidelboray@users.noreply.github.com> Date: Tue, 4 Jun 2019 05:14:58 +0200 Subject: Perl6 Challenge #2 Solution --- challenge-011/khalid/perl6/ch-2.p6 | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 challenge-011/khalid/perl6/ch-2.p6 (limited to 'challenge-011') diff --git a/challenge-011/khalid/perl6/ch-2.p6 b/challenge-011/khalid/perl6/ch-2.p6 new file mode 100644 index 0000000000..f1b8b09b59 --- /dev/null +++ b/challenge-011/khalid/perl6/ch-2.p6 @@ -0,0 +1,10 @@ +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) + } + @id; +} +say "Rows : " ,identity-matrix(@*ARGS[0]).perl; +say "Formated Matrix : \t"; +.say for identity-matrix(@*ARGS[0]).map: "\t|" ~ * ~ '|' -- cgit From a9a58d82e50aee18bb3113796715e378357e83cb Mon Sep 17 00:00:00 2001 From: Khaled Mohamed Elborey <37024839+khalidelboray@users.noreply.github.com> Date: Tue, 4 Jun 2019 05:17:57 +0200 Subject: Update ch-2.p6 --- challenge-011/khalid/perl6/ch-2.p6 | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'challenge-011') diff --git a/challenge-011/khalid/perl6/ch-2.p6 b/challenge-011/khalid/perl6/ch-2.p6 index f1b8b09b59..6bd045c9e1 100644 --- a/challenge-011/khalid/perl6/ch-2.p6 +++ b/challenge-011/khalid/perl6/ch-2.p6 @@ -2,9 +2,10 @@ 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 : \t"; -.say for identity-matrix(@*ARGS[0]).map: "\t|" ~ * ~ '|' +say "Rows : " ,identity-matrix(@*ARGS[0]).perl; +say "Formated Matrix : "; +.say for identity-matrix(@*ARGS[0]).map: "\t\t|" ~ * ~ '|' -- cgit