aboutsummaryrefslogtreecommitdiff
path: root/challenge-011
diff options
context:
space:
mode:
authordrclaw1394 <drclaw@mac.com>2019-06-10 20:56:34 +1000
committerGitHub <noreply@github.com>2019-06-10 20:56:34 +1000
commit5c1663e3f7a4bf8767cd62c4e7db03186561edb2 (patch)
tree2a0fa3af0f3b0fd5a71a9ae67984f4fa2adb8aa1 /challenge-011
parentb577c5e4a0a63be26d335cb74580c1ae721105c0 (diff)
parente874646e75a09fbe9c9f248e2071bc4182973b7f (diff)
downloadperlweeklychallenge-club-5c1663e3f7a4bf8767cd62c4e7db03186561edb2.tar.gz
perlweeklychallenge-club-5c1663e3f7a4bf8767cd62c4e7db03186561edb2.tar.bz2
perlweeklychallenge-club-5c1663e3f7a4bf8767cd62c4e7db03186561edb2.zip
Merge pull request #11 from manwar/master
update to week 12
Diffstat (limited to 'challenge-011')
-rw-r--r--challenge-011/aaron-sherman/README1
-rw-r--r--challenge-011/aaron-sherman/perl6/ch-1.p676
-rw-r--r--challenge-011/aaron-sherman/perl6/ch-2.p676
-rw-r--r--challenge-011/adam-russell/blog.txt1
-rw-r--r--challenge-011/adam-russell/perl5/ch-1.pl14
-rw-r--r--challenge-011/adam-russell/perl5/ch-2.pl18
-rw-r--r--challenge-011/alicia-bielsa/perl5/ch-1.pl65
-rw-r--r--challenge-011/alicia-bielsa/perl5/ch-2.pl30
-rw-r--r--challenge-011/andrezgz/perl5/ch-1.pl15
-rw-r--r--challenge-011/andrezgz/perl5/ch-2.pl18
-rw-r--r--challenge-011/arne-sommer/blog.txt1
-rwxr-xr-xchallenge-011/arne-sommer/perl6/ch-1.p619
-rwxr-xr-xchallenge-011/arne-sommer/perl6/ch-1a.p63
-rwxr-xr-xchallenge-011/arne-sommer/perl6/ch-2.p69
-rwxr-xr-xchallenge-011/arne-sommer/perl6/ch-2a.p626
-rwxr-xr-xchallenge-011/arne-sommer/perl6/ch-2b.p617
-rwxr-xr-xchallenge-011/arne-sommer/perl6/ch-2c.p610
-rwxr-xr-xchallenge-011/arne-sommer/perl6/ch-2d.p610
-rw-r--r--challenge-011/athanasius/perl5/ch-1.pl75
-rw-r--r--challenge-011/athanasius/perl5/ch-2.pl78
-rw-r--r--challenge-011/athanasius/perl5/ch-3.pl327
-rw-r--r--challenge-011/daniel-mantovani/perl5/ch-1.pl56
-rw-r--r--challenge-011/dave-jacoby/blog.txt1
-rw-r--r--challenge-011/duncan-c-white/README32
-rwxr-xr-xchallenge-011/duncan-c-white/perl5/ch-1.pl62
-rwxr-xr-xchallenge-011/duncan-c-white/perl5/ch-2.pl31
-rw-r--r--challenge-011/e-choroba/blog.txt1
-rw-r--r--challenge-011/feng-chang/README1
-rw-r--r--challenge-011/feng-chang/perl5/ch-2.pl16
-rwxr-xr-xchallenge-011/feng-chang/perl5/ch-3.pl26
-rw-r--r--challenge-011/feng-chang/perl6/ch-1.p63
-rw-r--r--challenge-011/feng-chang/perl6/ch-2.p68
-rw-r--r--challenge-011/feng-chang/perl6/ch-3.p624
-rw-r--r--challenge-011/fjwhittle/perl6/ch-1.p612
-rw-r--r--challenge-011/fjwhittle/perl6/ch-2.p612
-rw-r--r--challenge-011/gustavo-chaves/perl5/README.pod44
-rwxr-xr-xchallenge-011/gustavo-chaves/perl5/ch-1.pl64
-rwxr-xr-xchallenge-011/gustavo-chaves/perl5/ch-2.pl13
-rwxr-xr-xchallenge-011/gustavo-chaves/perl5/ch-2a.pl12
-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
-rw-r--r--challenge-011/jo-christian-oterhals/blog.txt1
-rw-r--r--challenge-011/jo-christian-oterhals/perl6/ch-1.p621
-rw-r--r--challenge-011/jo-christian-oterhals/perl6/ch-1a.p63
-rw-r--r--challenge-011/jo-christian-oterhals/perl6/ch-2.p65
-rw-r--r--challenge-011/kian-meng-ang/perl5/ch-1.pl15
-rw-r--r--challenge-011/kian-meng-ang/perl5/ch-2.pl22
-rw-r--r--challenge-011/laurent-rosenfeld/blog.txt1
-rw-r--r--challenge-011/laurent-rosenfeld/perl5/ch-1.pl17
-rw-r--r--challenge-011/laurent-rosenfeld/perl5/ch-2.pl17
-rw-r--r--challenge-011/laurent-rosenfeld/perl5/ch-2a.pl19
-rw-r--r--challenge-011/laurent-rosenfeld/perl5/ch-2b.pl17
-rw-r--r--challenge-011/laurent-rosenfeld/perl5/ch-2c.pl14
-rw-r--r--challenge-011/laurent-rosenfeld/perl6/ch-1.p622
-rw-r--r--challenge-011/laurent-rosenfeld/perl6/ch-2.p617
-rw-r--r--challenge-011/laurent-rosenfeld/perl6/ch-2a.p610
-rw-r--r--challenge-011/laurent-rosenfeld/perl6/ch-2b.p69
-rw-r--r--challenge-011/matthew-persico/README1
-rwxr-xr-xchallenge-011/maxim-nechaev/perl5/ch-1.pl22
-rwxr-xr-xchallenge-011/maxim-nechaev/perl5/ch-2.pl13
-rw-r--r--challenge-011/ozzy/perl6/ch-1.p614
-rw-r--r--challenge-011/ozzy/perl6/ch-2.p621
-rw-r--r--challenge-011/steven-wilson/perl5/ch-3.pl71
-rw-r--r--challenge-011/yozen-hernandez/blog.txt1
-rwxr-xr-xchallenge-011/yozen-hernandez/perl5/ch-1.pl32
-rwxr-xr-xchallenge-011/yozen-hernandez/perl5/ch-2.pl37
68 files changed, 1772 insertions, 11 deletions
diff --git a/challenge-011/aaron-sherman/README b/challenge-011/aaron-sherman/README
new file mode 100644
index 0000000000..14ec31f570
--- /dev/null
+++ b/challenge-011/aaron-sherman/README
@@ -0,0 +1 @@
+Solutions by Aaron Sherman.
diff --git a/challenge-011/aaron-sherman/perl6/ch-1.p6 b/challenge-011/aaron-sherman/perl6/ch-1.p6
new file mode 100644
index 0000000000..d61cb697bc
--- /dev/null
+++ b/challenge-011/aaron-sherman/perl6/ch-1.p6
@@ -0,0 +1,76 @@
+#!/usr/bin/env perl6
+
+# From : https://perlweeklychallenge.org/blog/perl-weekly-challenge-011/
+
+# Challenge #1
+# Write a script that computes the equal point in the Fahrenheit and
+# Celsius scales, knowing that the freezing point of water is 32 °F and
+# 0 °C, and that the boiling point of water is 212 °F and 100 °C. This
+# challenge was proposed by Laurent Rosenfeld.
+
+# The challenge was a bit bland, so I jazzed it up.
+# --help for more info
+
+use v6.c;
+
+# Note that this is the only place we keep the
+# units, so everything else except comments has
+# to derive even the abbreviations from this lookup.
+our %knowns = (
+ unit => <F C>,
+ freezing => [32, 0],
+ boiling => [212, 100] );
+
+proto MAIN($input?) {*}
+
+multi MAIN(
+ #= Convert the given value e.g. 37C
+ Str $input where m/<after \d><alpha>$/
+) {
+ my $value = +$input.substr(0,*-1);
+ my $from = $input.substr(*-1);
+ my $units = %knowns<unit>.join('/');
+ die "$from is not one of $units" if !%knowns<unit>.grep: * eq $from;
+ my $to = %knowns<unit>.grep({$_ ne $input}).first;
+ say "$value$from in $to: {convert($value, :$to)}";
+}
+
+multi MAIN(
+ #= Show conversion for given unit e.g. C
+ Str $input where $input eq [|] |%knowns<unit>
+) {
+ my $to = %knowns<unit>.grep({$_ ne $input}).first;
+ my $conversion = conversion(:$to);
+ my $scale = $conversion<scale>.nude.join('/');
+ say "Conversion to $to: {$input}*{$scale} + {$conversion<offset>}";
+}
+
+#= by default show crossover for units
+multi MAIN() {
+ my $units = %knowns<unit>.join('/');
+ say "$units cross over at {crossover}";
+}
+
+sub other-unit($unit) { return %knowns<unit>.grep({$_ ne $unit}).first }
+
+sub convert($value, :$to where $to eq [|] |%knowns<unit>) {
+ my $conv = conversion(:$to);
+ return $value*$conv<scale> + $conv<offset>;
+}
+
+sub crossover() {
+ my $conv = conversion(:to<F>);
+ return $conv<offset>/(1-$conv<scale>);
+}
+
+sub conversion(:$to where $to eq [|] |%knowns<unit>) {
+ my $to-index = %knowns<unit>.first: * eq $to, :k;
+ # Get the offset between the two
+ my $offset = [-] |%knowns<freezing>;
+ my $scale = [/] (|%knowns<boiling> <<->> |%knowns<freezing>);
+ if !$to-index {
+ return { scale => $scale, offset => $offset, index => $to-index };
+ } else {
+ return { scale => 1/$scale, offset => -$offset, index => $to-index };
+ }
+}
diff --git a/challenge-011/aaron-sherman/perl6/ch-2.p6 b/challenge-011/aaron-sherman/perl6/ch-2.p6
new file mode 100644
index 0000000000..d61cb697bc
--- /dev/null
+++ b/challenge-011/aaron-sherman/perl6/ch-2.p6
@@ -0,0 +1,76 @@
+#!/usr/bin/env perl6
+
+# From : https://perlweeklychallenge.org/blog/perl-weekly-challenge-011/
+
+# Challenge #1
+# Write a script that computes the equal point in the Fahrenheit and
+# Celsius scales, knowing that the freezing point of water is 32 °F and
+# 0 °C, and that the boiling point of water is 212 °F and 100 °C. This
+# challenge was proposed by Laurent Rosenfeld.
+
+# The challenge was a bit bland, so I jazzed it up.
+# --help for more info
+
+use v6.c;
+
+# Note that this is the only place we keep the
+# units, so everything else except comments has
+# to derive even the abbreviations from this lookup.
+our %knowns = (
+ unit => <F C>,
+ freezing => [32, 0],
+ boiling => [212, 100] );
+
+proto MAIN($input?) {*}
+
+multi MAIN(
+ #= Convert the given value e.g. 37C
+ Str $input where m/<after \d><alpha>$/
+) {
+ my $value = +$input.substr(0,*-1);
+ my $from = $input.substr(*-1);
+ my $units = %knowns<unit>.join('/');
+ die "$from is not one of $units" if !%knowns<unit>.grep: * eq $from;
+ my $to = %knowns<unit>.grep({$_ ne $input}).first;
+ say "$value$from in $to: {convert($value, :$to)}";
+}
+
+multi MAIN(
+ #= Show conversion for given unit e.g. C
+ Str $input where $input eq [|] |%knowns<unit>
+) {
+ my $to = %knowns<unit>.grep({$_ ne $input}).first;
+ my $conversion = conversion(:$to);
+ my $scale = $conversion<scale>.nude.join('/');
+ say "Conversion to $to: {$input}*{$scale} + {$conversion<offset>}";
+}
+
+#= by default show crossover for units
+multi MAIN() {
+ my $units = %knowns<unit>.join('/');
+ say "$units cross over at {crossover}";
+}
+
+sub other-unit($unit) { return %knowns<unit>.grep({$_ ne $unit}).first }
+
+sub convert($value, :$to where $to eq [|] |%knowns<unit>) {
+ my $conv = conversion(:$to);
+ return $value*$conv<scale> + $conv<offset>;
+}
+
+sub crossover() {
+ my $conv = conversion(:to<F>);
+ return $conv<offset>/(1-$conv<scale>);
+}
+
+sub conversion(:$to where $to eq [|] |%knowns<unit>) {
+ my $to-index = %knowns<unit>.first: * eq $to, :k;
+ # Get the offset between the two
+ my $offset = [-] |%knowns<freezing>;
+ my $scale = [/] (|%knowns<boiling> <<->> |%knowns<freezing>);
+ if !$to-index {
+ return { scale => $scale, offset => $offset, index => $to-index };
+ } else {
+ return { scale => 1/$scale, offset => -$offset, index => $to-index };
+ }
+}
diff --git a/challenge-011/adam-russell/blog.txt b/challenge-011/adam-russell/blog.txt
new file mode 100644
index 0000000000..1b39aba56b
--- /dev/null
+++ b/challenge-011/adam-russell/blog.txt
@@ -0,0 +1 @@
+https://adamcrussell.livejournal.com/3900.html
diff --git a/challenge-011/adam-russell/perl5/ch-1.pl b/challenge-011/adam-russell/perl5/ch-1.pl
new file mode 100644
index 0000000000..a723c744a4
--- /dev/null
+++ b/challenge-011/adam-russell/perl5/ch-1.pl
@@ -0,0 +1,14 @@
+use strict;
+use warnings;
+##
+# Write a script that computes the equal point in the Fahrenheit and Celsius
+# scales, knowing that the freezing point of water is 32 °F and 0 °C, and
+# that the boiling point of water is 212 °F and 100 °C.
+# °F = (°C * 9/5) + 32
+##
+for my $c (-100 .. 100){
+ my $f = ($c * (9/5)) + 32;
+ if($f == $c){
+ print "°F = °C at $f\n";
+ }
+}
diff --git a/challenge-011/adam-russell/perl5/ch-2.pl b/challenge-011/adam-russell/perl5/ch-2.pl
new file mode 100644
index 0000000000..d29c2bf377
--- /dev/null
+++ b/challenge-011/adam-russell/perl5/ch-2.pl
@@ -0,0 +1,18 @@
+use strict;
+use warnings;
+##
+# Write a script to create an Identity Matrix for the given size.
+# For example, if the size is 4, then create Identity Matrix 4x4.
+##
+use constant SIZE => 10;
+
+my @a;
+for my $i (0 .. SIZE - 1){
+ my @b = (0) x SIZE;
+ $b[$i] = 1;
+ push @a, \@b;
+}
+print SIZE . " x " . SIZE . " identity matrix:\n";
+for my $i (0 .. SIZE - 1){
+ print "\t" . join(" ", @{$a[$i]}) . "\n";
+}
diff --git a/challenge-011/alicia-bielsa/perl5/ch-1.pl b/challenge-011/alicia-bielsa/perl5/ch-1.pl
new file mode 100644
index 0000000000..7c90ea500e
--- /dev/null
+++ b/challenge-011/alicia-bielsa/perl5/ch-1.pl
@@ -0,0 +1,65 @@
+use strict;
+use warnings;
+use POSIX;
+
+
+
+
+#Write a script that computes the equal point in the Fahrenheit and Celsius scales
+#knowing that the freezing point of water is 32 °F and 0 °C,
+#and that the boiling point of water is 212 °F and 100 °C.
+#This challenge was proposed by Laurent Rosenfeld
+
+
+my $pointCelsius = 0;
+my $equalPoint = 0;
+my $keepSearching = 1;
+
+while ($keepSearching){
+
+ my $pointFahrenheid= celsiusToFarenheit($pointCelsius) ;
+
+ my $difference = $pointCelsius - $pointFahrenheid;
+
+ if ($difference > 0 ){
+
+ $pointCelsius -= int( $difference/2) ? int( $difference/2) : ceil( $difference/2) ;
+
+ } elsif ($difference < 0 ){
+
+ $pointCelsius += int( $difference/2) ? int( $difference/2) : floor($difference/2) ;
+
+ } else {
+
+ $equalPoint = $pointCelsius;
+
+ $keepSearching = 0;
+ }
+}
+
+
+print "Equal Point is $equalPoint\n";
+
+
+
+sub fahrenheitToCelsius {
+
+ my $degreesFarenheit = shift;
+
+ my $degreesCelsius = ($degreesFarenheit - 32) * 5 / 9;
+
+ return $degreesCelsius;
+
+}
+
+
+
+sub celsiusToFarenheit {
+
+ my $degreesCelsius = shift;
+
+ my $degreesFarenheit = $degreesCelsius * 9 / 5 + 32;
+
+ return $degreesFarenheit;
+
+} \ No newline at end of file
diff --git a/challenge-011/alicia-bielsa/perl5/ch-2.pl b/challenge-011/alicia-bielsa/perl5/ch-2.pl
new file mode 100644
index 0000000000..d645f4bffb
--- /dev/null
+++ b/challenge-011/alicia-bielsa/perl5/ch-2.pl
@@ -0,0 +1,30 @@
+#Write a script to create an Indentity Matrix for the given size.
+#For example, if the size is 4, then create Identity Matrix 4x4.
+#For more information about Indentity Matrix, please read the wiki page.
+
+use strict;
+use warnings;
+
+my $size = 11;
+
+my @aIdentityMatrix = ();
+
+for my $a (0..$size-1){
+ my @aRow = ();
+ for my $b (0..$size-1){
+ if ($a == $b){
+ push (@aRow, 1);
+ } else {
+ push (@aRow, 0);
+ }
+ }
+ push ( @aIdentityMatrix , \@aRow);
+}
+
+
+foreach my $row (@aIdentityMatrix){
+ foreach my $column ( @{$row} ) {
+ print $column ."\t";
+ }
+ print "\n";
+} \ No newline at end of file
diff --git a/challenge-011/andrezgz/perl5/ch-1.pl b/challenge-011/andrezgz/perl5/ch-1.pl
new file mode 100644
index 0000000000..2671169b2b
--- /dev/null
+++ b/challenge-011/andrezgz/perl5/ch-1.pl
@@ -0,0 +1,15 @@
+#!/usr/bin/perl
+
+# https://perlweeklychallenge.org/blog/perl-weekly-challenge-011/
+# Challenge #1
+# Write a script that computes the equal point in the Fahrenheit and Celsius scales,
+# knowing that the freezing point of water is 32 °F and 0 °C,
+# and that the boiling point of water is 212 °F and 100 °C.
+# This challenge was proposed by Laurent Rosenfeld.
+
+use strict;
+use warnings;
+
+my $f = 212;
+while ( $f - ($f - 32) * (100-0)/(212-32) ) { $f-- }; #Simple, but effective
+print $f;
diff --git a/challenge-011/andrezgz/perl5/ch-2.pl b/challenge-011/andrezgz/perl5/ch-2.pl
new file mode 100644
index 0000000000..276dbc4453
--- /dev/null
+++ b/challenge-011/andrezgz/perl5/ch-2.pl
@@ -0,0 +1,18 @@
+#!/usr/bin/perl
+
+# https://perlweeklychallenge.org/blog/perl-weekly-challenge-011/
+# Challenge #2
+# Write a script to create an Indentity Matrix for the given size.
+# For example, if the size is 4, then create Identity Matrix 4x4.
+# For more information about Indentity Matrix, please read the wiki page.
+# https://en.wikipedia.org/wiki/Identity_matrix
+
+
+use strict;
+use warnings;
+
+die "Usage: $0 <matrix-size>" unless $ARGV[0] && $ARGV[0] =~ /\d+/;
+
+my $n = int($ARGV[0]) - 1;
+
+for (0..$n) { print " 0" x $_ . " 1" . " 0" x ($n - $_) . $/; }
diff --git a/challenge-011/arne-sommer/blog.txt b/challenge-011/arne-sommer/blog.txt
new file mode 100644
index 0000000000..ff33263a07
--- /dev/null
+++ b/challenge-011/arne-sommer/blog.txt
@@ -0,0 +1 @@
+https://perl6.eu/fc-matrix.html
diff --git a/challenge-011/arne-sommer/perl6/ch-1.p6 b/challenge-011/arne-sommer/perl6/ch-1.p6
new file mode 100755
index 0000000000..8160d12bfe
--- /dev/null
+++ b/challenge-011/arne-sommer/perl6/ch-1.p6
@@ -0,0 +1,19 @@
+#! /usr/bin/env perl6
+
+my $c = 0;
+
+loop
+{
+ my $f = celcius2fahrenheit($c);
+ if $f <= $c
+ {
+ say "Fahrenheit ($f) and Celsius ($c) are equal(ish).";
+ last;
+ }
+ $c--;
+}
+
+sub celcius2fahrenheit ($c)
+{
+ return $c * 1.8 + 32;
+}
diff --git a/challenge-011/arne-sommer/perl6/ch-1a.p6 b/challenge-011/arne-sommer/perl6/ch-1a.p6
new file mode 100755
index 0000000000..9799e85810
--- /dev/null
+++ b/challenge-011/arne-sommer/perl6/ch-1a.p6
@@ -0,0 +1,3 @@
+#! /usr/bin/env perl6
+
+say "Fahrenheit and Celsius are equal at -40.";
diff --git a/challenge-011/arne-sommer/perl6/ch-2.p6 b/challenge-011/arne-sommer/perl6/ch-2.p6
new file mode 100755
index 0000000000..89ff615443
--- /dev/null
+++ b/challenge-011/arne-sommer/perl6/ch-2.p6
@@ -0,0 +1,9 @@
+#! /usr/bin/env perl6
+
+use Math::Matrix;
+
+unit sub MAIN (Int $size where $size > 0);
+
+my $im = Math::Matrix.new-identity( $size );
+
+say $im;
diff --git a/challenge-011/arne-sommer/perl6/ch-2a.p6 b/challenge-011/arne-sommer/perl6/ch-2a.p6
new file mode 100755
index 0000000000..0dd48982f3
--- /dev/null
+++ b/challenge-011/arne-sommer/perl6/ch-2a.p6
@@ -0,0 +1,26 @@
+#! /usr/bin/env perl6
+
+unit sub MAIN (Int $size where $size > 0);
+
+my @im[$size;$size] = 0 xx $size xx $size;
+
+@im[$_;$_] = 1 for ^$size;
+
+print @im.&nice-format;
+
+sub nice-format (@shaped)
+{
+ my ($row, $col) = @shaped.shape;
+
+ my $result;
+
+ for ^$row -> $x
+ {
+ for ^$col -> $y
+ {
+ $result ~= @shaped[$x;$y] ~ " ";
+ }
+ $result ~= "\n";
+ }
+ return $result;
+} \ No newline at end of file
diff --git a/challenge-011/arne-sommer/perl6/ch-2b.p6 b/challenge-011/arne-sommer/perl6/ch-2b.p6
new file mode 100755
index 0000000000..6c95394f34
--- /dev/null
+++ b/challenge-011/arne-sommer/perl6/ch-2b.p6
@@ -0,0 +1,17 @@
+#! /usr/bin/env perl6
+
+unit sub MAIN (Int $size where $size > 0);
+
+# my @im = 0 xx $size xx $size;
+# @im[$_;$_] = 1 for ^$size;
+
+my @row = (1, 0 xx $size -1).flat;
+my @x; @x.push: @row.rotate(- $_) for ^$size;
+my @im = @x;
+
+print @im.&nice-format;
+
+sub nice-format (@array)
+{
+ return (@($_).join(" ") for @array).join("\n") ~ "\n";
+} \ No newline at end of file
diff --git a/challenge-011/arne-sommer/perl6/ch-2c.p6 b/challenge-011/arne-sommer/perl6/ch-2c.p6
new file mode 100755
index 0000000000..2979c44550
--- /dev/null
+++ b/challenge-011/arne-sommer/perl6/ch-2c.p6
@@ -0,0 +1,10 @@