aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorE7-87-83 <fungcheokyin@gmail.com>2021-09-27 20:03:40 +0800
committerE7-87-83 <fungcheokyin@gmail.com>2021-09-27 20:03:40 +0800
commit3e0ef063102fd8d25be76ac2dc036a035d9d7f13 (patch)
tree5117916db4e5d920863871421a30f888df4f62ba
parenta293baa0c6e595d451fc0cd1e7342392038cd7f3 (diff)
downloadperlweeklychallenge-club-3e0ef063102fd8d25be76ac2dc036a035d9d7f13.tar.gz
perlweeklychallenge-club-3e0ef063102fd8d25be76ac2dc036a035d9d7f13.tar.bz2
perlweeklychallenge-club-3e0ef063102fd8d25be76ac2dc036a035d9d7f13.zip
TWC 132, Task 1 in 3 languages
-rw-r--r--challenge-132/cheok-yin-fung/java/MirrorDates.java28
-rw-r--r--challenge-132/cheok-yin-fung/julia/ch-1.jl34
-rw-r--r--challenge-132/cheok-yin-fung/perl/ch-1.pl42
3 files changed, 104 insertions, 0 deletions
diff --git a/challenge-132/cheok-yin-fung/java/MirrorDates.java b/challenge-132/cheok-yin-fung/java/MirrorDates.java
new file mode 100644
index 0000000000..238f259d83
--- /dev/null
+++ b/challenge-132/cheok-yin-fung/java/MirrorDates.java
@@ -0,0 +1,28 @@
+// The Weekly Challenge - 132
+// Task 1 Mirror Dates
+// Usage: java MirrorDates YYYY MM DD
+
+import java.time.LocalDate;
+import java.time.YearMonth;
+
+public class MirrorDates
+{
+ public static void main(String[] args)
+ {
+ int year = Integer.parseInt(args[0]);
+ int month = Integer.parseInt(args[1]);
+ int day = Integer.parseInt(args[2]);
+
+ mirror_dates(year, month, day);
+ }
+
+ public static void mirror_dates (int birth_year,int birth_month, int birth_day) {
+ LocalDate my_today = LocalDate.of(2021,9,22);
+ LocalDate birthday = LocalDate.of(birth_year, birth_month, birth_day);
+ long y1 = my_today.toEpochDay() - birthday.toEpochDay();
+ LocalDate d_senior = birthday.minusDays(y1);
+ LocalDate d_junior = my_today.plusDays(y1);
+ System.out.println(d_senior);
+ System.out.println(d_junior);
+ }
+}
diff --git a/challenge-132/cheok-yin-fung/julia/ch-1.jl b/challenge-132/cheok-yin-fung/julia/ch-1.jl
new file mode 100644
index 0000000000..24eb6f5aa3
--- /dev/null
+++ b/challenge-132/cheok-yin-fung/julia/ch-1.jl
@@ -0,0 +1,34 @@
+# The Weekly Challenge Week 132
+# Task 1 Mirror Dates
+# Usage: include("ch-1.jl")
+# mirror_dates(Date(YYYY,MM,DD))
+
+using Dates
+
+function mirror_dates(my_date_of_birth)
+ my_today = Date(2021,09,22)
+ y1 = Dates.values(my_today - my_date_of_birth)
+ d_senior = my_date_of_birth - Dates.Day(y1)
+ d_junior = my_today + Dates.Day(y1)
+ println(d_senior)
+ println(d_junior)
+end
+
+
+# julia> include("ch-1.jl")
+
+# #Example 1
+# julia> mirror_dates(Date(2021,09,18))
+# 2021-09-14
+# 2021-09-26
+
+# #Example 2
+# julia> mirror_dates(Date(1975,10,10))
+# 1929-10-27
+# 2067-09-05
+
+# #Example 3
+# julia> mirror_dates(Date(1967,02,14))
+# 1912-07-08
+# 2076-04-30
+
diff --git a/challenge-132/cheok-yin-fung/perl/ch-1.pl b/challenge-132/cheok-yin-fung/perl/ch-1.pl
new file mode 100644
index 0000000000..7bfe736e7d
--- /dev/null
+++ b/challenge-132/cheok-yin-fung/perl/ch-1.pl
@@ -0,0 +1,42 @@
+#!/usr/bin/perl
+# The Weekly Challenge 131
+# Task 1 Mirror Dates
+# Usage: ch-1.pl YYYY/MM/DD
+use v5.24.0;
+use warnings;
+use Time::Local qw'timelocal timegm_nocheck';
+use Test::More tests => 3;
+
+say mirror_str($ARGV[0]) if defined($ARGV[0]);
+
+sub mirror {
+ my @arr_today = (22, 8, 2021); # Wed Sep 22 2021
+ my $_today = timelocal(0, 0, 0, @arr_today);
+ my @arr_birth = ($_[2], $_[1]-1, $_[0]);
+ my $_birth = timelocal(0, 0, 0, @arr_birth);
+ my $sec_diff = $_today - $_birth;
+ my $y1 = int (($_today - $_birth)/86400);
+ my @d_senior = localtime timegm_nocheck 0, 0, 0, $arr_birth[0]-$y1, $arr_birth[1], $arr_birth[2];
+ my @d_junior = localtime timegm_nocheck 0, 0, 0, $arr_today[0]+$y1, $arr_today[1], $arr_today[2];
+ return [ [@d_senior], [@d_junior] ];
+}
+
+sub mirror_str {
+ my ($byear, $bmonth, $bday) = split /\//, $_[0];
+ $bmonth =~ s/^0//; # remove leading zeros
+ $bday =~ s/^0//; # remove leading zeros
+ my ($d_s, $d_j) = mirror($byear, $bmonth, $bday)->@*;
+
+ return
+ ($d_s->[5]+1900)."/"
+ .($d_s->[4]<=8 ? 0 : "").($d_s->[4]+1)."/"
+ .($d_s->[3]<10 ? 0 : "").($d_s->[3])
+ .", "
+ .($d_j->[5]+1900)."/"
+ .($d_j->[4]<=8 ? 0 : "").($d_j->[4]+1)."/"
+ .($d_j->[3]<10 ? 0 : "").($d_j->[3]);
+}
+
+ok mirror_str("2021/09/18") eq "2021/09/14, 2021/09/26", "Example 1";
+ok mirror_str("1975/10/10") eq "1929/10/27, 2067/09/05", "Example 2";
+ok mirror_str("1967/02/14") eq "1912/07/08, 2076/04/30", "Example 3";