diff options
Diffstat (limited to 'challenge-276/perlboy1967/perl/ch1.pl')
| -rwxr-xr-x | challenge-276/perlboy1967/perl/ch1.pl | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/challenge-276/perlboy1967/perl/ch1.pl b/challenge-276/perlboy1967/perl/ch1.pl new file mode 100755 index 0000000000..9ff82133f6 --- /dev/null +++ b/challenge-276/perlboy1967/perl/ch1.pl @@ -0,0 +1,39 @@ +#!/bin/perl + +=pod + +The Weekly Challenge - 276 +- https://theweeklychallenge.org/blog/perl-weekly-challenge-276 + +Author: Niels 'PerlBoy' van Dijke + +Task 1: Complete Day +Submitted by: Mohammad Sajid Anwar + +You are given an array of integers, @hours. + +Write a script to return the number of pairs that forms a complete day. + +|| A complete day is defined as a time duration that is an exact multiple +|| of 24 hours. + +=cut + +use v5.32; +use feature qw(signatures); +use common::sense; + +use Test2::V0 qw(-no_srand); +use DDP; + +use Algorithm::Combinatorics qw(combinations); + +sub completeDay (@hours) { + grep { $_ % 24 == 0 } map { $$_[0] + $$_[1] } combinations(\@hours,2); +} + +is(completeDay(12,12,30,24,24),2); +is(completeDay(72,48,24,5),3); +is(completeDay(12,18,24),0); + +done_testing; |
