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

#Ruby approach 2 rev 1, 76 bytes

Ruby approach 2 rev 1, 76 bytes

->s{s=s.chars*' '
0.upto(w=s.size**0.5-1){|i|puts' '*(w-i)+s[i*i+i,i*2+2]}}

Optimized using syntax ideas from Vasu Adari's answer, plus a few twists of my own.

#Ruby approach 2 rev 0, 93 bytes

Ruby approach 2 rev 0, 93 bytes

->s{s=s.chars.to_a.join(' ')
w=(s.size**0.5).to_i
w.times{|i|puts' '*(w-i-1)+s[i*i+i,i*2+2]}}

Completely different approach. First we add spaces in between the characters of the input. Then we print out the rows line by line.

#Ruby approach 1, 94 bytes# ->s{n=-1;w=((s.size2)**0.5).to_i (ww).times{|i|print i/w+i%w<w-1?'':s[n+=1],-i%w==1?$/:' '}}

Ruby approach 1, 94 bytes

->s{n=-1;w=((s.size*2)**0.5).to_i
(w*w).times{|i|print i/w+i%w<w-1?'':s[n+=1],-i%w==1?$/:' '}}

this ended up far longer than anticipated.

w contains the number of printable characters in the bottom row, or equivalently, the number of lines.

Every line contains w whitespace characters (the last of which is the newline) so the idea is to print these whitespace characters and insert the printable characters where necessary.

#Ruby approach 2 rev 1, 76 bytes

->s{s=s.chars*' '
0.upto(w=s.size**0.5-1){|i|puts' '*(w-i)+s[i*i+i,i*2+2]}}

Optimized using syntax ideas from Vasu Adari's answer, plus a few twists of my own.

#Ruby approach 2 rev 0, 93 bytes

->s{s=s.chars.to_a.join(' ')
w=(s.size**0.5).to_i
w.times{|i|puts' '*(w-i-1)+s[i*i+i,i*2+2]}}

Completely different approach. First we add spaces in between the characters of the input. Then we print out the rows line by line.

#Ruby approach 1, 94 bytes# ->s{n=-1;w=((s.size2)**0.5).to_i (ww).times{|i|print i/w+i%w<w-1?'':s[n+=1],-i%w==1?$/:' '}}

this ended up far longer than anticipated.

w contains the number of printable characters in the bottom row, or equivalently, the number of lines.

Every line contains w whitespace characters (the last of which is the newline) so the idea is to print these whitespace characters and insert the printable characters where necessary.

Ruby approach 2 rev 1, 76 bytes

->s{s=s.chars*' '
0.upto(w=s.size**0.5-1){|i|puts' '*(w-i)+s[i*i+i,i*2+2]}}

Optimized using syntax ideas from Vasu Adari's answer, plus a few twists of my own.

Ruby approach 2 rev 0, 93 bytes

->s{s=s.chars.to_a.join(' ')
w=(s.size**0.5).to_i
w.times{|i|puts' '*(w-i-1)+s[i*i+i,i*2+2]}}

Completely different approach. First we add spaces in between the characters of the input. Then we print out the rows line by line.

Ruby approach 1, 94 bytes

->s{n=-1;w=((s.size*2)**0.5).to_i
(w*w).times{|i|print i/w+i%w<w-1?'':s[n+=1],-i%w==1?$/:' '}}

this ended up far longer than anticipated.

w contains the number of printable characters in the bottom row, or equivalently, the number of lines.

Every line contains w whitespace characters (the last of which is the newline) so the idea is to print these whitespace characters and insert the printable characters where necessary.

added 217 characters in body
Source Link
Level River St
  • 28.8k
  • 4
  • 40
  • 112

#Ruby approach 2 rev 1, 76 bytes

->s{s=s.chars*' '
0.upto(w=s.size**0.5-1){|i|puts' '*(w-i)+s[i*i+i,i*2+2]}}

Optimized using syntax ideas from Vasu Adari's answer, plus a few twists of my own.

#Ruby approach 2 rev 0, 93 bytes

->s{s=s.chars.to_a.join(' ')
w=(s.size**0.5).to_i
w.times{|i|puts' '*(w-i-1)+s[i*i+i,i*2+2]}}

Completely different approach. First we add spaces in between the characters of the input. Then we print out the rows line by line.

