| Bytes | Lang | Time | Link |
|---|---|---|---|
| 067 | Wolfram Language Mathematica | 231119T021854Z | 138 Aspe |
| 088 | Rust | 231119T021613Z | 138 Aspe |
| 125 | C++ | 230728T142727Z | Toby Spe |
| 009 | Japt | 230803T155036Z | Shaggy |
| 307 | Minecraft Function | 230802T203623Z | LostXOR |
| 052 | Zsh extendedglob | 230730T212609Z | roblogic |
| 041 | Bash+coreutils | 230729T045115Z | roblogic |
| 011 | J | 230726T013417Z | Bubbler |
| 043 | Perl 5 p | 230727T112912Z | Nahuel F |
| 048 | Scala | 230726T094038Z | t9dupuy |
| 037 | Ruby | 230725T144446Z | Jordan |
| 007 | Husk | 230725T160101Z | Dominic |
| 071 | Java JDK | 230726T093953Z | Fhuvi |
| 008 | 05AB1E | 230725T151323Z | Kevin Cr |
| 054 | C gcc | 230725T204426Z | mousetai |
| 059 | Zsh | 230726T042114Z | GammaFun |
| 036 | Desmos | 230726T040926Z | Aiden Ch |
| 043 | ><> Fish | 230726T004130Z | c-- |
| 006 | Vyxal | 230726T014101Z | emanresu |
| 031 | Arturo | 230726T004615Z | chunes |
| 012 | Charcoal | 230725T134259Z | Neil |
| 047 | Python | 230725T133610Z | Sanguine |
| 062 | C gcc | 230725T181245Z | Peter |
| 060 | Nim | 230725T174943Z | xigoi |
| 030 | Octave / MATLAB | 230725T161507Z | Luis Men |
| 046 | JavaScript ES6 | 230725T145529Z | Arnauld |
| 079 | Go | 230725T155239Z | bigyihsu |
| 006 | Dyalog APL | 230725T144551Z | RubenVer |
| 5511 | Nibbles | 230725T143558Z | Dominic |
| 055 | Nibbles | 230725T135711Z | xigoi |
| 068 | Excel | 230725T142257Z | Jos Wool |
| 031 | R | 230725T135718Z | Dominic |
| 005 | Jelly | 230725T131248Z | caird co |
| 575 | Vyxal | 230725T133108Z | lyxal |
| 048 | ><> Fish | 230725T133052Z | mousetai |
| 040 | Swift | 230725T132734Z | Bbrk24 |
Wolfram Language (Mathematica), 67 bytes
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()}
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;});}
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}
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
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.
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}
Takes input as f[listmax;k,j]. Pretty much a built-in-to-built-in translation of the J solution above.
Husk, 7 bytes
ṁ↑³Cḣ⁰+
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ḣ
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)
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(",");}
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)
Zsh, 59 bytes
for ((;i<$1&&i++<$3;))l+=({$i..$3..$[$1+$2]})
echo ${(on)l}
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.
><> (Fish), 43 bytes
Hover over any symbol to see what it does
In plaintext:
ii:i+0v1
)r}:r:<\v?)%{@:&@:$}:&;?
1+:nao^+>

Vyxal, 6 bytes
øḊ⁰ẎT›
(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]
$[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
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;}
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.
Octave / MATLAB, 30 bytes
@(k,j,m)find(mod(0:m-1,k+j)<k)
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):[]
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}
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)
+.`/+@$,_<@
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
|,_-@%-$~+@
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)
Indexes of elements of 0..(listmax-1) that are less than k after modulo-(k+j).
Jelly, 6 5 bytes
Ø+xṁM
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›
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
Hover over any symbol to see what it does
Unformatted version of code if above looks broken:
i:i+i0v/
v 1+>$:@$:@(?;:r:}$:}$r$@%)?
\1+:nao\
