g | x | w | all
Bytes Lang Time Link
067Wolfram Language Mathematica231119T021854Z138 Aspe
088Rust231119T021613Z138 Aspe
125C++230728T142727ZToby Spe
009Japt230803T155036ZShaggy
307Minecraft Function230802T203623ZLostXOR
052Zsh extendedglob230730T212609Zroblogic
041Bash+coreutils230729T045115Zroblogic
011J230726T013417ZBubbler
043Perl 5 p230727T112912ZNahuel F
048Scala230726T094038Zt9dupuy
037Ruby230725T144446ZJordan
007Husk230725T160101ZDominic
071Java JDK230726T093953ZFhuvi
00805AB1E230725T151323ZKevin Cr
054C gcc230725T204426Zmousetai
059Zsh230726T042114ZGammaFun
036Desmos230726T040926ZAiden Ch
043><> Fish230726T004130Zc--
006Vyxal230726T014101Zemanresu
031Arturo230726T004615Zchunes
012Charcoal230725T134259ZNeil
047Python230725T133610ZSanguine
062C gcc230725T181245ZPeter
060Nim230725T174943Zxigoi
030Octave / MATLAB230725T161507ZLuis Men
046JavaScript ES6230725T145529ZArnauld
079Go230725T155239Zbigyihsu
006Dyalog APL230725T144551ZRubenVer
5511Nibbles230725T143558ZDominic
055Nibbles230725T135711Zxigoi
068Excel230725T142257ZJos Wool
031R230725T135718ZDominic
005Jelly230725T131248Zcaird co
575Vyxal230725T133108Zlyxal
048><> Fish230725T133052Zmousetai
040Swift230725T132734ZBbrk24

Wolfram Language (Mathematica), 67 bytes

Try it online!

f[k_,j_,l_]:=Table[If[Mod[x,k+j]<k,x+1],{x,0,l-1}]~DeleteCases~Null

Rust, 88 bytes

|k:usize,j:usize,l:usize|->Vec<usize>{(0..l).filter(|x|x%(k+j)<k).map(|x|x+1).collect()}

Attempt This Online!

C++, 125 bytes

It's never going to be a code-golf winner, but with C++23 nearing standardisation, it's interesting to showcase what the new std::views classes offer us:

#include<ranges>
auto f(int a,int b,int n){using namespace std::views;return
iota(1,n+1)|chunk(a+b)|transform(take(a))|join;}

This simply divides the input range into chunks of size a+b, taking the first a elements from each chunk, and then reassembles the chunks back into a single range.

Self-test of the question's examples:

#include <algorithm>
#include <iterator>
#include <vector>
auto k_skip_j(int a,int b,int n)
{
#ifdef __cpp_lib_ranges_to_container
    return f(a,b,n) | std::ranges::to<std::vector>();
#else
    auto r = f(a,b,n);
    auto result = std::vector<int>();
    std::ranges::copy(r, std::back_inserter(result));
    return result;
#endif
}

#include <gtest/gtest.h>

TEST(k_skip_j, three_two_six) {
    auto result = k_skip_j(3, 2, 6);
    auto expected = std::vector{1,2,3,6};
    EXPECT_EQ(result, expected);
}

TEST(k_skip_j, one_one_twelve) {
    auto result = k_skip_j(1, 1, 12);
    auto expected = std::vector{1,3,5,7,9,11};
    EXPECT_EQ(result, expected);
}

TEST(k_skip_j, two_three_twenty) {
    auto result = k_skip_j(2, 3, 20);
    auto expected = std::vector{1,2,6,7,11,12,16,17};
    EXPECT_EQ(result, expected);
}

For comparison, the C++20 version weighs 140 bytes:

#include<ranges>
auto f(int a,int b,int n){return
std::views::iota(1,n+1)|std::views::filter([n=-1,a,b](auto)mutable{return(++n%=a+b)<a;});}

Japt, 9 bytes

0-based output. Add 1 byte for 1-based output.

o kgVcÈÇY

Try it

Minecraft Function, 307 bytes

scoreboard players operation r d = c d
execute if score c d matches 0 run scoreboard players operation j d += k d
scoreboard players operation r d %= j d
scoreboard players add c d 1
execute if score r d < k d run tellraw @a {"score":{"name":"c","objective":"d"}}
execute if score c d < m d run function a:b

Must be run as a function named b in a data pack named a. The function increments c in a loop while c < m. Each iteration, if c % (k + j) < k, it prints c.

