diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2019-06-04 04:18:45 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-06-04 04:18:45 +0100 |
| commit | f9646a43d8a3d881e93d770a9400a92b511c351b (patch) | |
| tree | 61bad7cbf0944e32d4a092ed5051b879590575ef /challenge-011 | |
| parent | 47f37bec726ae705e23483800ff0b47cf4847986 (diff) | |
| parent | a9a58d82e50aee18bb3113796715e378357e83cb (diff) | |
| download | perlweeklychallenge-club-f9646a43d8a3d881e93d770a9400a92b511c351b.tar.gz perlweeklychallenge-club-f9646a43d8a3d881e93d770a9400a92b511c351b.tar.bz2 perlweeklychallenge-club-f9646a43d8a3d881e93d770a9400a92b511c351b.zip | |
Merge pull request #219 from khalidelboray/patch-5
Perl6 Challenge #2 Solution
Diffstat (limited to 'challenge-011')
| -rw-r--r-- | challenge-011/khalid/perl6/ch-2.p6 | 11 |
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|" ~ * ~ '|' |
