Japt, 8 bytes
ËùDV*EvV
Explanation
Ë ùDV*EvV
UmDE{DùDV*EvV} Ungolfed
Implicit: U = s, V = n
UmDE{ } Replace each char D and (0-)index E in U by this function:
EvV Take 1 if the index is divisible by V; 0 otherwise.
V* Multiply this by V. This gives V for every Vth index; 0 for others.
DùD Pad D with itself to this length. This gives V copies of D for every
Vth index; 1 copy of D for others.
Implicit: output last expression
I have to credit the idea to use ù to @Shaggy's answer here. I don't know that I ever would have thought of it myself...
ETHproductions
- 50.3k
- 6
- 96
- 241