diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2020-02-18 11:08:49 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-02-18 11:08:49 +0000 |
| commit | 1858008d355337e56bff2fba990a7f6ccb836409 (patch) | |
| tree | e78ae199abd0f771ac3acf5cfe2aab80e70aa1ef /challenge-048 | |
| parent | 31beb31618ad94e42890e8f2c88a853095889e72 (diff) | |
| parent | a119d8cf4604eaf74a93ce1d94b03de4edf570ab (diff) | |
| download | perlweeklychallenge-club-1858008d355337e56bff2fba990a7f6ccb836409.tar.gz perlweeklychallenge-club-1858008d355337e56bff2fba990a7f6ccb836409.tar.bz2 perlweeklychallenge-club-1858008d355337e56bff2fba990a7f6ccb836409.zip | |
Merge pull request #1271 from holli-holzer/master
Corrections
Diffstat (limited to 'challenge-048')
| -rw-r--r-- | challenge-048/markus-holzer/raku/ch-1.p6 | 12 | ||||
| -rw-r--r-- | challenge-048/markus-holzer/raku/ch-2.p6 | 73 |
2 files changed, 63 insertions, 22 deletions
diff --git a/challenge-048/markus-holzer/raku/ch-1.p6 b/challenge-048/markus-holzer/raku/ch-1.p6 index 27637602ca..7512a5c3e8 100644 --- a/challenge-048/markus-holzer/raku/ch-1.p6 +++ b/challenge-048/markus-holzer/raku/ch-1.p6 @@ -1,10 +1,16 @@ -my @circle = (1..500); +# perfect example of overcomplicated thinking +# the shift two, push one method is probably nicer, +# if not faster + +my @circle = 1..500; +my $offset = 0; while @circle.elems > 1 { - my $offset = @circle.elems %% 2 ?? 0 !! 1; + my $pivot-man = @circle[ *-2 ]; @circle = @circle[ $offset, { $_ + 2 } ... * ]; + $offset = @circle[ *-1 ] == $pivot-man ?? 0 !! 1; } -# Survivor: No. 245 +# Survivor: No. 489 say "Survivor: No.", @circle.first; diff --git a/challenge-048/markus-holzer/raku/ch-2.p6 b/challenge-048/markus-holzer/raku/ch-2.p6 index 79932e9cce..fb6daa6f93 100644 --- a/challenge-048/markus-holzer/raku/ch-2.p6 +++ b/challenge-048/markus-holzer/raku/ch-2.p6 @@ -1,19 +1,54 @@ -my $formatter = sub { sprintf '%02d%02d%04d', .month, .day, .year given $^date }; - -.say for (2000..2099) - .grep({ - 0 < $^year.substr(2,2).flip < 12 }) - .map({ - Date.new($^year, |$year.flip.comb(2), :$formatter ) }); - -# 10022001 -# 01022010 -# 11022011 -# 02022020 -# 03022030 -# 04022040 -# 05022050 -# 06022060 -# 07022070 -# 08022080 -# 09022090
\ No newline at end of file +my $formatter = sub { sprintf '%02d%02d%04d', .month, .day, .year given $^date };
+
+#.say for (1300..1399)
+.say for (2000..2999)
+ # filter out most of the impossible years
+ .grep({
+ 0 < .substr(2,2).flip < 13 &&
+ 0 < .substr(0,2).flip < 32 })
+ # Try making a date, this fails sometimes, eg for the year 1311 -> 11311311
+ # which is not a valid date. That doesn't happen for 2000 to 29999 though.
+ .map({
+ try Date.new($_, |.flip.comb(2), :$formatter ) })
+ # So we need to filter these out
+ .grep({
+ .so });
+
+# 36 solutions in total
+# 10022001
+# 01022010
+# 11022011
+# 02022020
+# 12022021
+# 03022030
+# 04022040
+# 05022050
+# 06022060
+# 07022070
+# 08022080
+# 09022090
+# 10122101
+# 01122110
+# 11122111
+# 02122120
+# 12122121
+# 03122130
+# 04122140
+# 05122150
+# 06122160
+# 07122170
+# 08122180
+# 09122190
+# 10222201
+# 01222210
+# 11222211
+# 02222220
+# 12222221
+# 03222230
+# 04222240
+# 05222250
+# 06222260
+# 07222270
+# 08222280
+# 09222290
+
|
