From 5400b64d1fafdf0047aad6f38a35c93fc24f9cc3 Mon Sep 17 00:00:00 2001 From: Steven Wilson Date: Thu, 20 Jan 2022 20:52:46 +0000 Subject: add solution week 148 task 2 in perl --- challenge-148/steven-wilson/perl/ch-02.pl | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 challenge-148/steven-wilson/perl/ch-02.pl 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; + } + } + } + } +} + -- cgit