aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-132/adam-russell/perl/ch-1.pl42
1 files changed, 42 insertions, 0 deletions
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