#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