aboutsummaryrefslogtreecommitdiff
path: root/challenge-048/xkr47/raku/ch-1.p6
blob: e2346a65668c0ea10511cd98f692b13fea5a54f1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#!/usr/bin/env perl6

class Pwc048_1 is Array {
    method iterator {
        class :: does Iterator {
            has $.index is rw = 0;
            has $.array is required;
            method pull-one {
                my $val = $.array.AT-POS($.index++);
                $.index %= $.array.elems;
                $.array.splice($.index, 1);
                if ($.array.elems) {
                    $.index %= $.array.elems;
                    $val;
                } else {
                    IterationEnd;
                }
            }
        }.new(array => self)
    }
}

my $arr = Pwc048_1.new();
$arr.append(1...50);
say "Survivors, in order: ", $arr;