aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2021-10-10 00:47:40 +0100
committerGitHub <noreply@github.com>2021-10-10 00:47:40 +0100
commit0c16a86f9e3e425b89733cb30751fe0db08a22a0 (patch)
tree33617ffd0602bad33cac0383e237b0544ebfa0cc
parentdf2e855235e01ff30d662cf69f3bd9fca79b3fca (diff)
parent9201f43751790fffe346b95e15193d031b700106 (diff)
downloadperlweeklychallenge-club-0c16a86f9e3e425b89733cb30751fe0db08a22a0.tar.gz
perlweeklychallenge-club-0c16a86f9e3e425b89733cb30751fe0db08a22a0.tar.bz2
perlweeklychallenge-club-0c16a86f9e3e425b89733cb30751fe0db08a22a0.zip
Merge pull request #4994 from rage311/133
Challenge 133
-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');