diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2022-01-21 08:31:07 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-01-21 08:31:07 +0000 |
| commit | 939c27e6694f95bc1792c77e3689799a7afaa4eb (patch) | |
| tree | d8de44c84e4b71cd8e3f5d61e05b95f4bf97ea18 | |
| parent | 6dbc3a09469ff878dd9d6f677ba6dbde38224942 (diff) | |
| parent | 5400b64d1fafdf0047aad6f38a35c93fc24f9cc3 (diff) | |
| download | perlweeklychallenge-club-939c27e6694f95bc1792c77e3689799a7afaa4eb.tar.gz perlweeklychallenge-club-939c27e6694f95bc1792c77e3689799a7afaa4eb.tar.bz2 perlweeklychallenge-club-939c27e6694f95bc1792c77e3689799a7afaa4eb.zip | |
Merge pull request #5548 from oWnOIzRi/week148
add solution week 148 task 2 in perl
| -rw-r--r-- | challenge-148/steven-wilson/perl/ch-02.pl | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/challenge-148/steven-wilson/perl/ch-02.pl b/challenge-148/steven-wilson/perl/ch-02.pl new file mode 100644 index 0000000000..f1beb1d333 --- /dev/null +++ b/challenge-148/steven-wilson/perl/ch-02.pl @@ -0,0 +1,31 @@ +#!/usr/bin/env perl +# Week 148 Task 2 +# Cardano Triplets +# Write a script to generate first 5 Cardano Triplets. +# A triplet of positive integers (a,b,c) is called +# a Cardano Triplet if it satisfies the below condition. + +use strict; +use warnings; +use feature qw/ say /; +use POSIX qw/ cbrt sqrt /; + +my $max = 117; +my $counter = 0; + +FIRST_FIVE: for my $a ( 1 .. $max ) { + for my $b ( 1 .. $max ) { + for my $c ( 1 .. $max ) { + if ( ( cbrt( $a + $b * sqrt($c) ) + cbrt( $a - $b * sqrt($c) ) ) + == 1 ) + { + say "($a, $b, $c)"; + $counter++; + if ( $counter == 5 ) { + last FIRST_FIVE; + } + } + } + } +} + |