#Ruby approach 1, 94 bytes# ->s{n=-1;w=((s.size2)**0.5).to_i (ww).times{|i|print i/w+i%w<w-1?'':s[n+=1],-i%w==1?$/:' '}}

this ended up far longer than anticipated.

w contains the number of printable characters in the bottom row, or equivalently, the number of lines.

Every line contains w whitespace characters (the last of which is the newline) so the idea is to print these whitespace characters and insert the printable characters where necessary.

#Ruby approach 2, 93 bytes

->s{s=s.chars.to_a.join(' ')
w=(s.size**0.5).to_i
w.times{|i|puts' '*(w-i-1)+s[i*i+i,i*2+2]}}

Completely different approach. First we add spaces in between the characters of the input. Then we print out the rows line by line.

#Ruby approach 1, 94 bytes# ->s{n=-1;w=((s.size2)**0.5).to_i (ww).times{|i|print i/w+i%w<w-1?'':s[n+=1],-i%w==1?$/:' '}}

this ended up far longer than anticipated.

w contains the number of printable characters in the bottom row, or equivalently, the number of lines.

Every line contains w whitespace characters (the last of which is the newline) so the idea is to print these whitespace characters and insert the printable characters where necessary.

#Ruby approach 2 rev 1, 76 bytes

->s{s=s.chars*' '
0.upto(w=s.size**0.5-1){|i|puts' '*(w-i)+s[i*i+i,i*2+2]}}

Optimized using syntax ideas from Vasu Adari's answer, plus a few twists of my own.

#Ruby approach 2 rev 0, 93 bytes

->s{s=s.chars.to_a.join(' ')
w=(s.size**0.5).to_i
w.times{|i|puts' '*(w-i-1)+s[i*i+i,i*2+2]}}

Completely different approach. First we add spaces in between the characters of the input. Then we print out the rows line by line.

#Ruby approach 1, 94 bytes# ->s{n=-1;w=((s.size2)**0.5).to_i (ww).times{|i|print i/w+i%w<w-1?'':s[n+=1],-i%w==1?$/:' '}}

this ended up far longer than anticipated.

w contains the number of printable characters in the bottom row, or equivalently, the number of lines.

Every line contains w whitespace characters (the last of which is the newline) so the idea is to print these whitespace characters and insert the printable characters where necessary.

added 289 characters in body
Source Link
Level River St
  • 28.8k
  • 4
  • 40
  • 112

#Ruby approach 2, 93 bytes

->s{s=s.chars.to_a.join(' ')
w=(s.size**0.5).to_i
w.times{|i|puts' '*(w-i-1)+s[i*i+i,i*2+2]}}

Completely different approach. First we add spaces in between the characters of the input. Then we print out the rows line by line.

#Ruby approach 1, 94 bytes# ->s{n=-1;w=((s.size2)**0.5).to_i (ww).times{|i|print i/w+i%w<w-1?'':s[n+=1],-i%w==1?$/:' '}}

this ended up far longer than anticipated.

w contains the number of printable characters in the bottom row, or equivalently, the number of lines.

Every line contains w whitespace characters (the last of which is the newline) so the idea is to print these whitespace characters and insert the printable characters where necessary.

#Ruby, 94 bytes# ->s{n=-1;w=((s.size2)**0.5).to_i (ww).times{|i|print i/w+i%w<w-1?'':s[n+=1],-i%w==1?$/:' '}}

this ended up far longer than anticipated.

w contains the number of printable characters in the bottom row, or equivalently, the number of lines.

Every line contains w whitespace characters (the last of which is the newline) so the idea is to print these whitespace characters and insert the printable characters where necessary.

#Ruby approach 2, 93 bytes

->s{s=s.chars.to_a.join(' ')
w=(s.size**0.5).to_i
w.times{|i|puts' '*(w-i-1)+s[i*i+i,i*2+2]}}

Completely different approach. First we add spaces in between the characters of the input. Then we print out the rows line by line.

#Ruby approach 1, 94 bytes# ->s{n=-1;w=((s.size2)**0.5).to_i (ww).times{|i|print i/w+i%w<w-1?'':s[n+=1],-i%w==1?$/:' '}}

this ended up far longer than anticipated.

w contains the number of printable characters in the bottom row, or equivalently, the number of lines.

Every line contains w whitespace characters (the last of which is the newline) so the idea is to print these whitespace characters and insert the printable characters where necessary.

Source Link
Level River St
  • 28.8k
  • 4
  • 40
  • 112
Loading

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