diff options
| author | Mark Anderson <mark@frontrangerunner.com> | 2020-02-23 01:39:09 -0700 |
|---|---|---|
| committer | Mark Anderson <mark@frontrangerunner.com> | 2020-02-23 01:39:09 -0700 |
| commit | c67d39c53299707059b6e05c8bbdfacbba5b6545 (patch) | |
| tree | 0ba72454c9af4c6027aa8446eefdb2018ad098f5 | |
| parent | 351fdd66f07c2b93cdf8f8e145780367d6abd8fe (diff) | |
| download | perlweeklychallenge-club-c67d39c53299707059b6e05c8bbdfacbba5b6545.tar.gz perlweeklychallenge-club-c67d39c53299707059b6e05c8bbdfacbba5b6545.tar.bz2 perlweeklychallenge-club-c67d39c53299707059b6e05c8bbdfacbba5b6545.zip | |
Challenge 48
| -rw-r--r-- | challenge-048/mark-anderson/raku/ch-1.p6 | 21 | ||||
| -rw-r--r-- | challenge-048/mark-anderson/raku/ch-2.p6 | 5 |
2 files changed, 15 insertions, 11 deletions
diff --git a/challenge-048/mark-anderson/raku/ch-1.p6 b/challenge-048/mark-anderson/raku/ch-1.p6 index 02fc01baa4..db59eb4ba9 100644 --- a/challenge-048/mark-anderson/raku/ch-1.p6 +++ b/challenge-048/mark-anderson/raku/ch-1.p6 @@ -1,16 +1,15 @@ #!/usr/bin/env perl6 -my @living = 1 .. 50; -my @temp; +# I wish I would have thought of the "push @a, shift @a; shift @a;" solution. -while (@living > 1) { - loop (my $i = 0; $i < @living; $i += 2) { - push @temp, @living[$i]; - } - - shift @temp if @temp[*-1] == @living[*-1]; - @living = @temp; - @temp = []; +my @people = 1 .. 50; + +while @people > 1 { + my $last = @people[*-1]; + + @people = @people[@people.keys.grep(* %% 2)]; + + shift @people if @people[*-1] == $last; } -say @living.pop; +put @people; diff --git a/challenge-048/mark-anderson/raku/ch-2.p6 b/challenge-048/mark-anderson/raku/ch-2.p6 index d5cf44be9c..de498ab3c5 100644 --- a/challenge-048/mark-anderson/raku/ch-2.p6 +++ b/challenge-048/mark-anderson/raku/ch-2.p6 @@ -1,5 +1,7 @@ #!/usr/bin/env perl6 +# Just brute force. + my $mdy = sub ($self) { sprintf "%02d%02d%04d", .month, .day, .year given $self; } @@ -18,5 +20,8 @@ while ($dt.year < 3000) { printf "%02d/%02d/%04d\n", .month, .day, .year given $dt; } + #$dt += 1; # Formatting may be lost with this line + # so I'm doing the below hack for now. + # (The issue has been fixed in Rakudo Star RC-1) $dt = $dt.succ.clone(formatter => $mdy); } |
