From 9a7352c378bbea7491d0b1f4ee9973ab2670a47a Mon Sep 17 00:00:00 2001 From: Adam Russell Date: Sun, 3 Oct 2021 15:12:06 -0400 Subject: solution to challenge 132 --- challenge-132/adam-russell/perl/ch-1.pl | 42 +++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 challenge-132/adam-russell/perl/ch-1.pl diff --git a/challenge-132/adam-russell/perl/ch-1.pl b/challenge-132/adam-russell/perl/ch-1.pl new file mode 100644 index 0000000000..5cf04756a2 --- /dev/null +++ b/challenge-132/adam-russell/perl/ch-1.pl @@ -0,0 +1,42 @@ +use strict; +use warnings; +## +# You are given a date (yyyy/mm/dd). +# Assuming, the given date is your date of birth. +# Write a script to find the mirror dates of the given date. +## +use Time::Piece; +use Time::Seconds; + +sub mirror_dates{ + my($date_string, $start_date_string) = @_; + my $date = Time::Piece->strptime($date_string, q[%Y/%m/%e]); + my $today; + if($start_date_string){ + $today = Time::Piece->strptime($start_date_string, q[%Y/%m/%e]); + } + else{ + $today = localtime; + } + my $age = $today - $date; + my $past = $date - $age; + my $future = $today + $age; + return $past->strftime(q[%Y/%m/%d]), $future->strftime(q[%Y/%m/%d]); +} + +MAIN:{ + my($past, $future); + ($past, $future) = mirror_dates("2021/09/18", "2021/09/22"); + print "$past, $future\n"; + ($past, $future) = mirror_dates("1975/10/10", "2021/09/22"); + print "$past, $future\n"; + ($past, $future) = mirror_dates("1967/02/14", "2021/09/22"); + print "$past, $future\n"; + + ($past, $future) = mirror_dates("2021/09/18"); + print "$past, $future\n"; + ($past, $future) = mirror_dates("1975/10/10"); + print "$past, $future\n"; + ($past, $future) = mirror_dates("1967/02/14"); + print "$past, $future\n"; +} \ No newline at end of file -- cgit