Skip to main content
added 983 characters in body
Source Link
Jonathan Allan
  • 115.5k
  • 8
  • 68
  • 293

Python, 93 93 90  87 bytes

lambda*s,d=1,j='\n'.join:j(j([x[:i+1]for i in range(d<0,len(x))][::(d:=-d)])for x in s) 

An unnamed function that accepts the two strings and returns a string.

Note: Produces a trialling newline when the second input is length one.

Try it online


Previous, recursive function

-3 thanks to movatica.

f=lambda a,b,r='',i=2:a and f(a[:-1],b,r+a+'\n')or(len(b)>=i andb[i-1:]and f(a,b,r+b[:i]+'\n',i+1)or r) 

Starts with the empty string r, adds a and a newline and removes the last character from a until a is empty then adds the required portions of b and a newline by keeping a counter, i, which starts at 2 until the length of b is exceeded, then returns r. Has a trailing newline.

All tests are on ideoneTry it online

Python, 93 bytes

f=lambda a,b,r='',i=2:a and f(a[:-1],b,r+a+'\n')or(len(b)>=i and f(a,b,r+b[:i]+'\n',i+1)or r) 

Starts with the empty string r, adds a and a newline and removes the last character from a until a is empty then adds the required portions of b and a newline by keeping a counter, i, which starts at 2 until the length of b is exceeded, then returns r. Has a trailing newline.

All tests are on ideone

Python,  93 90  87 bytes

lambda*s,d=1,j='\n'.join:j(j([x[:i+1]for i in range(d<0,len(x))][::(d:=-d)])for x in s) 

An unnamed function that accepts the two strings and returns a string.

Note: Produces a trialling newline when the second input is length one.

Try it online


Previous, recursive function

-3 thanks to movatica.

f=lambda a,b,r='',i=2:a and f(a[:-1],b,r+a+'\n')or(b[i-1:]and f(a,b,r+b[:i]+'\n',i+1)or r) 

Starts with the empty string r, adds a and a newline and removes the last character from a until a is empty then adds the required portions of b and a newline by keeping a counter, i, which starts at 2 until the length of b is exceeded, then returns r. Has a trailing newline.

Try it online

Commonmark migration
Source Link

#Python, 93 bytes

Python, 93 bytes

f=lambda a,b,r='',i=2:a and f(a[:-1],b,r+a+'\n')or(len(b)>=i and f(a,b,r+b[:i]+'\n',i+1)or r) 

Starts with the empty string r, adds a and a newline and removes the last character from a until a is empty then adds the required portions of b and a newline by keeping a counter, i, which starts at 2 until the length of b is exceeded, then returns r. Has a trailing newline.

All tests are on ideone

#Python, 93 bytes

f=lambda a,b,r='',i=2:a and f(a[:-1],b,r+a+'\n')or(len(b)>=i and f(a,b,r+b[:i]+'\n',i+1)or r) 

Starts with the empty string r, adds a and a newline and removes the last character from a until a is empty then adds the required portions of b and a newline by keeping a counter, i, which starts at 2 until the length of b is exceeded, then returns r. Has a trailing newline.

All tests are on ideone

Python, 93 bytes

f=lambda a,b,r='',i=2:a and f(a[:-1],b,r+a+'\n')or(len(b)>=i and f(a,b,r+b[:i]+'\n',i+1)or r) 

Starts with the empty string r, adds a and a newline and removes the last character from a until a is empty then adds the required portions of b and a newline by keeping a counter, i, which starts at 2 until the length of b is exceeded, then returns r. Has a trailing newline.

All tests are on ideone

edited body
Source Link
Jonathan Allan
  • 115.5k
  • 8
  • 68
  • 293

#Python, 9193 bytes

f=lambda a,b,r='',i=2:a and f(a[:-1],b,r+a+'\n')or(len(b)>=i and f(a,b,r+b[:i]+'\n',i+1)or r) 

Starts with the empty string r, adds a and a newline and removes the last character from a until a is empty then adds the required portions of b and a newline by keeping a counter, i, which starts at 2 until the length of b is exceeded, then returns r. Has a trailing newline.

All tests are on ideone

#Python, 91 bytes

f=lambda a,b,r='',i=2:a and f(a[:-1],b,r+a+'\n')or(len(b)>=i and f(a,b,r+b[:i]+'\n',i+1)or r) 

Starts with the empty string r, adds a and a newline and removes the last character from a until a is empty then adds the required portions of b and a newline by keeping a counter, i, which starts at 2 until the length of b is exceeded, then returns r. Has a trailing newline.

All tests are on ideone

#Python, 93 bytes

f=lambda a,b,r='',i=2:a and f(a[:-1],b,r+a+'\n')or(len(b)>=i and f(a,b,r+b[:i]+'\n',i+1)or r) 

Starts with the empty string r, adds a and a newline and removes the last character from a until a is empty then adds the required portions of b and a newline by keeping a counter, i, which starts at 2 until the length of b is exceeded, then returns r. Has a trailing newline.

All tests are on ideone

added 73 characters in body
Source Link
Jonathan Allan
  • 115.5k
  • 8
  • 68
  • 293
Loading
added 73 characters in body
Source Link
Jonathan Allan
  • 115.5k
  • 8
  • 68
  • 293
Loading
Source Link
Jonathan Allan
  • 115.5k
  • 8
  • 68
  • 293
Loading