diff options
| author | Steven Wilson <steven1170@zoho.eu> | 2022-01-20 20:52:46 +0000 |
|---|---|---|
| committer | Steven Wilson <steven1170@zoho.eu> | 2022-01-20 20:52:46 +0000 |
| commit | 5400b64d1fafdf0047aad6f38a35c93fc24f9cc3 (patch) | |
| tree | c98d9a15057c8d2073b35e97141ebe2c536b8d05 | |
| parent | 41ffff4cdd277812f256e75acdb5f62e3b0dc906 (diff) | |
| download | perlweeklychallenge-club-5400b64d1fafdf0047aad6f38a35c93fc24f9cc3.tar.gz perlweeklychallenge-club-5400b64d1fafdf0047aad6f38a35c93fc24f9cc3.tar.bz2 perlweeklychallenge-club-5400b64d1fafdf0047aad6f38a35c93fc24f9cc3.zip | |
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; + } + } + } + } +} + |
