Skip to main content
deleted 1 character in body
Source Link
britishtea
  • 1.2k
  • 6
  • 14

Ruby, 9190

f=->n{a=["/\\".center(2*n)]
2.upto(n){a<<a[-1].gsub(/\\\/"\\/","  ").gsub(/ \/|\\ /,"/\\")}
puts a}

Explanation

  • Input is taken as an argument to a lambda. It is expected to be an Integer.
  • Use String#center to create a String "/\" with n - 2 spaces on each side and put it into an Array (a).
  • Add to a the last element of a with every occurrence of "\/" replaced with " " and every occurrence of " /" or " \" replaced with "/\".
  • Use puts to print each element in a on its own line.

Ruby, 91

f=->n{a=["/\\".center(2*n)]
2.upto(n){a<<a[-1].gsub(/\\\//,"  ").gsub(/ \/|\\ /,"/\\")}
puts a}

Explanation

  • Input is taken as an argument to a lambda. It is expected to be an Integer.
  • Use String#center to create a String "/\" with n - 2 spaces on each side and put it into an Array (a).
  • Add to a the last element of a with every occurrence of "\/" replaced with " " and every occurrence of " /" or " \" replaced with "/\".
  • Use puts print each element in a on its own line.

Ruby, 90

f=->n{a=["/\\".center(2*n)]
2.upto(n){a<<a[-1].gsub("\\/","  ").gsub(/ \/|\\ /,"/\\")}
puts a}

Explanation

  • Input is taken as an argument to a lambda. It is expected to be an Integer.
  • Use String#center to create a String "/\" with n - 2 spaces on each side and put it into an Array (a).
  • Add to a the last element of a with every occurrence of "\/" replaced with " " and every occurrence of " /" or " \" replaced with "/\".
  • Use puts to print each element in a on its own line.
deleted 9 characters in body
Source Link
britishtea
  • 1.2k
  • 6
  • 14

Ruby, 91

f=->n{a=["/\\".center(2*n)]
2.upto(n){a<<a[-1].gsub(/\\\//,"  ").gsub(/ \/|\\ /,"/\\")}
a*"\n"puts a}

Explanation

  • Input is taken as an argument to a lambda. It is expected to be an Integer.
  • Use String#center to create a String "/\" with n - 2 spaces on each side and put it into an Array (a).
  • Add to a the last element of a with every occurrence of "\/" replaced with " " and every occurrence of " /" or " \" replaced with "/\".
  • Use Array#*puts to joinprint each element in a into a String separated by "\n" on its own line.

Ruby, 91

f=->n{a=["/\\".center(2*n)]
2.upto(n){a<<a[-1].gsub(/\\\//,"  ").gsub(/ \/|\\ /,"/\\")}
a*"\n"}

Explanation

  • Input is taken as an argument to a lambda. It is expected to be an Integer.
  • Use String#center to create a String "/\" with n - 2 spaces on each side and put it into an Array (a).
  • Add to a the last element of a with every occurrence of "\/" replaced with " " and every occurrence of " /" or " \" replaced with "/\".
  • Use Array#* to join a into a String separated by "\n".

Ruby, 91

f=->n{a=["/\\".center(2*n)]
2.upto(n){a<<a[-1].gsub(/\\\//,"  ").gsub(/ \/|\\ /,"/\\")}
puts a}

Explanation

  • Input is taken as an argument to a lambda. It is expected to be an Integer.
  • Use String#center to create a String "/\" with n - 2 spaces on each side and put it into an Array (a).
  • Add to a the last element of a with every occurrence of "\/" replaced with " " and every occurrence of " /" or " \" replaced with "/\".
  • Use puts print each element in a on its own line.
added 122 characters in body
Source Link
britishtea
  • 1.2k
  • 6
  • 14

Ruby, 14191

f=->n{q="a=["/\\"
a=[q].center(2*n)]
2.upto(n-1).times{a<<a[-1].gsub(/\\\/| ?(\/) ?|," ?(\\) ?/"){|x|{"\\.gsub(/"=>"  ",?\\=>q,?\/=>q}[x.tr("|\\ "/,"""/\\")]}}
a.map{|x|x.center 2*n}*"\n"a*"\n"}

Explanation

  • Input is taken as an argument to a lambda. It is expected to be an Integer.
  • Using string replacement basedUse String#center to create a String "/\" with n - 2 spaces on rules 1each side and 2 in the problemput it into an Array is constructed(a).
  • The elements inAdd to a the Array are centered usinglast element of String#centera with every occurrence of "\/" replaced with " " and joined together usingevery occurrence of " /" or " \" replaced with "/\".
  • Use Array#* to join a into a String separated by "\n".

Ruby, 141

f=->n{q="/\\"
a=[q]
(n-1).times{a<<a[-1].gsub(/\\\/| ?(\/) ?| ?(\\) ?/){|x|{"\\/"=>"  ",?\\=>q,?/=>q}[x.tr(" ","")]}}
a.map{|x|x.center 2*n}*"\n"}

Explanation

  • Input is taken as an argument to a lambda.
  • Using string replacement based on rules 1 and 2 in the problem an Array is constructed.
  • The elements in the Array are centered using String#center and joined together using Array#*.

Ruby, 91

f=->n{a=["/\\".center(2*n)]
2.upto(n){a<<a[-1].gsub(/\\\//,"  ").gsub(/ \/|\\ /,"/\\")}
a*"\n"}

Explanation

  • Input is taken as an argument to a lambda. It is expected to be an Integer.
  • Use String#center to create a String "/\" with n - 2 spaces on each side and put it into an Array (a).
  • Add to a the last element of a with every occurrence of "\/" replaced with " " and every occurrence of " /" or " \" replaced with "/\".
  • Use Array#* to join a into a String separated by "\n".
Source Link
britishtea
  • 1.2k
  • 6
  • 14
Loading