2 added 6 characters in body
source | link

J, 3434 32 bytes

   (]+[*(1-~2*2|%~)*0=|)/@}.@(,~1+i_1}2+i.)

   ((]+[*(1-~2*2|%~)*0=|)/@}.@(,~1+i_1}2+i.)) every 1+i.20  NB. running with inputs 1..20
1 4 8 6 12 14 16 9 18 20 24 26 28 22 39 15 36 35 40 38

Will try to golf it a bit more and add some explanation later.

Try it online here.

J, 34 bytes

   (]+[*(1-~2*2|%~)*0=|)/@}.@(,~1+i.)

   ((]+[*(1-~2*2|%~)*0=|)/@}.@(,~1+i.)) every 1+i.20  NB. running with inputs 1..20
1 4 8 6 12 14 16 9 18 20 24 26 28 22 39 15 36 35 40 38

Will try to golf it a bit more and add some explanation later.

Try it online here.

J, 34 32 bytes

   (]+[*(1-~2*2|%~)*0=|)/@(_1}2+i.)

   ((]+[*(1-~2*2|%~)*0=|)/@(_1}2+i.)) every 1+i.20  NB. running with inputs 1..20
1 4 8 6 12 14 16 9 18 20 24 26 28 22 39 15 36 35 40 38

Will try to golf it a bit more and add some explanation later.

Try it online here.

1
source | link

J, 34 bytes

   (]+[*(1-~2*2|%~)*0=|)/@}.@(,~1+i.)

   ((]+[*(1-~2*2|%~)*0=|)/@}.@(,~1+i.)) every 1+i.20  NB. running with inputs 1..20
1 4 8 6 12 14 16 9 18 20 24 26 28 22 39 15 36 35 40 38

Will try to golf it a bit more and add some explanation later.

Try it online here.