aboutsummaryrefslogtreecommitdiff
path: root/challenge-011
diff options
context:
space:
mode:
authorMohammad S Anwar <mohammad.anwar@yahoo.com>2019-06-07 11:21:07 +0100
committerMohammad S Anwar <mohammad.anwar@yahoo.com>2019-06-07 11:21:07 +0100
commite3d46091fdb8bf0c49294bf8a6d6d94502ed1be7 (patch)
tree7f0dda85a544f1086d60b14d2a17200f0d366d97 /challenge-011
parentabbe03fdbb07cb0da906340a0216a93fda739498 (diff)
downloadperlweeklychallenge-club-e3d46091fdb8bf0c49294bf8a6d6d94502ed1be7.tar.gz
perlweeklychallenge-club-e3d46091fdb8bf0c49294bf8a6d6d94502ed1be7.tar.bz2
perlweeklychallenge-club-e3d46091fdb8bf0c49294bf8a6d6d94502ed1be7.zip
- Added solution by Maxim Nechaev.
Diffstat (limited to 'challenge-011')
-rwxr-xr-xchallenge-011/maxim-nechaev/perl5/ch-1.pl22
-rwxr-xr-xchallenge-011/maxim-nechaev/perl5/ch-2.pl13
2 files changed, 35 insertions, 0 deletions
diff --git a/challenge-011/maxim-nechaev/perl5/ch-1.pl b/challenge-011/maxim-nechaev/perl5/ch-1.pl
new file mode 100755
index 0000000000..11735070d8
--- /dev/null
+++ b/challenge-011/maxim-nechaev/perl5/ch-1.pl
@@ -0,0 +1,22 @@
+#!/usr/bin/perl -w
+use strict;
+use feature 'say';
+
+# function to find root
+sub f {
+ my $c = shift; # celsius
+ my $f = 9*$c/5 + 32; # fahrenheit
+ return $c - $f;
+}
+
+# see https://en.wikipedia.org/wiki/Bisection_method
+my $a = -1000; # begin interval
+my $b = 1000; # end interval
+my $s = 1E-13; # accuracy
+my $x; # root to find
+do {
+ $x = ($a + $b)/2;
+ f($a) * f($x) < 0? $b = $x : $a = $x;
+} while abs f($x) > $s;
+
+say $x; # -40
diff --git a/challenge-011/maxim-nechaev/perl5/ch-2.pl b/challenge-011/maxim-nechaev/perl5/ch-2.pl
new file mode 100755
index 0000000000..c3430a1095
--- /dev/null
+++ b/challenge-011/maxim-nechaev/perl5/ch-2.pl
@@ -0,0 +1,13 @@
+#!/usr/bin/perl -w
+use strict;
+use Math::Matrix;
+
+my $size = 5;
+my $indentity = Math::Matrix->diagonal( (1) x $size );
+
+print $indentity;
+# 1.00000 0.00000 0.00000 0.00000 0.00000
+# 0.00000 1.00000 0.00000 0.00000 0.00000
+# 0.00000 0.00000 1.00000 0.00000 0.00000
+# 0.00000 0.00000 0.00000 1.00000 0.00000
+# 0.00000 0.00000 0.00000 0.00000 1.00000