k, j, and listmax are input as scoreboard players k, j, and m for objective d. To set up the inputs, run the commands:

/scoreboard objectives add d dummy
/scoreboard players set k d <value>
/scoreboard players set j d <value>
/scoreboard players set m d <value>

The above commands could be considered part of the program, but since they are necessary to provide input they have not been counted.

Zsh --extendedglob, 52 bytes

for i ({1..$3})<<<${$(((i-1)%($1+$2)<$1?i:0))/(#s)0}

Try it online!

Using the modulo technique, but still not understanding how it works!

Bash+coreutils, 41 bytes

seq 1 $3|xargs -n$[$1+$2]|cut -d\  -f1-$1

Try it online!

59 bytes: c=$3;for((i=1;i<=c;i+=$1+$2)){ seq $i $[k=i+$1-1,k<c?k:c];}

J, 12 11 bytes

>:@I.@$1-I.

Attempt This Online!

Takes input as listmax f (k, j).

-1 byte thanks to ngn by taking k,j instead of j,k.

>:@I.@$1-I.
         I.  k copies of 0 and j copies of 1
       1-    change 0 to 1 and 1 to 0
      $      take listmax cyclically
   I.@       convert each occurrence of 1 to its index (0-based)
>:@          add 1

K (ngn/k), 10 bytes

{1+&x#~&y}

Try it online!

Takes input as f[listmax;k,j]. Pretty much a built-in-to-built-in translation of the J solution above.

Perl 5 (-p), 43 bytes

/ \d+/;$_=join$",grep{$i++%($`+$&)<$`}1..$'

Try it online!

Scala, 48 bytes

(k,j,l)=>for(i<-0 until l if i%(k+j)<k)yield i+1

Try it online!

Same modulo trick.

Ruby, 41 37 bytes

-4 bytes thanks to Dingus

->k,j,m{m.times{p _1+1if _1%(k+j)<k}}

Attempt This Online!

Husk, 7 bytes

ṁ↑³Cḣ⁰+

Try it online!

Same approach as my Nibbles answer. Takes arguments in order k,listmax,j.

ṁ↑³Cḣ⁰+
   C     # cut
    ḣ⁰   #  the range from 1..middle argument
         # into sublists of length
      +  #  sum of other arguments
ṁ        # then map over this list-of-lists
 ↑       #  taking
  ³      #  first-arg elements from each
ṁ        # and flatten the result

Alternative approach, also 7 bytes

f¢Ṙ⁰ḋ2ḣ

Try it online!

Takes arguments in order [k,j],listmax.

f¢Ṙ⁰ḋ2ḣ
  Ṙ      # repeat
    ḋ2   #  the binary digits of 2 (so: [1,0])
   ⁰     #  each by number given in arg 1
 ¢       # and repeat this list infinitely;
f        # now use this to filter elements of
      ḣ  #  1..arg 2

Java (JDK), 71 bytes

Output is an IntStream if that's acceptable.

(k,j,l)->java.util.stream.IntStream.range(1,l+1).filter(i->--i%(k+j)<k)

Try it online!


If that's not acceptable, then here's a more classic solution with an array as output (81 bytes) :

(k,j,l)->{var r="";for(int i=0;i<l;)r+=i++%(k+j)<k?i+",":"";return r.split(",");}

Try it online!

05AB1E, 8 bytes

LI¹и£ιн˜

Inputs as \$max, [k,j]\$.

Try it online or verify all test cases.

Here an alternative 8 bytes approach:

LDIÅΓ¹∍Ï

Try it online or verify all test cases.

Explanation:

L         # Push a list in the range [1, first (implicit) input `max`]
 I        # Push the second input-pair [`k`,`j`]
  ¹и      # Repeat it the first input amount of times as list
    £     # Split the first list into parts of those sizes,
          # containing empty trailing lists if it's out of bounds
     ι    # Uninterleave this list of lists into two parts
      н   # Pop and only keep the first part
       ˜  # Flatten it
          # (after which the result is output implicitly)
L         # Push a list in the range [1, first (implicit) input `max`]
 D        # Duplicate this list
  I       # Push the second input-pair [`k`,`j`]
   ÅΓ     # Pop the top two lists, and run-length decode it,
          # resulting in `k` amount of 1s followed by `j` amount of 2s
     ¹∍   # Shorten/extend it to a length equal to the first input `max`
       Ï  # Only leave the values in the ranged list at the truthy positions
          # (only 1 is truthy in 05AB1E)
          # (after which the result is output implicitly)

C (gcc), 54 bytes

i;f(a,b,m){for(i=0;i<m;i++%(a+b)<a&&printf("%d ",i));}

Try it online!

Zsh, 59 bytes

for ((;i<$1&&i++<$3;))l+=({$i..$3..$[$1+$2]})
echo ${(on)l}

Attempt This Online!

I really think there's some gains to be had from another method, but that method eludes me.

This loops, iterating the starting point of a brace expansion {$start..$end..$skip} until it reaches the first or third argument (j or listmax). Each brace expansion is appended to the list l. Finally, the (on) flag sorts the list numerically.

-8 bytes if the output does not need to be sorted. (<<<$l)

Desmos, 36 bytes

l=[1...m]
f(k,j,m)=l[mod(l-1,k+j)<k]

Uses the same modulo trick that some other answers here have done to filter for the appropriate numbers.

Try It On Desmos!

Try It On Desmos! - Prettified

><> (Fish), 43 bytes

ii:i+0v1
)r}:r:<\v?)%{@:&@:$}:&;?
1+:nao^+>

