From 9614a6c9c1141c11c2b587633f83d19ea09d0c92 Mon Sep 17 00:00:00 2001 From: Michael Manring Date: Fri, 12 Aug 2022 12:15:49 +0700 Subject: pwc030 solution in dart --- challenge-030/pokgopun/dart/ch-1.dart | 10 ++++++++++ challenge-030/pokgopun/dart/ch-2.dart | 27 +++++++++++++++++++++++++++ challenge-030/pokgopun/go/ch-2.go | 16 ++++++++++++++-- 3 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 challenge-030/pokgopun/dart/ch-1.dart create mode 100644 challenge-030/pokgopun/dart/ch-2.dart diff --git a/challenge-030/pokgopun/dart/ch-1.dart b/challenge-030/pokgopun/dart/ch-1.dart new file mode 100644 index 0000000000..74965a6b86 --- /dev/null +++ b/challenge-030/pokgopun/dart/ch-1.dart @@ -0,0 +1,10 @@ +void main() { + int startY = 2019; + int endY = 2100; + for (var y = startY; y <= endY; y++) { + var t = DateTime(y, 12, 25); + if (t.weekday == DateTime.sunday) { + print(t); + } + } +} diff --git a/challenge-030/pokgopun/dart/ch-2.dart b/challenge-030/pokgopun/dart/ch-2.dart new file mode 100644 index 0000000000..3294d0fee6 --- /dev/null +++ b/challenge-030/pokgopun/dart/ch-2.dart @@ -0,0 +1,27 @@ +/* +Write a script to print all possible series of 3 positive numbers, where in each series at least one of the number is even and sum of the three numbers is always 12. For example, 3,4,5. +*/ +// (odd + odd) + odd => (even) + odd => odd, thus three numbers that sum to an even number cannot be all odd, no need to care about the even number +// Assume numbers in series can be duplicated and unordered as none of there contraints are mentioned + +void main() { + int n = 12; + for (int i = 0; i <= n; i++) { + //for (int j = 0; j <= n - i; j++) { + /* + for (int j = i; j <= n - i; j++) { + if (n - i - j < j) { + break; + } + */ + /**/ + for (int j = i + 1; j <= n - i; j++) { + if (n - i - j <= j) { + break; + } + /**/ + print( + "${i.toString().padLeft(2)}, ${j.toString().padLeft(2)}, ${(n - i - j).toString().padLeft(2)}"); + } + } +} diff --git a/challenge-030/pokgopun/go/ch-2.go b/challenge-030/pokgopun/go/ch-2.go index 8d5f287ccd..2a32bbc453 100644 --- a/challenge-030/pokgopun/go/ch-2.go +++ b/challenge-030/pokgopun/go/ch-2.go @@ -15,8 +15,20 @@ func main() { w := bufio.NewWriter(os.Stdout) n := 12 for i := 0; i <= n; i++ { - for j := 0; j <= 12-i; j++ { - fmt.Fprintf(w, "%d, %d, %d\n", i, j, 12-i-j) + //for j := 0; j <= n-i; j++ { + /* + for j := i; j <= n-i; j++ { + if n-i-j < j { + break + } + */ + /**/ + for j := i + 1; j <= n-i; j++ { + if n-i-j <= j { + break + } + /**/ + fmt.Fprintf(w, "%2d, %2d, %2d\n", i, j, n-i-j) } } w.Flush() -- cgit