OFFSET
1,2
COMMENTS
This is a permutation of the natural numbers.
LINKS
Paul Tek, Table of n, a(n) for n = 1..10000
EXAMPLE
Before step 3, the intermediate sequence is:
1,3,2,5,4,7,6,9,8,11,10,13,12,15,14,17,16,19,18,21,20,23,22,...
We separate the multiples of 3 from the other numbers:
3, 6,9, 12,15, 18,21, ,...
1, 2,5,4,7, 8,11,10,13, 14,17,16,19, 20,23,22,...
We move the multiples of 3 to the right:
3,6, 9,12, 15,18, ,...
1, 2,5,4,7, 8,11,10,13, 14,17,16,19, 20,23,22,...
Thus, we obtain this intermediate sequence after step 3:
1,2,5,4,7,3,6,8,11,10,13,9,12,14,17,16,19,15,18,20,23,22,...
PROG
(Perl)
my $max = 1000;
my @a = (1..$max);
sub move {
my $k = shift;
my @res = ();
my @prev = ();
foreach (@_) {
if ($_ % $k==0) {
push @res => @prev;
@prev = ($_);
} else {
push @res => $_;
}
}
return @res;
}
foreach my $k (2..$max) {
@a = move($k => @a);
}
print join(", " => @a), "\n";
CROSSREFS
KEYWORD
nonn
AUTHOR
Paul Tek, Mar 17 2013
STATUS
approved