Hover over any symbol to see what it does

In plaintext:

ii:i+0v1
)r}:r:<\v?)%{@:&@:$}:&;?
1+:nao^+>

Try it

control flow

Vyxal, 6 bytes

øḊ⁰ẎT›

Try it Online!

(or 5.5 bytes if you're using vyncode)

øḊ     # Perform dyadic run length decoding - creates a list of
       # [[list_max] * k, [0] * j]
  ⁰Ẏ   # Slice to length list_max
    T› # Truthy indices + 1

Arturo, 31 bytes

$[k j l]->select l=>[k>%&-1k+j]

Try it!

$[k j l]->          ; a function taking three args
    select l=>[     ; select elts in [1..l], assign current elt to &
        k>          ; is k greater than...
        %&-1        ; current elt minus one modulo...
        k+j         ; k plus j?
    ]               ; end select

Charcoal, 15 12 bytes

I⊕⌕A…⭆²⭆NιN0

Try it online! Link is to verbose version of code. Would have been 1 fewer byte with 0-indexing. Explanation: Now a port of @lyxal's Vyxal answer.

      ²         Literal integer `2`
     ⭆          Map over implicit range and join
        N       Next input
       ⭆        Map over implicit range and join
         ι      Outer value
    …           Cyclically extended to length
          N     Third input as a number
  ⌕A            Find all occurrences of
           0    Literal string `0`
 ⊕              Vectorised increment
I               Cast to string
                Implicitly print

Python, 53 48 47 bytes

lambda k,j,l:[x+1for x in range(l)if x%(k+j)<k]

Attempt This Online!

-5 by Lynn

-1 by Ethan C

C (gcc), 62 bytes

i,j;f(a,b,m){for(i=j=0;m/++i;j-->b&&printf("%d ",i))j=j?:a+b;}

Try It Online!

Ungolfed:

i,j;
f(a,b,m)
{
    for(i=j=0;m/++i;j-->b&&printf("%d ",i))
        j=j?:a+b;
}

i is the counter, and the loop ends when it's greater than m, which is the maximum value. j is initialized to 0, but is reinitialized to a+b before it is read from. It's decremented once for each iteration of the loop, and i is only printed when j is greater than b, so only the first a+b - b = a values are printed. When j reaches 0 after b more iterations, it's set to a+b again.

Nim, 60 bytes

proc r(k,j,m:int)=
 for n in 1..m:
  if(n-1)%%(j+k)<k:echo n

Attempt This Online!

Octave / MATLAB, 30 bytes

@(k,j,m)find(mod(0:m-1,k+j)<k)

Try it online!

Explanation

@(k,j,m)find(mod(0:m-1,k+j)<k)

@(k,j,m)                         % Define anonymous function of k, j, m
                 0:m-1           % Range [0 1 2 ... m-1]
             mod(     ,k+j)      % Modulo k+j (element-wise)
                           <k    % Less than k? (element-wise)
        find(                )   % (1-based) Indices of true entries

JavaScript (ES6), 46 bytes

Expects (k)(j)(listmax).

k=>j=>g=m=>m--?m%(k+j)<k?[...g(m),m+1]:g(m):[]

Try it online!

Commented

k =>                 // 1st function taking k
j =>                 // 2nd function taking j
g = m =>             // 3rd recursive function taking m
m-- ?                // if m is not 0 (decrement it afterwards):
  m % (k + j) < k ?  //   if m modulo (k + j) is less than k:
    [...g(m), m + 1] //     append the result of a recursive call,
                     //     followed by m + 1
  :                  //   else:
    g(m)             //     just do a recursive call and append nothing
:                    // else:
  []                 //   stop

Go, 79 bytes

func(k,j,n int)(o[]int){for i:=0;i<n;i++{if i%(k+j)<k{o=append(o,i+1)}}
return}

Attempt This Online!

Port of @SanguineL's answer.

Dyalog APL, 6 bytes

Thanks @Lynn for -6

⍸1=⍴∘⍸­⁡​‎‎⁡⁠⁡‏‏​⁡⁠⁡‌⁢​‎‎⁡⁠⁢⁢‏‏​⁡⁠⁡‌⁣​‎‎⁡⁠⁤‏⁠‏​⁡⁠⁡‌⁤​‎‎⁡⁠⁢‏⁠‎⁡⁠⁣‏‏​⁡⁠⁡‌­
⍸       # ‎⁡At what indices
     ⍸  # ‎⁢is the list of k 1's and j 2's
   ⍴    # ‎⁣cycled to length listmax
 1=     # ‎⁤equal to 1?
💎

Created with the help of Luminespire.

left argument listmax, right argument pair of k and j

Nibbles, 5.5 bytes (11 nibbles)

+.`/+@$,_<@

Attempt This Online!

Different approach to xigoi's Nibbles answer, but still 5.5 bytes...

+.`/+@$,_<@
  `/         # make chunks of size
    +@$      #  sum of first two arguments
       ,_    # from the range 1..third argument
 .           # then, for each chunk
         <@  #  take first arg elements
+            # and flatten the list of chunks

Nibbles, 5.5 bytes

|,_-@%-$~+@

Attempt This Online!

Find all numbers \$n\$ from \$1\$ to \$m\$ such that \$(n-1) \bmod (k+j) < k\$.

|,_-@%-$~+@
|           filter
 ,           range
  _           max number
            by the following value being strictly positive:
   -         subtract
    @         k (number of elements to keep)
     %        modulo
      - ~      subtract 1 from
       $        the element
         +     add
          @     k (number of elements to keep)
                j (number of elements to drop)

Excel, 68 bytes

=LET(a,TOROW(SEQUENCE(,A1)+(A1+B1)*SEQUENCE(C1,,0)),FILTER(a,a<=C1))

k, j and listmax in A1, B1 and C1 respectively. Outputs a horizontal array.

R, 32 31 bytes

\(k,j,m)which((1:m-1)%%(k+j)<k)

Attempt This Online!

Indexes of elements of 0..(listmax-1) that are less than k after modulo-(k+j).

Jelly, 6 5 bytes

Ø+xṁM

Try it online!

Takes input as [k, j] on the left, and listmax on the right.

-1 byte thanks to Lynn pushing me to save a byte!

How it works

Ø+xṁM - Main link. Takes [k, j] on the left, listmax on the right
Ø+    - [1, -1]
  x   - Repeat 1 k times and -1 j times
   ṁ  - Mold this list of length k+j to length listmax
    M - Maximal indices, i.e. indices of the 1s

Vyxal, 46 bitsv2, 5.75 bytes

₀fẋfẎT›

Try it Online!

Vyncode!!!

Explained

₀fẋfẎT›­⁡​‎‎⁡⁠⁡‏⁠‎⁡⁠⁢‏⁠‎⁡⁠⁣‏‏​⁡⁠⁡‌⁢​‎‎⁡⁠⁤‏‏​⁡⁠⁡‌⁣​‎‎⁡⁠⁢⁡‏‏​⁡⁠⁡‌⁤​‎‎⁡⁠⁢⁢‏⁠‎⁡⁠⁢⁣‏‏​⁡⁠⁡‌­
₀fẋ      # ‎⁡A list of [[1] * k, [0] * j]
   f     # ‎⁢flattened
    Ẏ    # ‎⁣with the first listmax items taken, wrapping if needed
     T›  # ‎⁤truthy indices + 1
💎

Created with the help of Luminespire.

><> (Fish), 48 bytes

i:i+i0v/
v   1+>$:@$:@(?;:r:}$:}$r$@%)?
\1+:nao\

Hover over any symbol to see what it does

Try it

Unformatted version of code if above looks broken:

i:i+i0v/
v   1+>$:@$:@(?;:r:}$:}$r$@%)?
\1+:nao\

enter image description here

Swift, 40 bytes

{k,j,l in(1...l).filter{($0-1)%(k+j)<k}}

Try it on SwiftFiddle!