aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrage311 <rage_311@hotmail.com>2021-10-09 16:14:58 -0600
committerrage311 <rage_311@hotmail.com>2021-10-09 16:14:58 -0600
commit9201f43751790fffe346b95e15193d031b700106 (patch)
treef71a221f1bc4b47b7500fee19070f426576f06c1
parentdfc0b71eb6c46c8f48c1f9e4fc68f1f927ddb574 (diff)
downloadperlweeklychallenge-club-9201f43751790fffe346b95e15193d031b700106.tar.gz
perlweeklychallenge-club-9201f43751790fffe346b95e15193d031b700106.tar.bz2
perlweeklychallenge-club-9201f43751790fffe346b95e15193d031b700106.zip
Added challenge #1
-rw-r--r--challenge-133/rage311/perl/ch-1.pl25
1 files changed, 25 insertions, 0 deletions
diff --git a/challenge-133/rage311/perl/ch-1.pl b/challenge-133/rage311/perl/ch-1.pl
new file mode 100644
index 0000000000..5b838433f6
--- /dev/null
+++ b/challenge-133/rage311/perl/ch-1.pl
@@ -0,0 +1,25 @@
+#!/usr/bin/env perl
+
+use 5.034;
+use warnings;
+use feature 'signatures';
+no warnings 'experimental::signatures';
+use Test::Simple tests => 4;
+
+# TASK #1 › Integer Square Root
+# Submitted by: Mohammad S Anwar
+# You are given a positive integer $N.
+# Write a script to calculate the integer square root of the given number.
+
+sub int_sqrt ($in) {
+ my $guess = int($in / 2);
+ while ((my $new_guess = int(($guess + int($in / $guess)) * 0.5)) != $guess) {
+ $guess = $new_guess;
+ }
+ return $guess;
+}
+
+ok(int_sqrt(10) == 3, 'int_sqrt(10) == 3');
+ok(int_sqrt(27) == 5, 'int_sqrt(27) == 5');
+ok(int_sqrt(85) == 9, 'int_sqrt(85) == 9');
+ok(int_sqrt(101) == 10, 'int_sqrt(101) == 10');