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,107#

Ruby,107

->a,b,n{(-b..b).map{|i|s='..'*b+?.
i%b==0&&(i==0?s[b]=n :s[b+a]=s[b-a]=?o)
i.abs==a&&s[0]=s[-1]=?o
puts s}}

Ungolfed in test program

f=->a,b,n{
 (-b..b).map{|i| #iterate from -i to i (lines of grit)
 s='..'*b+?. #make a string of 2n+1 .'s
 i%b==0&&(i==0?s[b]=n :s[b+a]=s[b-a]=?o) #if i%b=0 plot the centre character (if i=0) or the o's on the top and bottom rows
 i.abs==a&&s[0]=s[-1]=?o #if i.abs=a plot the o's in left and right columns
 puts s #having substituted the .'s with o and centre as necessary, output the current line
 }
}
a=gets.to_i
b=gets.to_i
n=gets.chop
f[a,b,n]

#Ruby,107#

->a,b,n{(-b..b).map{|i|s='..'*b+?.
i%b==0&&(i==0?s[b]=n :s[b+a]=s[b-a]=?o)
i.abs==a&&s[0]=s[-1]=?o
puts s}}

Ungolfed in test program

f=->a,b,n{
 (-b..b).map{|i| #iterate from -i to i (lines of grit)
 s='..'*b+?. #make a string of 2n+1 .'s
 i%b==0&&(i==0?s[b]=n :s[b+a]=s[b-a]=?o) #if i%b=0 plot the centre character (if i=0) or the o's on the top and bottom rows
 i.abs==a&&s[0]=s[-1]=?o #if i.abs=a plot the o's in left and right columns
 puts s #having substituted the .'s with o and centre as necessary, output the current line
 }
}
a=gets.to_i
b=gets.to_i
n=gets.chop
f[a,b,n]

Ruby,107

->a,b,n{(-b..b).map{|i|s='..'*b+?.
i%b==0&&(i==0?s[b]=n :s[b+a]=s[b-a]=?o)
i.abs==a&&s[0]=s[-1]=?o
puts s}}

Ungolfed in test program

f=->a,b,n{
 (-b..b).map{|i| #iterate from -i to i (lines of grit)
 s='..'*b+?. #make a string of 2n+1 .'s
 i%b==0&&(i==0?s[b]=n :s[b+a]=s[b-a]=?o) #if i%b=0 plot the centre character (if i=0) or the o's on the top and bottom rows
 i.abs==a&&s[0]=s[-1]=?o #if i.abs=a plot the o's in left and right columns
 puts s #having substituted the .'s with o and centre as necessary, output the current line
 }
}
a=gets.to_i
b=gets.to_i
n=gets.chop
f[a,b,n]
Source Link
Level River St
  • 28.8k
  • 4
  • 40
  • 112

#Ruby,107#

->a,b,n{(-b..b).map{|i|s='..'*b+?.
i%b==0&&(i==0?s[b]=n :s[b+a]=s[b-a]=?o)
i.abs==a&&s[0]=s[-1]=?o
puts s}}

Ungolfed in test program

f=->a,b,n{
 (-b..b).map{|i| #iterate from -i to i (lines of grit)
 s='..'*b+?. #make a string of 2n+1 .'s
 i%b==0&&(i==0?s[b]=n :s[b+a]=s[b-a]=?o) #if i%b=0 plot the centre character (if i=0) or the o's on the top and bottom rows
 i.abs==a&&s[0]=s[-1]=?o #if i.abs=a plot the o's in left and right columns
 puts s #having substituted the .'s with o and centre as necessary, output the current line
 }
}
a=gets.to_i
b=gets.to_i
n=gets.chop
f[a,b,n]

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