Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

Return to Answer

added 183 characters in body
Source Link
Giuseppe
  • 29.4k
  • 3
  • 33
  • 106

MATL, 10(削除) 10 (削除ここまで) 7 bytes

-3 bytes thanks to Luis Mendo!

ji1yqY"hY"tq:ghY"

Try it online! Try it online!

I'm probably not making the best use of implicitTakes input here, since I'm not using it at allas n and then S as a string/char array.

j % take(implicit input)
 as a string % stack: n
it  % takeduplicate
 input as number % stack: n n
1q  % pushdecrement
  % stack: n n-1
y:  % copyrange
 2nd item on % stack: (n) [1 2 ... n-1]
qg  % decrementconvert to logical (nonzero->1, zero->0)
Y" % runstack: lengthn decode[1 1 ... 1]
h % horizontal concatenate
 % stack: [n, 1, 1 ..., 1]
Y" % run-length decodedecoding, taking the string as first input and recycling 
 % the lengths [n 1 1 ... 1] as needed
 % (implicit output as a string)

MATL, 10 bytes

ji1yqY"hY"

Try it online!

I'm probably not making the best use of implicit input here, since I'm not using it at all.

j % take input as a string
i % take input as number
1 % push 1
y % copy 2nd item on stack (n)
q % decrement
Y" % run length decode
h % horizontal concatenate [n, 1, ..., 1]
Y" % runlength decode, recycling as needed
 % implicit output as a string

MATL, (削除) 10 (削除ここまで) 7 bytes

-3 bytes thanks to Luis Mendo!

tq:ghY"

Try it online!

Takes input as n and then S as a string/char array.

 % (implicit input)
  % stack: n
t  % duplicate
  % stack: n n
q  % decrement
  % stack: n n-1
:  % range
 % stack: n [1 2 ... n-1]
g  % convert to logical (nonzero->1, zero->0)
 % stack: n [1 1 ... 1]
h % horizontal concatenate
 % stack: [n 1 1 ... 1]
Y" % run-length decoding, taking the string as first input and recycling 
 % the lengths [n 1 1 ... 1] as needed
 % (implicit output as string)
added 282 characters in body
Source Link
Giuseppe
  • 29.4k
  • 3
  • 33
  • 106

MATL, 10 bytes

ji1yqY"hY"

Try it online!

I'm probably not making the best use of implicit input here, since I'm not using it at all.

j % take input as a string
i % take input as number
1 % push 1
y % copy 2nd item on stack (n)
q % decrement
Y" % run length decode
h % horizontal concatenate [n, 1, ..., 1]
Y" % run length decode, recycling as needed
 % implicit output as a string

MATL, 10 bytes

ji1yqY"hY"

Try it online!

I'm probably not making the best use of implicit input here, since I'm not using it at all.

MATL, 10 bytes

ji1yqY"hY"

Try it online!

I'm probably not making the best use of implicit input here, since I'm not using it at all.

j % take input as a string
i % take input as number
1 % push 1
y % copy 2nd item on stack (n)
q % decrement
Y" % run length decode
h % horizontal concatenate [n, 1, ..., 1]
Y" % run length decode, recycling as needed
 % implicit output as a string
Source Link
Giuseppe
  • 29.4k
  • 3
  • 33
  • 106

MATL, 10 bytes

ji1yqY"hY"

Try it online!

I'm probably not making the best use of implicit input here, since I'm not using it at all.

AltStyle によって変換されたページ (->オリジナル) /