aboutsummaryrefslogtreecommitdiff
path: root/challenge-063/mohammad-anwar/raku/ch-2.p6
blob: d14f542883aece61a2f3b6132a34edd31789a8df (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
26
27
#!/usr/bin/env perl6

use v6.d;

sub MAIN(Str :$string = 'xyxx', Bool :$verbose?) {
    rotate($string, $verbose).say;
}

sub rotate(Str $string where rx:i/^ <[xy]>+ $/, Bool $verbose?) {

    my $size = $string.chars;
    my $temp = $string;
    my $i = 1;
    my $c = 1;
    while $i <= $size {
        my $part_a = substr($temp, 0, $i);
        my $part_b = substr($temp, $i);
        $temp = ($part_b, $part_a).join;
        say "[$c]: [$temp]" if $verbose;
        last if $temp eq $string;

        $i++; $c++;
        $i = 1 if $i > $size;
    }

    return $c;
}