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

Commonmark migration
Source Link

#Pyth, 17

Pyth, 17

#Pyth, 17

Pyth, 17

added 1220 characters in body
Source Link
izzyg
  • 42.3k
  • 5
  • 79
  • 216

[Try it here.][1]

Explanation to follow. [1]: http://pyth.herokuappTry it here.com/

Explanation:

 Implicit:
 z = input() z is the string.
 Q = eval(input()) Q is the length.
< Q First Q characters of
 u UQ*zQ Reduce, with an initial value of z repeated Q times, 
 on the list range(len(Q)).
 Since the reduce function doesn't use the sequence variable H
 this function amounts to applying the inner code Q times to
 the initial value, where the working variable is G.
 ss Sum from list of tuples of strings, to tuple of strings,
 to string.
 C, Zip together
 cG\_ G split on underscores
 G with G.
 This inserts a character of G between every underscore
 separated group of G, which amounts to replacing the
 underscores with characters of G, after summation.

[Try it here.][1]

Explanation to follow. [1]: http://pyth.herokuapp.com/

Try it here.

Explanation:

 Implicit:
 z = input() z is the string.
 Q = eval(input()) Q is the length.
< Q First Q characters of
 u UQ*zQ Reduce, with an initial value of z repeated Q times, 
 on the list range(len(Q)).
 Since the reduce function doesn't use the sequence variable H
 this function amounts to applying the inner code Q times to
 the initial value, where the working variable is G.
 ss Sum from list of tuples of strings, to tuple of strings,
 to string.
 C, Zip together
 cG\_ G split on underscores
 G with G.
 This inserts a character of G between every underscore
 separated group of G, which amounts to replacing the
 underscores with characters of G, after summation.
Source Link
izzyg
  • 42.3k
  • 5
  • 79
  • 216

#Pyth, 17

<ussC,cG\_GUQ*zQQ

Input should be given with the string on the first line, and the length on the second, on STDIN. For example:

abc____
50

[Try it here.][1]

Explanation to follow. [1]: http://pyth.herokuapp.com/

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