Skip to main content
Commonmark migration
Source Link

#Ruby: 98 92 characters

Ruby: 98 92 characters

Proc that returns a string with the Sun.

f=->n{x=(0..m=n*2).map{|i|s=?|.center m+1
s[i]=?\\
s[m-i]=?/
s}
x[n]=?O.center m+1,?-
x*?\n}

Sample run:

irb(main):001:0> f=->n{x=(0..m=n*2).map{|i|s=?|.center m+1;s[i]=?\\;s[m-i]=?/;s};x[n]=?O.center m+1,?-;x*?\n}
=> #<Proc:0x000000020dea60@(irb):1 (lambda)>
irb(main):002:0> (0..3).each {|i| puts f[i]}
O
\|/
-O-
/|\
\ | /
 \|/ 
--O--
 /|\ 
/ | \
\  |  /
 \ | / 
  \|/  
---O---
  /|\  
 / | \ 
/  |  \
=> 0..3

#Ruby: 98 92 characters

Proc that returns a string with the Sun.

f=->n{x=(0..m=n*2).map{|i|s=?|.center m+1
s[i]=?\\
s[m-i]=?/
s}
x[n]=?O.center m+1,?-
x*?\n}

Sample run:

irb(main):001:0> f=->n{x=(0..m=n*2).map{|i|s=?|.center m+1;s[i]=?\\;s[m-i]=?/;s};x[n]=?O.center m+1,?-;x*?\n}
=> #<Proc:0x000000020dea60@(irb):1 (lambda)>
irb(main):002:0> (0..3).each {|i| puts f[i]}
O
\|/
-O-
/|\
\ | /
 \|/ 
--O--
 /|\ 
/ | \
\  |  /
 \ | / 
  \|/  
---O---
  /|\  
 / | \ 
/  |  \
=> 0..3

Ruby: 98 92 characters

Proc that returns a string with the Sun.

f=->n{x=(0..m=n*2).map{|i|s=?|.center m+1
s[i]=?\\
s[m-i]=?/
s}
x[n]=?O.center m+1,?-
x*?\n}

Sample run:

irb(main):001:0> f=->n{x=(0..m=n*2).map{|i|s=?|.center m+1;s[i]=?\\;s[m-i]=?/;s};x[n]=?O.center m+1,?-;x*?\n}
=> #<Proc:0x000000020dea60@(irb):1 (lambda)>
irb(main):002:0> (0..3).each {|i| puts f[i]}
O
\|/
-O-
/|\
\ | /
 \|/ 
--O--
 /|\ 
/ | \
\  |  /
 \ | / 
  \|/  
---O---
  /|\  
 / | \ 
/  |  \
=> 0..3
edited body
Source Link
manatwork
  • 20.7k
  • 5
  • 51
  • 81

#Ruby: 9898 92 characters

Proc that returns a string with the Sun.

f=->n{x=[]
x=(0..m=n*2).map{|i|x[i]=s=|i|s=?|.center m+1
s[i]=?\\
s[m-i]=?/
s}
x[n]=?O.center m+1,?-
x*?\n}

Sample run:

irb(main):001:0> f=->n{x=[];x=(0..m=n*2).map{|i|x[i]=s=|i|s=?|.center m+1;s[i]=?\\;s[m-i]=?/;s};x[n]=?O.center m+1,?-;x*?\n}
=> #<Proc:0x000000010fcef8@0x000000020dea60@(irb):1 (lambda)>
irb(main):002:0> (0..3).each {|i| puts f[i]}
O
\|/
-O-
/|\
\ | /
 \|/ 
--O--
 /|\ 
/ | \
\  |  /
 \ | / 
  \|/  
---O---
  /|\  
 / | \ 
/  |  \
=> 0..3

#Ruby: 98 characters

Proc that returns a string with the Sun.

f=->n{x=[]
(0..m=n*2).map{|i|x[i]=s=?|.center m+1
s[i]=?\\
s[m-i]=?/}
x[n]=?O.center m+1,?-
x*?\n}

Sample run:

irb(main):001:0> f=->n{x=[];(0..m=n*2).map{|i|x[i]=s=?|.center m+1;s[i]=?\\;s[m-i]=?/};x[n]=?O.center m+1,?-;x*?\n}
=> #<Proc:0x000000010fcef8@(irb):1 (lambda)>
irb(main):002:0> (0..3).each {|i| puts f[i]}
O
\|/
-O-
/|\
\ | /
 \|/ 
--O--
 /|\ 
/ | \
\  |  /
 \ | / 
  \|/  
---O---
  /|\  
 / | \ 
/  |  \
=> 0..3

#Ruby: 98 92 characters

Proc that returns a string with the Sun.

f=->n{x=(0..m=n*2).map{|i|s=?|.center m+1
s[i]=?\\
s[m-i]=?/
s}
x[n]=?O.center m+1,?-
x*?\n}

Sample run:

irb(main):001:0> f=->n{x=(0..m=n*2).map{|i|s=?|.center m+1;s[i]=?\\;s[m-i]=?/;s};x[n]=?O.center m+1,?-;x*?\n}
=> #<Proc:0x000000020dea60@(irb):1 (lambda)>
irb(main):002:0> (0..3).each {|i| puts f[i]}
O
\|/
-O-
/|\
\ | /
 \|/ 
--O--
 /|\ 
/ | \
\  |  /
 \ | / 
  \|/  
---O---
  /|\  
 / | \ 
/  |  \
=> 0..3
Source Link
manatwork
  • 20.7k
  • 5
  • 51
  • 81

#Ruby: 98 characters

Proc that returns a string with the Sun.

f=->n{x=[]
(0..m=n*2).map{|i|x[i]=s=?|.center m+1
s[i]=?\\
s[m-i]=?/}
x[n]=?O.center m+1,?-
x*?\n}

Sample run:

irb(main):001:0> f=->n{x=[];(0..m=n*2).map{|i|x[i]=s=?|.center m+1;s[i]=?\\;s[m-i]=?/};x[n]=?O.center m+1,?-;x*?\n}
=> #<Proc:0x000000010fcef8@(irb):1 (lambda)>
irb(main):002:0> (0..3).each {|i| puts f[i]}
O
\|/
-O-
/|\
\ | /
 \|/ 
--O--
 /|\ 
/ | \
\  |  /
 \ | / 
  \|/  
---O---
  /|\  
 / | \ 
/  |  \
=> 0..3