diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2020-02-08 08:34:38 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-02-08 08:34:38 +0000 |
| commit | 4b5c60af20136da48c7aea12475c195bf7b0a7ea (patch) | |
| tree | a2aec3f621752a49f5cd077467d8933ae61c50ae /challenge-046 | |
| parent | 0e4204d852c7bf58b693a56d686928f309fae22a (diff) | |
| parent | 5debe59c5dab2ad488365484b47599b73564b6a9 (diff) | |
| download | perlweeklychallenge-club-4b5c60af20136da48c7aea12475c195bf7b0a7ea.tar.gz perlweeklychallenge-club-4b5c60af20136da48c7aea12475c195bf7b0a7ea.tar.bz2 perlweeklychallenge-club-4b5c60af20136da48c7aea12475c195bf7b0a7ea.zip | |
Merge pull request #1224 from andemark/branch-for-challenge-046
Cosmetic changes
Diffstat (limited to 'challenge-046')
| -rw-r--r-- | challenge-046/mark-anderson/raku/ch-2.p6 | 27 |
1 files changed, 13 insertions, 14 deletions
diff --git a/challenge-046/mark-anderson/raku/ch-2.p6 b/challenge-046/mark-anderson/raku/ch-2.p6 index a81be20ee8..021a5265ce 100644 --- a/challenge-046/mark-anderson/raku/ch-2.p6 +++ b/challenge-046/mark-anderson/raku/ch-2.p6 @@ -1,24 +1,23 @@ #!/usr/bin/env perl6 -# @doors will be an array of 0s and 1s. -# A 0 will be an open door and a 1 will be a closed door. -# Employee 1 opens all doors. -my @doors[500] = 0 xx 500; +my $open := True; -for 2..500 -> $emp { - # @seq will hold the door numbers that - # the current employee will open/close. - my @seq = $emp, $emp*2...500; +# @doors is an array of Bools. +# The first employee opens every door. +my @doors = $open xx 500; - for @seq -> $door { +for 2 .. 500 -> $emp { + # The following sequence is the doors that + # the next employee opens or closes. + for $emp, $emp*2 ... 500 -> $door { # If the door is open then close it. # If the door is closed then open it. - # The "+^= 1" will toggle the number. - @doors[$door-1] +^= 1; + # The "?^= $open" will toggle the Bool. + @doors[$door-1] ?^= $open; } } -for 1..500 -> $door { - # Print the door number if it is open. - say $door unless @doors[$door-1]; +for 1 .. 500 -> $door { + # Print the door if it's open. + say $door if @doors[$door-1]; } |
