aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJaldhar H. Vyas <jaldhar@braincells.com>2019-06-08 23:29:26 -0400
committerJaldhar H. Vyas <jaldhar@braincells.com>2019-06-08 23:29:26 -0400
commit200df31e40095ad9494cc5f383d3cb35c73d9d7c (patch)
tree61822603925e14fa760da4ba30ac3deb3645a834
parent82d3bc4156c6bc9a94bb5d6bca89b7b747371cc6 (diff)
downloadperlweeklychallenge-club-200df31e40095ad9494cc5f383d3cb35c73d9d7c.tar.gz
perlweeklychallenge-club-200df31e40095ad9494cc5f383d3cb35c73d9d7c.tar.bz2
perlweeklychallenge-club-200df31e40095ad9494cc5f383d3cb35c73d9d7c.zip
Challenge 11 by Jaldhar H. Vyas
-rwxr-xr-xchallenge-011/jaldhar-h-vyas/perl5/ch-1.pl13
-rwxr-xr-xchallenge-011/jaldhar-h-vyas/perl5/ch-2.pl27
-rwxr-xr-xchallenge-011/jaldhar-h-vyas/perl6/ch-1.sh1
-rwxr-xr-xchallenge-011/jaldhar-h-vyas/perl6/ch-2.p613
4 files changed, 54 insertions, 0 deletions
diff --git a/challenge-011/jaldhar-h-vyas/perl5/ch-1.pl b/challenge-011/jaldhar-h-vyas/perl5/ch-1.pl
new file mode 100755
index 0000000000..323424fe7e
--- /dev/null
+++ b/challenge-011/jaldhar-h-vyas/perl5/ch-1.pl
@@ -0,0 +1,13 @@
+#!/usr/bin/perl
+use warnings;
+use strict;
+use 5.010;
+
+my $x = 0;
+
+# We know x cannot be positive because 0C = 32F...
+while ($x != 32 + 1.8 * $x) {
+ $x--; # ...so count backwards.
+}
+
+say $x; \ No newline at end of file
diff --git a/challenge-011/jaldhar-h-vyas/perl5/ch-2.pl b/challenge-011/jaldhar-h-vyas/perl5/ch-2.pl
new file mode 100755
index 0000000000..5cd275cae8
--- /dev/null
+++ b/challenge-011/jaldhar-h-vyas/perl5/ch-2.pl
@@ -0,0 +1,27 @@
+#!/usr/bin/perl
+use warnings;
+use strict;
+use 5.010;
+
+sub usage() {
+ print <<"-USAGE-";
+Usage:
+ $0 <n>
+
+ <n> the size of the identity matrix
+-USAGE-
+exit(1);
+}
+
+my $n = shift // usage();
+
+if ($n < 2) {
+ usage();
+}
+
+for my $i (0 .. $n - 1) {
+ for my $j (0 .. $n - 1) {
+ print (($j == $i) ? '1 ' : '0 ');
+ }
+ print "\n";
+}
diff --git a/challenge-011/jaldhar-h-vyas/perl6/ch-1.sh b/challenge-011/jaldhar-h-vyas/perl6/ch-1.sh
new file mode 100755
index 0000000000..dfe59c1eee
--- /dev/null
+++ b/challenge-011/jaldhar-h-vyas/perl6/ch-1.sh
@@ -0,0 +1 @@
+perl6 -e 'say (0, -1 ... { $_ == 32 + 1.8 * $_ })[*-1];' \ No newline at end of file
diff --git a/challenge-011/jaldhar-h-vyas/perl6/ch-2.p6 b/challenge-011/jaldhar-h-vyas/perl6/ch-2.p6
new file mode 100755
index 0000000000..2019d97295
--- /dev/null
+++ b/challenge-011/jaldhar-h-vyas/perl6/ch-2.p6
@@ -0,0 +1,13 @@
+#!/usr/bin/perl6
+
+multi sub MAIN(
+ Int $n where $n > 1#= the size of the identity matrix
+) {
+
+ for (0 .. $n - 1) -> $i {
+ for (0 .. $n - 1) -> $j {
+ print ($j == $i) ?? '1 ' !! '0 ';
+ }
+ print "\n";
+ }
+} \ No newline at end of file