START
ESCWYP
MUSIC
VIDEOS
------------------------------------------------- permut.perl6 -----------------------
{
my Int $num = 2;
try {
$num = +@*ARGS[0];
}
if $num <= 2 {
$num = 2;
}
my Int $index = 1;
my Int $old = 1;
my Int $minfree = 1;
my Bool @f;
my Int @c;
for 0..$num -> $i {
@c[$i] = -1;
@f[$i] = True;
}
say "init fertig ", $num;
sub freespot(Int $ind){
if $ind > 0 {
@f[$ind] = True;
if $ind < $minfree {
$minfree = $ind;
}
}
}
sub takespot(Int $ind){
if $ind > 0 {
@f[$ind] = False;
if $ind == $minfree {
for $minfree+1..$num -> $i {
if @f[$i] == True {
$minfree = $i;
return;
}
}
}
}
}
my Int $count = 1;
while $index > 0 {
my Int $start = @c[$index]+1;
if $start == 0 {
$start = $minfree;
}
for $start..$num -> $i {
if (@f[$i] == True) {
freespot(@c[$index]);
takespot($i);
@c[$index] = $i;
if $index < $num {
$index++;
} else {
freespot($i);
if $num > 100 {
for 1..10 -> $j {
print @c[$j]," ";
}
say "... ";
for $num-10..$num -> $j {
print @c[$j]," ";
}
} else {
for 1..$num -> $j {
print @c[$j]," ";
}
}
say " | ",$count;
$count++;
}
last;
}
}
if $index == $old {
freespot(@c[$index]);
@c[$index] = -1;
$index--;
}
$old = $index;
}
}
START
ESCWYP
MUSIC
VIDEOS