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 170 characters in body
Source Link
FlipTack
  • 14.7k
  • 3
  • 56
  • 102

Python 3, 58 bytes

Working on golfing it down.

I know there are already other Python answers, but I thought I'd post this one too seeing as it scores pretty well compared to the others, despite being a full function and not a lambda.

Takes input as function parameters, and prints to STDOUT.

def f(s,n,i=0):
 for c in s:print(end=[c,c*n][i%n<1]);i+=1

Try it online!

For one byte less (57), I coded a lambda, however similar answers have already been posted by other users:

lambda s,n:''.join([c,c*n][i%n<1]for i,c in enumerate(s))

Python 3, 58 bytes

Working on golfing it down.

I know there are already other Python answers, but I thought I'd post this one too seeing as it scores pretty well compared to the others, despite being a full function and not a lambda.

Takes input as function parameters, and prints to STDOUT.

def f(s,n,i=0):
 for c in s:print(end=[c,c*n][i%n<1]);i+=1

Try it online!

Python 3, 58 bytes

Working on golfing it down.

I know there are already other Python answers, but I thought I'd post this one too seeing as it scores pretty well compared to the others, despite being a full function and not a lambda.

Takes input as function parameters, and prints to STDOUT.

def f(s,n,i=0):
 for c in s:print(end=[c,c*n][i%n<1]);i+=1

Try it online!

For one byte less (57), I coded a lambda, however similar answers have already been posted by other users:

lambda s,n:''.join([c,c*n][i%n<1]for i,c in enumerate(s))
Rollback to Revision 2
Source Link
FlipTack
  • 14.7k
  • 3
  • 56
  • 102

Python 3, 5758 bytes

The non recursive approach!Working on golfing it down.

I know there are already other Python answers, but I thought I'd post this one too seeing as it scores pretty well compared to the others, despite not being recursivea full function and not a lambda.

Takes input as function parameters, and prints to STDOUT.

lambdadef f(s,n:''.join([c,c*n][i%n<1]fori=0):
 i,for c in enumerate(s):print(end=[c,c*n][i%n<1]);i+=1

Try it online! Try it online!

Python 3, 57 bytes

The non recursive approach!

I know there are already other Python answers, but I thought I'd post this one too seeing as it scores pretty well compared to the others, despite not being recursive.

lambda s,n:''.join([c,c*n][i%n<1]for i,c in enumerate(s))

Try it online!

Python 3, 58 bytes

Working on golfing it down.

I know there are already other Python answers, but I thought I'd post this one too seeing as it scores pretty well compared to the others, despite being a full function and not a lambda.

Takes input as function parameters, and prints to STDOUT.

def f(s,n,i=0):
 for c in s:print(end=[c,c*n][i%n<1]);i+=1

Try it online!

deleted 266 characters in body
Source Link
FlipTack
  • 14.7k
  • 3
  • 56
  • 102

Python 3, 5857 bytes

Working on golfing it down.The non recursive approach!

I know there are already other Python answers, but I thought I'd post this one too seeing as it scores pretty well compared to the others, despite being a full function and not a lambda.

Takes input as function parameters, and prints to STDOUTbeing recursive.

deflambda f(s,n,i=0):
 for''.join([c,c*n][i%n<1]for i,c in s:printenumerate(end=[c,c*n][i%n<1]s);i+=1)

Try it online!

My best attempt at a recursive lambda ended up at 57 bytes (however, others have already posted similar, shorter, lambdas)Try it online!

f=lambda s,n,i=0:s[i:]and[1,n][i%n<1]*s[i]+f(s,n,i+1)or''

Python 3, 58 bytes

Working on golfing it down.

I know there are already other Python answers, but I thought I'd post this one too seeing as it scores pretty well compared to the others, despite being a full function and not a lambda.

Takes input as function parameters, and prints to STDOUT.

def f(s,n,i=0):
 for c in s:print(end=[c,c*n][i%n<1]);i+=1

Try it online!

My best attempt at a recursive lambda ended up at 57 bytes (however, others have already posted similar, shorter, lambdas)

f=lambda s,n,i=0:s[i:]and[1,n][i%n<1]*s[i]+f(s,n,i+1)or''

Python 3, 57 bytes

The non recursive approach!

I know there are already other Python answers, but I thought I'd post this one too seeing as it scores pretty well compared to the others, despite not being recursive.

lambda s,n:''.join([c,c*n][i%n<1]for i,c in enumerate(s))

Try it online!

added 131 characters in body
Source Link
FlipTack
  • 14.7k
  • 3
  • 56
  • 102
Loading
deleted 1 character in body
Source Link
FlipTack
  • 14.7k
  • 3
  • 56
  • 102
Loading
Source Link
FlipTack
  • 14.7k
  • 3
  • 56
  • 102
Loading

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