Skip to main content
Implemented Mauris' suggestion
Source Link

Haskell, 109 9898 96 bytes

With nimi's suggestions, it's now just under 100 bytes:Thanks to nimi and Mauris for their help!

0#0='O'
0#_='-'
_#0='|'
i#j|i==j='\\'|i== -j='/'|1<2=' '
f n=unlines[[i#j|j<-n=unlines[map(i#)[-n..n]]|i<n]|i<-[-n..n]]

Explanation:

The operator # specifies which character appears at coordinates (i,j), with the sun centered at (0,0). Function f builds the result String by iterating themapping # over all pairs of coordinates ranging from -n to n.

Usage:

ghci> putStr $ f 2
\ | /
 \|/ 
--O--
 /|\ 
/ | \

Haskell, 109 98 bytes

With nimi's suggestions, it's now just under 100 bytes:

0#0='O'
0#_='-'
_#0='|'
i#j|i==j='\\'|i== -j='/'|1<2=' '
f n=unlines[[i#j|j<-[-n..n]]|i<-[-n..n]]

Explanation:

The operator # specifies which character appears at coordinates (i,j), with the sun centered at (0,0). Function f builds the result String by iterating the coordinates from -n to n.

Usage:

ghci> putStr $ f 2
\ | /
 \|/ 
--O--
 /|\ 
/ | \

Haskell, 109 98 96 bytes

Thanks to nimi and Mauris for their help!

0#0='O'
0#_='-'
_#0='|'
i#j|i==j='\\'|i== -j='/'|1<2=' '
f n=unlines[map(i#)[-n..n]|i<-[-n..n]]

Explanation:

The operator # specifies which character appears at coordinates (i,j), with the sun centered at (0,0). Function f builds the result String by mapping # over all pairs of coordinates ranging from -n to n.

Usage:

ghci> putStr $ f 2
\ | /
 \|/ 
--O--
 /|\ 
/ | \
Implemented nimi's suggestions
Source Link

Haskell, 109109 98 bytes

With nimi's suggestions, it's now just under 100 bytes:

s 0 0='O'0#0='O'
s 0 _='0#_='-'
s _ 0='|'_#0='|'
s i j|i==j='\\'|i==i#j|i==j='\\'|i== -j='/'|True=''|1<2=' '
f n=unlines[[s i j|j<n=unlines[[i#j|j<-[-n..n]]|i<-[-n..n]]

Explanation:

FunctionThe operator s# specifies which character appears at coordinates (i,j), with the sun centered at (0,0). Function f builds the result String by iterating the coordinates from -n to n.

Usage:

ghci> putStr $ f 2
\ | /
 \|/ 
--O--
 /|\ 
/ | \

Haskell, 109 bytes

s 0 0='O'
s 0 _='-'
s _ 0='|'
s i j|i==j='\\'|i== -j='/'|True=' '
f n=unlines[[s i j|j<-[-n..n]]|i<-[-n..n]]

Explanation:

Function s specifies which character appears at coordinates (i,j), with the sun centered at (0,0). Function f builds the result String by iterating the coordinates from -n to n.

Usage:

ghci> putStr $ f 2
\ | /
 \|/ 
--O--
 /|\ 
/ | \

Haskell, 109 98 bytes

With nimi's suggestions, it's now just under 100 bytes:

0#0='O'
0#_='-'
_#0='|'
i#j|i==j='\\'|i== -j='/'|1<2=' '
f n=unlines[[i#j|j<-[-n..n]]|i<-[-n..n]]

Explanation:

The operator # specifies which character appears at coordinates (i,j), with the sun centered at (0,0). Function f builds the result String by iterating the coordinates from -n to n.

Usage:

ghci> putStr $ f 2
\ | /
 \|/ 
--O--
 /|\ 
/ | \
Source Link

Haskell, 109 bytes

s 0 0='O'
s 0 _='-'
s _ 0='|'
s i j|i==j='\\'|i== -j='/'|True=' '
f n=unlines[[s i j|j<-[-n..n]]|i<-[-n..n]]

Explanation:

Function s specifies which character appears at coordinates (i,j), with the sun centered at (0,0). Function f builds the result String by iterating the coordinates from -n to n.

Usage:

ghci> putStr $ f 2
\ | /
 \|/ 
--O--
 /|\ 
/ | \