diff options
| author | Michael Manring <michael@manring> | 2022-08-12 12:15:49 +0700 |
|---|---|---|
| committer | Michael Manring <michael@manring> | 2022-08-12 12:17:58 +0700 |
| commit | 9614a6c9c1141c11c2b587633f83d19ea09d0c92 (patch) | |
| tree | 50c0ec923500e596e070b1bb0a2307bc80d8f20f /challenge-030 | |
| parent | 13d05d5e4a50534c6593a5ea43b5f64e2c588500 (diff) | |
| download | perlweeklychallenge-club-9614a6c9c1141c11c2b587633f83d19ea09d0c92.tar.gz perlweeklychallenge-club-9614a6c9c1141c11c2b587633f83d19ea09d0c92.tar.bz2 perlweeklychallenge-club-9614a6c9c1141c11c2b587633f83d19ea09d0c92.zip | |
pwc030 solution in dart
Diffstat (limited to 'challenge-030')
| -rw-r--r-- | challenge-030/pokgopun/dart/ch-1.dart | 10 | ||||
| -rw-r--r-- | challenge-030/pokgopun/dart/ch-2.dart | 27 | ||||
| -rw-r--r-- | challenge-030/pokgopun/go/ch-2.go | 16 |
3 files changed, 51 insertions, 2 deletions
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() |
