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

#Python 2, 182 bytes#

Python 2, 182 bytes

def f(s):
 M=max(map(len,s));p=' '*M;L=[p]+s+M*[p];r='';k=0
 while k/M<len(s)*3+M:
 i=k%M;w=k/M-i+1;r+=(L[(w/3+1)*(w%3==1)]+p)[i];k+=1
 if i==M-1:r=r.rstrip()+'\n'
 return r.strip()

A bit long, but on the positive side, it returns a string with no trailing white space on each line, and no trailing white space or returns at the end; constraints that some other entries don't obey.

A list of words is passed into the function; some 'blanks' are aded to this list and then the algorithm maps a row,column pair to a wordNumber, characterNumber in the expanded list. (This is a bit of the inverse of the usual strategy seen in other solutions).

If we allow trailing white space on all lines except the last, we can do a bit better (163 bytes):

def f(s):
 M=max(map(len,s));p=' '*M;L=[p]+s+M*[p];r='';k=0
 while k/M<len(s)*3+M:i=k%M;w=k/M-i+1;r+=(L[(w/3+1)*(w%3==1)]+p)[i]+'\n'*(i==M-1);k+=1
 return r.strip()

#Python 2, 182 bytes#

def f(s):
 M=max(map(len,s));p=' '*M;L=[p]+s+M*[p];r='';k=0
 while k/M<len(s)*3+M:
 i=k%M;w=k/M-i+1;r+=(L[(w/3+1)*(w%3==1)]+p)[i];k+=1
 if i==M-1:r=r.rstrip()+'\n'
 return r.strip()

A bit long, but on the positive side, it returns a string with no trailing white space on each line, and no trailing white space or returns at the end; constraints that some other entries don't obey.

A list of words is passed into the function; some 'blanks' are aded to this list and then the algorithm maps a row,column pair to a wordNumber, characterNumber in the expanded list. (This is a bit of the inverse of the usual strategy seen in other solutions).

If we allow trailing white space on all lines except the last, we can do a bit better (163 bytes):

def f(s):
 M=max(map(len,s));p=' '*M;L=[p]+s+M*[p];r='';k=0
 while k/M<len(s)*3+M:i=k%M;w=k/M-i+1;r+=(L[(w/3+1)*(w%3==1)]+p)[i]+'\n'*(i==M-1);k+=1
 return r.strip()

Python 2, 182 bytes

def f(s):
 M=max(map(len,s));p=' '*M;L=[p]+s+M*[p];r='';k=0
 while k/M<len(s)*3+M:
 i=k%M;w=k/M-i+1;r+=(L[(w/3+1)*(w%3==1)]+p)[i];k+=1
 if i==M-1:r=r.rstrip()+'\n'
 return r.strip()

A bit long, but on the positive side, it returns a string with no trailing white space on each line, and no trailing white space or returns at the end; constraints that some other entries don't obey.

A list of words is passed into the function; some 'blanks' are aded to this list and then the algorithm maps a row,column pair to a wordNumber, characterNumber in the expanded list. (This is a bit of the inverse of the usual strategy seen in other solutions).

If we allow trailing white space on all lines except the last, we can do a bit better (163 bytes):

def f(s):
 M=max(map(len,s));p=' '*M;L=[p]+s+M*[p];r='';k=0
 while k/M<len(s)*3+M:i=k%M;w=k/M-i+1;r+=(L[(w/3+1)*(w%3==1)]+p)[i]+'\n'*(i==M-1);k+=1
 return r.strip()
Source Link
Chas Brown
  • 9.8k
  • 1
  • 14
  • 39

#Python 2, 182 bytes#

def f(s):
 M=max(map(len,s));p=' '*M;L=[p]+s+M*[p];r='';k=0
 while k/M<len(s)*3+M:
 i=k%M;w=k/M-i+1;r+=(L[(w/3+1)*(w%3==1)]+p)[i];k+=1
 if i==M-1:r=r.rstrip()+'\n'
 return r.strip()

A bit long, but on the positive side, it returns a string with no trailing white space on each line, and no trailing white space or returns at the end; constraints that some other entries don't obey.

A list of words is passed into the function; some 'blanks' are aded to this list and then the algorithm maps a row,column pair to a wordNumber, characterNumber in the expanded list. (This is a bit of the inverse of the usual strategy seen in other solutions).

If we allow trailing white space on all lines except the last, we can do a bit better (163 bytes):

def f(s):
 M=max(map(len,s));p=' '*M;L=[p]+s+M*[p];r='';k=0
 while k/M<len(s)*3+M:i=k%M;w=k/M-i+1;r+=(L[(w/3+1)*(w%3==1)]+p)[i]+'\n'*(i==M-1);k+=1
 return r.strip()

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