diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2021-10-07 18:28:35 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-10-07 18:28:35 +0100 |
| commit | 7a907d8c690e855db6ef743393e28298d299d50b (patch) | |
| tree | fdc86e447ab8cb690a8df945ae3c3d6f71438121 | |
| parent | 3c9fef4ee43074c9a2a13b6f47a2c44ef438ee2f (diff) | |
| parent | 3f6a727acdf2489318a88eefcb5b3b396b5492ce (diff) | |
| download | perlweeklychallenge-club-7a907d8c690e855db6ef743393e28298d299d50b.tar.gz perlweeklychallenge-club-7a907d8c690e855db6ef743393e28298d299d50b.tar.bz2 perlweeklychallenge-club-7a907d8c690e855db6ef743393e28298d299d50b.zip | |
Merge pull request #4984 from oWnOIzRi/week133
add solution week 133 task 1 in perl
| -rw-r--r-- | challenge-133/steven-wilson/perl/ch-1.pl | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/challenge-133/steven-wilson/perl/ch-1.pl b/challenge-133/steven-wilson/perl/ch-1.pl new file mode 100644 index 0000000000..150a2d5fae --- /dev/null +++ b/challenge-133/steven-wilson/perl/ch-1.pl @@ -0,0 +1,25 @@ +#!/usr/bin/env perl + +use strict; +use warnings; +use Test::More; + +my @test_input = qw/ 10 27 85 101 /; +my @test_output = qw/ 3 5 9 10 /; + +foreach my $i ( 1 .. ( scalar @test_input ) ) { + ok( find_isqrt( $test_input[ $i - 1 ] ) == $test_output[ $i - 1 ], "test $i" ); +} +done_testing(); + +sub find_isqrt { + my $input = shift; + my $x = $input; + use integer; + my $y = ( $x + 1 ) / 2; + while ( $y < $x ) { + $x = $y; + $y = ( ( $x + $input / $x ) / 2 ); + } + return $x; +} |
