diff options
| -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; + } + } + } + } +} + |
