text:
Extendify the ASCII Sun
Write a program that takes in (via STDIN/command line) a non-negative integer N.
When N is 0, your program should print O (that's capital Oh, not zero).
When N is 1, your program should print
\|/
-O-
/|\

When N is 2 your program should print
\ | /
 \|/
--O--
 /|\
/ | \

When N is 3 your program should print
\  |  /
 \ | /
  \|/
---O---
  /|\
 / | \
/  |  \

For larger N, this pattern continues on in the same exact fashion. Each of the eight rays of the "sun" should be made of N of the appropriate -, |, /, or \ characters.
Details

Instead of a program, you may write a function that takes an integer. The function should print the sun design normally or return it as a string.

You must either

have no trailing spaces at all, or
only have enough trailing spaces so the pattern is a perfect (2N+1)*(2N+1) rectangle.

The output for any or all N may optionally have a trailing newline.

Scoring
The shortest code in bytes wins.

Is a leading newline allowed? Especially interesting for N=0.

@Jakube No. Trailing only.

Pyth, 39 38 36 bytes
jbXmXXj\|m*\ Q2d\\_hd\/JhyQQX*\-JQ\O

Try it online: Pyth Compiler/Executor
Explanation
jbXmXXj\|m*\ Q2d\\_hd\/JhyQQX*\-JQ\O   implicit: Q = input
                       JhyQ            J = 1 + 2*Q
    m                  J               map each d of [0,1,...,2*Q] to:
          *\ Q                           " "*input
         m    2                          list with twice " "*input
      j\|                                join this list by "|"
     X         d\\                       replace the value at d to "\"
    X             _hd\/                  replace the value at -(d+1) to "/"
  X                        Q           replace line Q by:
                             *\-J        "-"*J
                            X    Q\O     replace element at Q with "O"
jb                                     join by "newlines"

Another 36 bytes solution would be:
jbmXXj\|m*?\-KqdQ\ Q2d\\_hd?\OK\/hyQ

C: 116 102 99 95 92 90
s(n){for(int c=-n,r=c;r<=n;c++)putchar(c>n?c=-c,r++,10:c?r?c-r?c+r?32:47:92:45:r?124:79);}

I think that I am getting fairly close to a minimal solution using this approach, but I can't stop feeling that there is a much better approach in C. Ungolfed:
void s(int n) {
  for(
    int c = -n, r = c;
    r <= n;
    c++
  )
    putchar(
      c > n
        ? c = -c, r++, '\n'
        : c
          ? r
            ? c - r
              ? c + r
                ? ' '
                : '/'
              : '\\'
            : '-'
          : r
            ? '|'
            : 'O'
    );
}

"c++" in C ... heh!

I'm glad you ungolfed it. Those ternary ifs are insane!

You can save 2 more bytes and make it vc 2012 compliant ;) c,r;s(n){for(r=c=-n;r<=n;c++)putchar(c>n?c=-c,r++,10:c?r?c-r?c+r?32:47:92:45:r?124:79);}

GNU sed, 252 + 1
Phew - I beat the php answer!
Score + 1 for using the -r parameter.
Because of sed limitations, we have to burn nearly 100 bytes just convert N to a string of N spaces.  The rest is the fun stuff.
/^0/{y/0/O/;q}
s/./<&/g
s/9/8 /g
s/8/7 /g
s/7/6 /g
s/6/5 /g
s/5/4 /g
s/4/3 /g
s/3/2 /g
s/2/1 /g
s/1/ /g
s/0//g
:t
s/ </<          /g
tt
s/<//g
:
s/ //
s^.*^\\&|&/^;ta
:a
/\\$/q
p
s^\\\|/^-O-^;tn
s^(\\)? (/)?^\2 \1^g;ta
:n
y/ /-/
p
s^-O-^/|\\^
y/-/ /
ta

Explanation

The first line is an early exit for the N=0 case.
The next 15 lines (up to the :) convert N to a string of N spaces
s/ // removes one space
s^.*^\\&|&/^;ta converts N-1 spaces to: \ + N-1 spaces + | + N-1 spaces + /
Iterate, printing each iteration, and moving \ one space to the right and / one space to the left...
...until we match \|/, which is replaced with -O- and jump to the n label
replace  with - and print
replace -0- with /|\, and replace  with - and jump back into the main loop
Iterate, printing each iteration, and moving \ one space to the right and / one space to the left...
...until we match \$ which indicates were finished, and quit.

Output
 $ for i in {0..3}; do sed -rf asciisun.sed <<< $i ; done
 O
 \|/
 -O-
 /|\
 \ | /
  \|/
 --O--
  /|\
 / | \
 \  |  /
  \ | /
   \|/
 ---O---
   /|\
  / | \
 /  |  \
 $

J, 37 34 40 bytes
1:echo('O\/-|'{.@#~0=+&|,-,+,[,])"*/~@i:

Usage:
   (1:echo('O\/-|'{.@#~0=+&|,-,+,[,])"*/~@i:) 2  NB. prints to stdout:
\ | /
 \|/
--O--
 /|\
/ | \

Explanation (from left to right):

i: generates list -n, -(n-1), ..., n-1, n
(  )"*/~@i: creates the Descartes product of i: with itself in a matrix arrangement, e.g. for n = 1 creates the following 3-by-3 matrix
┌─────┬────┬────┐
│-1 -1│-1 0│-1 1│
├─────┼────┼────┤
│0 -1 │0 0 │0 1 │
├─────┼────┼────┤
│1 -1 │1 0 │1 1 │
└─────┴────┴────┘

for every matrix-element with integers x y we do the following
+&|,-,+,[,] calculate a list of properties

+&| abs(x)+abs(y), equals 0 iff (if and only if) x=0 and y=0
- x-y, equals 0 iff x=y i.e. we are on the diagonal
+ x+y, equals 0 iff x=-y i.e. we are on the anti-diagonal
[ x, equals 0 iff x=0 i.e. we are on the middle row
] y, equals 0 iff y=0 i.e. we are on the middle column

'O\/-|'#~0= compare these above property values to 0 and take the ith character from the string 'O\/-|' if the ith property is true.
the first character in the resulting string will always be the one we need, if there string is empty we need a space
{. takes the first character of a string and if there is no one it returns a space character as padding just as we need
we now have the exact matrix we need so we print it to stdout once with 1:echo

Try it online here.

This is the ungolfed version?! I feel like a pretty average programmer at times, and then for some reason I end up on codegolf and see the stuff you guys pull off and can't help but feel like an idiot.

@JustSid Well, the text wasn't up to date with the code but technically I never wrote that the code is ungolfed. :)

It's still mighty impressive either way

@JustSid Not that it's any less impressive but J code pretty much just looks like that, and this seems like a challenge that it would be a good language for. It's a very impressive answer, but so is everything else in J :)

PHP, 182 bytes
This seemed like a fun activity for my first answer. Comments on my code are welcome.
<?php function s($n){$e=2*$n+1;for($i=0;$i<$e*$e;$i++){$x=$i%$e;$y=floor($i/$e);echo$y==$x?($x==$n?"O":"\\"):($e-1==$x+$y?"/":($y==$n?"-":($x==$n?"|":" ")));echo$x==$e-1?"\n":"";}}?>

Here is the un-golfed code with comments:
<?php
function s($n) {
    $e=2*$n+1; //edge length
    for($i=0;$i<$e*$e;$i++) {
        $x = $i%$e; // current x coordinate
        $y = floor($i/$e); // current y coordinate

        if ($y==$n&&$x==$n) {
            // center of square
            echo'O';
        }
        else if ($y==$n) {
            // horizontal line
            echo'-';
        }
        else if ($x==$n) {
            // vertical line
            echo'|';
        }
        else if ($y==$x) {
            // diagonal line from top-left to bottom right
            echo'\\';
        }
        else if (($y-$n)==($n-$x)) {
            // diagonal line from bottom-left to top-right
            echo'/';
        }
        else {
            // empty space
            echo' ';
        }
        if ($x==$e-1) {
            // add new line for the end of the row
            echo"\n";
        }
    }
}?>

<?php s(10); ?>

Edited with code by royhowie

Hi :-) Good first effort. You can shrink your code in quite a few places though. For example if(($y-$h)==($x-$h)) does the same as if(($y==$x). You can save another character by replacing if($x==y$)foo();else bar(); with if($x^$y)bar();else foo();. You should also try using ternary operators instead of if .. else statements.

ternary operators is a good tip

174 bytes: function s($n){$e=2*$n+1;for($i=0;$i<$e*$e;$i++){$x=$i%$e;$y=floor($i/$e);echo$y==$x?($x==$n?"O":"\\"):($e-1==$x+$y?"/":($y==$n?"-":($x==$n?"|":" ")));echo$x==$e-1?"\n":"";}}

there's no need for $r; just use echo ($r.= is the same amount of bytes as echo). 2. used ternary operator (saves a lot of characters). 3. $h was useless since it equaled $n. 4. You didn't need to use floor for $x = floor($i%$e);, since a modulus on an integer won't need to be rounded down.

@squeamishossifrage I never thought of that. Thanks for the tips!

@royhowie Thanks! Is it ok if I update my answer with your solution?

@user2518200 of course

With or without the floor() calls the $x and $y calculation still seems longer than using 2 fors. And when possible, combine calculation and first use – for example calculate $e inside the for where it is first used. Based on @royhowie's version, 161 characters: function s($n){for($y=0;$y<$e=2*$n+1;$y++)for($x=0;$x<$e;){echo$y==$x?($x==$n?"O":"\\"):($e-1==$x+$y?"/":($y==$n?"-":($x==$n?"|":" ")));echo$x++==$e-1?"\n":"";}}

Replace floor($e/2); with $e>>1; and you will save a few bytes.

for(;$i<$c=1+2*$argn;$o.="$t\n"){$t=str_pad("|O"[$b=$i++==$argn],$c," -"[$b],2);$b?:$t[$i-1]="\\".!$t[$c-$i]="/";}echo$o; 121 Bytes

@JörgHülsermann Wow that is nice. Feel free to make a new answer. I'll upvote it.

Feel free to take it as as your improvement.

I have reuse my idea in an other challenge so you can use it here

Python 2, 99
n=input()
R=range(-n,n+1)
for i in R:print''.join("O\|/ -"[[R,i,0,-i,j].index(j)^(i==0)]for j in R)

Prints line by line, creating each line by checking whether the coordinate (i,j) (centered at (0,0)) satisfies j==-i, j==0, j==i, or none, with a hack to make the center line work.

I think you can use R instead of .5 to save 1 byte.

@randomra That's clever, thanks. Down to two digits!

CJam, 48 45 43 41 38 bytes
This is still too long and I am still doing some redundant things, but here goes:
ri:R{_S*"\|/"@R-~S**1$N}%'-R*'O1$W$sW%

Try it online here

SpecBAS - 117 bytes
1 INPUT s: LET t=s*2: FOR y=0 TO t: PRINT AT y,y;"\";AT y,t/2;"|";AT t-y,y;"/";AT t/2,y;"-": NEXT y: PRINT AT s,s;"O"

This prints the slashes and dashes in one loop, and then plonks the "O" in the middle.
Output using 1, 2 and 9

An anonymous user suggested to change "-": NEXT y: PRINT AT s,s;"O" to "-";AT s,s;"O": NEXT y to save two bytes.

JavaScript (ES6) 97 98
This seems different enough ...

// GOLFED
f=n=>(y=>{for(t='';++y<n;t+='\n')for(x=-n;++x<n;)t+='-O /\\|'[y?x?x-y?x+y?2:3:4:5:+!x]})(-++n)||t

// Ungolfed

F=n=>{
  ++n;
  t = '';
  for (y = -n; ++y < n; t += '\n')
    for (x = -n; ++x < n; )
      if (y != 0)
        if (x != 0)
          if (x != y)
            if (x != -y)
              t += ' '
            else
              t += '/'
          else
            t += '\\'
        else
          t += '|'
      else
        if (x != 0)
          t += '-'
        else
          t += 'O'
  return t;
}

// TEST
function test(){ OUT.innerHTML = f(N.value|0); }
test()
input { width: 4em }
N: <input id=N value=5><button onclick="test()">Go</button>

Beautiful. I should have thought of a closure to use normal for loops.

I like this one. I had tried writing one using a string and accessing a specific index, but yours is much shorter.

OS/2 Classic Rexx, 102... or 14 for "cheater's version"
Take out the linefeeds to "golf" it.
w='%1'
o=center('O',w,'-')
m='center(space("\|/",w),%1)'
do w
  w=w-1
  interpret "o="m"|o|"m
end l
say o

Cheater's version, name the script whatever source code you want under 255 characters (requires HPFS disk):
interpret '%0'

EDIT: Just to be clear, cheater's version isn't intended to count! It's just to be silly and show an old dog can still do tricks. :)
e.g. For real fun and games, an implementation of Java-8/C11 style "lambda" expressions on a list iterator. Not tested, but ought to run on a circa 1979 IBM mainframe. ;)
ForEachInList( 'Months.January.Days', 'Day' -> 'SAY "You have an appointment with" Day.Appointment.Name "on" Day.Appointment.Date' )
EXIT

ForEachInList:
    SIGNAL ON SYNTAX
    PARSE ARG MyList "," MyVar "->" MyCommand
    INTERPRET ' MyListCount = ' || MyList || '.Count'
    DO ListIndex = 1 TO MyListCount
       INTERPRET MyVar || ' = ' || MyList || '.' || ListIndex
       INTERPRET MyCommand
    END
    RETURN
SYNTAX:
    SAY MyCommand ' is not a valid expression. '
    EXIT

-- Calling code assumes you already made a stem (array), naturally.

For your cheater version: if the filename of a program is not arbitrary, it has to be included in the byte count.

Fair enough. Cheater's version wasn't intended as at all serious! :) ...which is why I posted the "real" answer at 102. It was just for novelty's sake.

@lisa except that its not novel at all ;) . Also, it would break the leaderboard script if used in this challenge.

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--
 /|\
/ | \

You can save a few bytes by using an infix operator instead of s, e.g. 0#0='O', 0#_='-', etc. and 1<2 instead of True.

Maybe map(i#)[-n..n] to save two bytes.

R, 177 149 bytes
Mickey T. is the man! He helped me fix my originally incorrect solution and save 28 bytes. Thanks, Mickey!
m=matrix(" ",(w=2*(n=scan()+1)-1),w);m[row(m)==rev(col(m))]="/";diag(m)="\\";m[,n]="|";m[n,]="-";m[n,n]="O";m[,w]=paste0(m[,w],"\n");cat(t(m),sep="")

Ungolfed + explanation:
# Create a matrix of spaces, read n from stdin, assign w=2n+1
m <- matrix(" ", (w <- 2*(n <- scan() + 1) - 1), w)

# Replace the opposite diagonal with forward slashes
m[row(m) == rev(col(m))] <- "/"

# Replace the diagonal with backslashes
diag(m) <- "\\"

# Replace the vertical center line with pipes
m[, n] <- "|"

# Replace the horizontal center line with dashes
m[n, ] <- "-"

# Put an O in the middle
m[n, n] <- "O"

# Collapse the columns into single strings
m[, w] <- paste0(m[, w], "\n")

# Print the transposed matrix
cat(t(m), sep = "")

Any further suggestions are welcome!

Sorry Alex, you missed the vertical rays.  There is a few things that could be changed to shorten this without changing the general process.  The scan doesn't really need the w=.  It can also be shifted deeper into the commands.  The if can be ditched if you change the way the matrix is handled in a couple of instances.  Applying these I get m=matrix(" ",(w=2*(n=scan()+1)-1),w);m[row(m)-rev(col(m))==0]='/';diag(m)="\\";m[,n]='|';m[n,]="-";m[n,n]="O";m[,w]=paste0(m[,w],'\n');cat(t(m),sep='').  Further golfing possible I think.

@MickyT: That's fantastic. Thank you so much for noticing my mistake and proving a much better solution! I edited the answer.

Rust, 215 characters
fn a(n:usize){for i in 0..n{println!("{}\\{}|{1}/{0}",s(i),s(n-i-1))}println!("{}O{0}",vec!["-";n].concat());for i in(0..n).rev(){println!("{}/{}|{1}\\{0}",s(i),s(n-i-1))}}fn s(n:usize)->String{vec![" ";n].concat()}

I tried to use a string slicing method (by creating a string of n-1 spaces and slicing to and from an index) like so:
fn a(n:usize){let s=vec![" ";n-(n>0)as usize].concat();for i in 0..n{println!("{}\\{}|{1}/{0}",&s[..i],&s[i..])}println!("{}O{0}",vec!["-";n].concat());for i in(0..n).rev(){println!("{}/{}|{1}\\{0}",&s[..i],&s[i..])}}

But that's actually 3 chars longer.
Ungolfed code:
fn asciisun_ungolfed(n: usize) {
    for i in 0..n {
        println!("{0}\\{1}|{1}/{0}", spaces(i), spaces(n-i-1))
    }
    println!("{0}O{0}", vec!["-"; n].concat());
    for i in (0..n).rev() {
        println!("{0}/{1}|{1}\\{0}", spaces(i), spaces(n-i-1))
    }
}
fn spaces(n: usize) -> String { vec![" "; n].concat() }

The part I like is how I shave a few chars off on the formatting strings. For example,
f{0}o{1}o{1}b{0}ar

is equivalent to
f{}o{}o{1}b{0}ar

because the "auto-incrementer" for the format string argument position is not affected by manually specifying the number, and acts completely independently.

IDL 8.3, 135 bytes
Dunno if this can be golfed more... It's very straightforward. First we create a m x m array (m=2n+1) of empty strings; then, we draw the characters in lines (y=x, y=-x, y=n, and x=n). Then we drop the O in at point (n, n), and print the whole thing, formatted as m strings of length 1 on each line so that there's no extra spacing from printing the array natively.
pro s,n
m=2*n+1
v=strarr(m,m)
x=[0:m-1]
v[x,x]='\'
v[x,m-x-1]='/'
v[n,x]='|'
v[x,n]='-'
v[n,n]='O'
print,v,f='('+strtrim(m,2)+'A1)'
end

Test:
IDL> s,4
\   |   /
 \  |  /
  \ | /
   \|/
----O----
   /|\
  / | \
 /  |  \
/   |   \

"Instead of a program, you may write a function that takes an integer. The function should print the sun design normally or return it as a string."

hahaha no worries :)

C#, 230 226 bytes
string g(int n){string r="";int s=n*2+1;for(int h=0;h<s;h++){for(int w=0;w<s;w++){if(h==w){if(w==n){r+="O";}else{r+="\\";}}else if(w==s-h-1){r+="/";}else if(w==n){r+="|";}else if(h==n){r+="-";}else{r+=" ";}}r+="\n";}return r;}

As requested, the ungolfed version:

    string ug(int n) {
        // The sting we'll be returning
        string ret = "";

        // The width and height of the output
        int s = n * 2 + 1;

        // for loop for width and height
        for (int height = 0; height < s; height++)
        {
            for (int width = 0; width < s; width++)
            {
                // Matches on top-left to bottom-right diagonal line
                if (height == width)
                {
                    // If this is the center, write the 'sun'
                    if (width == n)
                    {
                        ret += "O";
                    }
                    // If this is not the center, add the diagonal line character
                    else
                    {
                        ret += "\\";
                    }
                }
                // Matches on top-right to bottom-left diagonal line
                else if (width == s - height - 1)
                {
                    ret += "/";
                }
                // Matches to add the center line
                else if (width == n)
                {
                    ret += "|";
                }
                // Matches to add the horizontal line
                else if (height == n)
                {
                    ret += "-";
                }
                // Matches all others
                else
                {
                    ret += " ";
                }
            }
            // Add a newline to separate each line
            ret += "\n";
        }
        return ret;
    }

This is my first post so apologies if I've done something wrong. Any comments and corrections are very welcome.

Also, s=2*n+1 rather than s=(n*2)+1 and w==s-h-1 rather than w==(s-h)-1 will make this a little shorter.

nice, may steal your string building method. it annoys me that linq is longer than for loops :(

I've added the ungolfed version :)

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

Octave 85
Bulding matrices as always=)
eye produces an identity matrix, the rest is self explanatory I think.
m=(e=eye(2*(k=input('')+1)-1))*92+rot90(e)*47;m(:,k)='|';m(k,:)=45;m(k,k)='o';[m,'']

Still two bytes better than mine :( I actually tried something similar to this initially, but couldn't get it small enough - I didn't realize I could do "m(:,k)='|'". Nice submission!

Javascript (ES7 Draft) 115

f=l=>[['O |/\\-'[y^x?z+~x^y?y^l?x^l?1:2:5:3:x^l&&4]for(x in _)].join('')for(y in _=[...Array(z=2*l+1)])].join('\n')

// Snippet demo: (Firefox only)
for(var X of [0,1,2,3,4,5])
    document.write('
' + f(X) + '

');

Matlab, 93 87 bytes
Sadly the function header has to be so big...
Apart from that I think it is golfed pretty well. I wonder if it could be done better with some of the syntax differences in Octave.
N=input('');E=eye(N)*92;D=rot90(E)*.52;H=ones(1,N)*45;V=H'*2.76;[E V D;H 79 H;D V E '']

You can just make a program with N=input('') to save 2 characters. Other than that you can just write [E V D;H 79 H;D V E ''] for converting the whole matrix into a char array, which will save you another byte or two. ( I just submitted an Octave program with a slightly different approach, but before I found yours=)

I actually had the input line first, but for some reason I mistakenly thought it wasn't allowed... Thanks for the other tip though!

Pyth - 52 bytes
The hard part was figuring out how to switch the slashes for each side. I settled for defining a lambda that takes the symbols to use.
KdMms[*Kt-QdG*Kd\|*KdH)_UQjbg\\\/p\O*Q\-*\-Qjb_g\/\\

Can likely be golfed more, explanation coming soon.
Try it online here.

Perl, 94
There are a lot of nested ternary operators in here, but I think the code is reasonably straightforward.
$n=<>;for$x(-$n..$n){for$y(-$n..$n){print$x^$y?$x+$y?$x?$y?$":'|':'-':'/':$x?'\\':'O'}print$/}

Try it out here: ideone.com/E8MC1d

88B: for$x(-($n=<>)..$n){map{print$x^$_?$x+$_?$x?$_?$":'|':'-':'/':$x?'\\':O}-$n..$n;print$/} - A couple of tweaks: convert inner for to map and change $y to $_; inline ($n=<>).

C# - 291 (full program)
using System;using System.Linq;class P{static void Main(string[] a){Func<int,int,int,char>C=(s,x,i)=>x==(2*s+1)?'\n':i==s?x==s?'O':'-':x==s?'|':x==i?'\\':x==2*s-i?'/':' ';int S=int.Parse(a[0])*2;Console.Write(Enumerable.Range(0,(S+1)*(S+1)+S).Select(z=>C(S/2,z%(S+2),z/(S+2))).ToArray());}}

working on it!!

Haskell, 80 bytes
a#b=2*a+0^b^2
f n|r<-[-n..n]=[[" /\\x-xOx|"!!mod(0#x#y#(x-y)#(x+y))9|x<-r]|y<-r]

Try it online!

JavaScript (ES6), 139 135 140 + 1 bytes
(+1 is for -p flag with node in the console)
fixed:
t=(n,m)=>(m=2*n+1,(A=Array).from(A(m),(d,i)=>A.from(A(m),(e,j)=>i==j?j==n?"O":"\\":m-1==j+i?"/":i==n?"-":j==n?"|":" ").join("")).join("\n"))

usage:
t(3)
/*
\  |  /
 \ | /
  \|/
---O---
  /|\
 / | \
/  |  \
*/

ungolfed:
var makeSun = function (n, m) {
    m = 2 * n + 1;    // there are 2*n+1 in each row/column
    return Array.from(Array(m), function (d, i) {
        return Array.from(Array(m), function (e, j) {
            // if i is j, we want to return a \
            // unless we're at the middle element
            // in which case we return the sun ("O")
            if (i == j) {
                return j == n ? "O" : "\\";
            // the other diagonal is when m-1 is j+i
            // so return a forward slash, /
            } else if (m - 1 == j + i) {
                return "/";
            // the middle row is all dashes
            } else if (i == n) {
                return "-";
            // the middle column is all pipes
            } else if (j == n) {
                return "|";
            // everything else is a space
            } else {
                return " ";
            }
        }).join("");
    }).join("\n");
}

You appear to be missing two rays.

Oh, darn, I forgot to add that back in…

(A=Array).from(A(m))

@MichaelT I fixed it, but I think I can golf it some more

@Shmiddty thanks for the suggestion! that saved a lot of characters

Ruby - 130 bytes
def f(n);a=(0...n).map{|i|' '*i+"\\"+' '*(n-1-i)+'|'+' '*(n-1-i)+'/'+' '*i};puts(a+['-'*n+'O'+'-'*n]+a.reverse.map(&:reverse));end

usage:
irb(main):002:0> f(3)
\  |  /
 \ | /
  \|/
---O---
  /|\
 / | \
/  |  \

Applied a couple of old trick: f=->n{a=(0...n).map{|i|(s=' ')*i+?\\+s*(m=n-1-i)+?|+s*(m)+?/+s*i};puts(a+[?-*n+'O'+?-*n]+a.reverse.map(&:reverse))} (See Tips for golfing in Ruby for some more.)

Perl 85 91 90 89 86B
map{$_=$r||O;s/^|$/ /mg;s/ (-*O-*) /-$1-/;$r="\\$s|$s/
$_
/$s|$s\\";$s.=$"}1..<>;say$r

Ungolfed:
# usage: echo 1|perl sun.pl

map {
    $_ = $r || O;  # no strict: o is "o". On the first run $r is not defined
    s/^|$/ /mg;    # overwriting $_ saves characters on these regexes
    s/ (-*O-*) /-$1-/;
    $r = "\\$s|$s/
$_
/$s|$s\\";         # Embedded newlines save 1B vs \n. On the first run $s is not defined.
    $s .= $"
} 1..<>;
say $r

Python, 175 129 127 125 Bytes
s,q,x=' ','',int(input())
for i in range(x):d=(x-i-1);q+=(s*i+'\\'+s*d+'|'+s*d+'/'+s*i+'\n')
print(q+'-'*x+'O'+'-'*x+q[::-1])

Try it online here.

Python 3, 193 186 bytes
Golfed
def f(n):
 s,b,e,d,g=' \\/|-';p,r,i='',int(n),0
 while r:print(s*i+b+s*(r-1)+d+s*(r-1)+e);r-=1;i+=1
 print(g*n+'O'+g*n);r+=1;i=n-1
 while r<n+1:print(s*i+e+s*(r-1)+d+s*(r-1)+b);r+=1;i-=1

Output
>>> f(3)
\  |  /
 \ | /
  \|/
---O---
  /|\
 / | \
/  |  \

>>> f(5)
\    |    /
 \   |   /
  \  |  /
   \ | /
    \|/
-----O-----
    /|\
   / | \
  /  |  \
 /   |   \
/    |    \

Ungolfed
def f(n):
    s, b, e, d, g = ' \\/|-'
    p, r, i = '', int(n), 0
    while r:
        print(s*i + b + s*(r-1) + d + s*(r-1) + e)
        r -= 1
        i += 1
    print(g*n + 'O' + g*n)
    r += 1
    i = n-1
    while r < n+1:
        print(s*i + e + s*(r-1) + d + s*(r-1) + b)
        r += 1
        i -= 1

There's a few things to be golfed here, but the biggest one is your default arguments. s=' ',b='\\',f='/',d='|',g='-' is very long, so you'd be better off moving it by adding s,b,f,d,g=" \/|-" to the second line.

I meant " \/|-" as a single string, rather than splitting it up into individual chars. You can unpack from a string like x,y,z="123", which makes x="1", y="2" and z="3".

Edited again. Thanks @Sp3000

CJam, 59 55 bytes
ri:A,W%{_S*"\|/"\*\A\-(S*_@@++}%_Wf%W%['-A*_'O\++]\++N*

This won't win any awards as-is but I was happy enough it worked!
Thanks to Sp3000 for golfing tips.

Nice work! Here's a few tips: 1) You can use S instead of the ' version for space and 2) For '-A*'O'-A you can do '-A*_'O\ instead because generating it twice is long

Prolog, 219 bytes
No, it's not much of a golfing language. But I think this site needs more Prolog.
s(N,N,N,79).
s(R,R,_,92).
s(R,C,N,47):-R+C=:=2*N.
s(N,_,N,45).
s(_,N,N,124).
s(_,_,_,32).
c(_,C,N):-C>2*N,nl.
c(R,C,N):-s(R,C,N,S),put(S),X is C+1,c(R,X,N).
r(R,N):-R>2*N.
r(R,N):-c(R,0,N),X is R+1,r(X,N).
g(N):-r(0,N).

Tested with swipl on Linux. Invoke like so: swipl -s asciiSun.prolog; then query for your desired size of sun:
?- g(3).
\  |  /
 \ | /
  \|/
---O---
  /|\
 / | \
/  |  \
true .

Ungolfed:
 % Args to sym/4 are row, column, N and the character code to be output at that location.
sym(N,N,N,79).
sym(R,R,_,'\\').
sym(R,C,N,'/') :- R+C =:= 2*N.
sym(N,_,N,'-').
sym(_,N,N,'|').
sym(_,_,_,' ').

 % Args to putCols/3 are row, column, and N.
 % Recursively outputs the characters in row from col onward.
putCols(_,C,N) :- C > 2*N, nl.
putCols(R,C,N) :- sym(R,C,N,S), put_code(S), NextC is C+1, putCols(R,NextC,N).

 % Args to putRows/2 are row and N.
 % Recursively outputs the grid from row downward.
putRows(R,N) :- R > 2*N.
putRows(R,N) :- putCols(R,0,N), NextR is R+1, putRows(NextR,N).

putGrid(N) :- putRows(0,N).

JavaScript (ES6), 142 140 134 117 bytes
n=>(g=x=>x?`${t=` `[r=`repeat`](n-x--)}\\${s=` `[r](x)}|${s}/${t}
`+g(x):`-`[r](n))(n)+`O`+[...g(n)].reverse().join``

Try It

f=
n=>(g=x=>x?`${t=` `[r=`repeat`](n-x--)}\\${s=` `[r](x)}|${s}/${t}
`+g(x):`-`[r](n))(n)+`O`+[...g(n)].reverse().join``
i.addEventListener("input",_=>o.innerText=f(+i.value))
o.innerText=f(i.value=1)
<input id=i type=number>

Powershell, 108 97 93 bytes
filter f{try{$s=' '*--$_
"\$s|$s/"
$_|f|%{(" $_ ","-$_-")[$_-match'O']}
"/$s|$s\"}catch{'O'}}

Explanation:

the recursive algorithm throws an exception on $s=' '*--$_ when current number less then 1;
the output is a perfect rectangle with trailing spaces.

Less golfed test script:
filter f{
    try{
        $s=' '*--$_
        "\$s|$s/"
        $_|f|%{(" $_ ","-$_-")[$_-match'O']}
        "/$s|$s\"
    }catch{
        'O'
    }
}

@(

,(0,"O")
,(1,"\|/",
    "-O-",
    "/|\")
,(2,"\ | /",
    " \|/ ",
    "--O--",
    " /|\ ",
    "/ | \")
,(3,"\  |  /",
    " \ | / ",
    "  \|/  ",
    "---O---",
    "  /|\  ",
    " / | \ ",
    "/  |  \")

) | % {
    $n,$expected = $_
    $result = $n|f
    "$result"-eq"$expected"
    $result
}

Output:
True
O
True
\|/
-O-
/|\
True
\ | /
 \|/
--O--
 /|\
/ | \
True
\  |  /
 \ | /
  \|/
---O---
  /|\
 / | \
/  |  \

Charcoal, 12 5 bytes
Ｐ*⊕θO

-7 bytes thanks to @ASCII-only, by using the builtin :*.
Try it online (verbose) or try it online (pure).
Explanation:
Print the 8-armed lines with a length of the input+1 (the +1 is because the center is included), without moving the cursor position:
MultiPrint(:*, Incremented(q));
Ｐ*⊕θ

Then print the "O" at the current location (still in the center, because we haven't moved due to the MultiPrint):
Print("O");
O

5?

@ASCII-only Thanks! Didn't even knew there was a :* builtin for this.

Groovy - 113
f={n->s=2*n+1;(1..s).each{r->(1..s+1).each{c->print c==r?n+1==r?"O":"\\":c==s-r+1?"/":c==n+1?"|":c>s?"\n":" "}}}

I think the ternary logic could probably be cleaned up to give a shorter answer...

SmileBASIC, 87 bytes
INPUT N
FOR Y=-N TO N
FOR X=-N TO N?" \/|-     O"[(X==Y)+!(X+Y)*2+!X*3+!Y*4];
NEXT?NEXT

Japt, 26 25 bytes
Pub golfing so, as usual, could probably be shorter.
Æ"\\|/"¬qXçÃÔp'OiUç-¹·ê û

Try it
Æ"\\|/"¬qXçÃÔp'OiUç-¹·ê û     :Implicit input of integer U
Æ                             :Map each X in the range [0,U)
 "\\|/"¬                      :  Split the string "\|/"
        q                     :  Join with
         Xç                   :    X spaces
           Ã                  :End map
            Ô                 :Reverse
             p                :Push
              'Oi             :  "O" prepended with
                 Uç-          :    "-" repeated U times
                    ¹         :End push
                     ·        :Join with newlines
                      ê       :Palindromise
                        û     :Centre pad each line with spaces to the length of the longest

Canvas, 14 bytes
╵⌐|＊⁸／＋↔ω↶ｎ┼O╋

Try it here!

Retina 0.8.2, 99 bytes
.+
$* X$&$*-
 ( *)X(-+)
$1\|/¶$2X$2¶$1/|\
+`^ ( *.)( *)
$1$2 | $2/¶$&
+` ( */)( *).+$
$&¶$1$2 | $2\

Try it online! Explanation:
.+
$* X$&$*-

Place the X and draw n -s to its right. This completes the output for n=0.
 ( *)X(-+)
$1\|/¶$2X$2¶$1/|\

If n>0 then copy the -s to the left, and add the first level of \|/ and /|\ around the X. This completes the output for n=1.
+`^ ( *.)( *)
$1$2 | $2/¶$&

Extend the \|/ upwards, removing a space of indent each time, adding it back on each side of the |.
+` ( */)( *).+$
$&¶$1$2 | $2\

Extend the /|\ downwards, removing a space of indent each time, adding it back on each side of the |.

Vyxal, 46 bytes
(\\n›↳⁰↲\|\/n›↲⁰↳Ṡ,)\O-?-,(\/n›↲⁰↳\|\\n›↳⁰↲Ṡ,)

Try it Online!
A mess that I can't be bothered fixing, at least for now.

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/


text:
Looping Random Number Generator
I'm not even sure if this is even possible, but I think it's worth a shot.
The Challenge
Code/conceptualize a pseudo-random number generator that has the potential to produce results evenly spaced out with similar frequencies... with a twist. The random number generator has to 'loop' back after Foo iterations to its beginning state then produce the exact same results. Foo is a variable of all positive integers.
For example, if the iterations amount is 4 and the random numbers generated after 4 iterations are {93,5,80,13}, then the next 4 iterations will produce {93,5,80,13}, as will the next 4 after that and so on.
Limitations

Random numbers can't be pre-defined. For example, the algorithm can't simply iterate over {1,2,3,4,...int.MaxValue}, up to the iteration amount then go back to the first value.
Similar to Limitation 1, random numbers can't be cached so a set of numbers can't be generated, saved, then repeatedly returned.
Similar to Limitation 2, the random number generator can't be 'forced' back to a certain state. Beginning seed numbers and whatnot cannot be saved.
The RNG can't use the number of iterations its run.

In other words, the Generator has to arrive back at its beginning state solely through consecutive calculations.
Objective
Shortest code wins!

As Sp says, most random number generators necessarily loop back on themselves because they are only pseudo random and have a finite period.

Yes, but that period is a defined one in this challenge. Sorry about the confusion. Changed 'any' to 'all'.

Does "all positive integers" really mean all or just up to int.max? If the latter then could someone just take the first Foo values of their language's PRNG? (Assuming the language PRNG period is larger than int.max.)

All can't be practically tested, so I'd say just up to int.max. Taking the first Foo values of a default PRNG would violate Limitation 2. The PRNG has to arrive back at its beginning state solely through consecutive calculations.

But the values wouldn't be saved per se. The prng would just be restarted.

Ah, true. That would violate Limitation 3 though.

What is the objective winning criterion? Shortest code? Fastest code (which leads to more questions)?

If you loop an integer N with steps of 3 to infinity and then use seed(n%3)/seed(n%2)+seed(n%1) to create numbers, would this break limitation 3?

I added a new limitation to clear things up, and the winning objective. @dwana That kind of violates limitation 3 but I clarified it with a new limitation.

I think you might want give a specific criteria for what counts as "reasonably random". Different PRNGs pass different tests, but if you specify the exact testing method then everybody can be on the same boat.

The ideal would be to provide code in the question that will validate the answers, so there is no confusion over which answers are valid. Testing randomness is not easy though...

Could I generate random numbers for foo iterations and then use those same numbers?

J
I think the simplest solution to this would be the slightly bendy
   p =: 0
   random =: 3 : '(p =: y | >: p) } ?. y # 0'

That is used like this:
   random 5
0.329284
   random 5
0.335644
   random 5
0.985972
   random 5
0.0583756
   random 5
0.038363
   random 5
0.329284

This can be easily modified to provide integers, just change the 0 to whatever value you want as a maximum. Alternatively, one might write the following code:
   p =: 0
   random =: 4 : '(p =: y | >: p) } ?. y # x'

Used like this:
   10 random 5
8
   10 random 5
6
   10 random 5
5
   10 random 5
4
   10 random 5
6
   10 random 5
8

How this works

 This uses the J primitive ?.: the statically seeded random number generator; as opposed to ?: the dynamically seeded random number generator. This makes sure the outcome is always the same when run with the same arguments. p is just a simple array pointer here, that gets incremented with every run of the function, up to a maximum of y: the left argument. Every time this code is executed, a list of y random numbers is generated (to comply with the rules). Yes, I do realize this is very much on the edge of the phrasing of the question and that it is most likely against the spirit of the question.

Python
Edit
Since the approach below does not satisfy the criterion, I give an even simpler method Full Cycle, which always produces a full cycle:
def generatePeriodic(seed, period):
    x = seed
    increment = findSmallestCoPrime(period)
    while True:
        x = (x + increment) % period
        yield x

This method always yields all values from [0, period - 1] and then repeats itself. Here findSmallestCoPrime is a function that returns the smallest prime p for which gcd(p, period) = 1 holds.
Previous approach
def generate(seed):
    a = 2 * 5 * 7 + 1
    c = 1
    m = 2 * 5 * 7 * 7
    x = seed % m
    while True:
        yield x
        x = (a * x + c) % m

This is a basic Linear congruential generator, with a period m. m is in this case 490.
The restrictions are:

0 < m
0 < a < m
0 <= c < m
0 <= seed < m

Linear congruential generator has full period for all seed values if and only if:

c and m are coprime,
a - 1 is divisible by all prime factors of m, and
a - 1 is a multiple of 4 if m is a multiple of 4.

With the following, we can choose (almost) any period m, and modify the code accordingly. We always choose c = 1, to satisfy the first point. Then we factorize m = p_1 ^ k_1 * p_2 ^ k_2 * ... * p_n ^ k_n, and we set a = p_1 * p_2 * ... * p_n + 1. So we satisfy the second point. Finally, if m % 4 == 0 we set a new value to a = 2 * (p_1 * p_2 * ... * p_k) + 1 (here note, that (p_1 * p_2 * ... * p_n) % 2 == 0). With this, we satisfy the third point (and the second point is still satisfied).
The only values of m that can not generate a Linear congruential generator are of type: m = 4 * p_1 * p_2 * ... p_n, where p_i != 2. This is because in such cases we get a = m + 1, which violates the second point of restrictions.

m, the period, should be the input parameter, not a fixed value!

Sure, I added the description on how to do this, but will update my answer.

Yeah, but your job is to program this stuff, so that a user don't have to do some calculations before using your program. Also you wrote: "almost any period". The OP asked for every period.

source: Stack Exchange

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/3.0/

sort: votes


text:
Build an ASCII Fibonacci Clock
Someone built a really fancy clock using Fibonacci numbers, which looks really nice but is fairly unusable. Just the way we like it! Let's recreate this.
The clock is made up of 5 sections corresponding to the first five Fibonacci numbers, starting from 1 (i.e. 1, 1, 2, 3, 5):
ccbeeeee
ccaeeeee
dddeeeee
dddeeeee
dddeeeee

The clock is capable of displaying the 12-hour time in increments of 5 minutes. Here is how that works. Consider the time 7:20. The hour 7 can be decomposed into the given Fibonacci numbers as
7 = 2 + 5

There are also 4 units of five minutes. The 4 can be decomposed as
4 = 2 + 1 + 1

Now the hours are shown in red, the minute chunks in green, and if a number is used for both hours and minutes it's shown in blue. If a number isn't used at all, it remains white. So the above would be shown as:
BBGRRRRR
BBGRRRRR
WWWRRRRR
WWWRRRRR
WWWRRRRR

But wait, there's more. The above decompositions aren't the only possibilities. One can also write 7 = 3 + 2 + 1 + 1 and 4 = 3 + 1, which would give one of
GGRWWWWW          GGBWWWWW
GGBWWWWW          GGRWWWWW
BBBWWWWW    or    BBBWWWWW
BBBWWWWW          BBBWWWWW
BBBWWWWW          BBBWWWWW

depending on which 1 is chosen. Of course there are other combinations as well. The clock chooses from all valid decompositions at random.
As I said... this might not win a usability award, but it sure is nice to look at.
The Challenge
Your task is to implement such a clock. Your program (or function) should print an ASCII representation of the current time (rounded down to the last multiple of 5 minutes) as described above to STDOUT or closest alternative. You may choose to read the time in any common format as input or obtain it with standard library functions. You must not assume that the current/given time is divisible by 5 minutes.
Your solution must choose randomly from all possible representations of the current time. That is each representation must be printed with non-zero probability.
Midnight and noon should be treated as 0:00 (as opposed to 12:00).
You may optionally print a single trailing newline character.
You may use any four distinct printable ASCII characters (character codes 0x20 to 0xFE) in place of RGBW. Please state your choice in your answer and use it consistently.
This is code golf, so the shortest answer (in bytes) wins.

(a) can we assume that the input follows the 12=0 rule? (b) does the output have to be in that orientation, or can we rotate it?

@sirpercival a) Yes, I think that counts as "any common format". b) It has to be the orientation given in the challenge.

This challenge spawned the unfortunate verb "fibclocking."

What's the motivation for midnight/noon being 0 instead of 12? The first five numbers in the sequence add up to 12 exactly.

@BrianJ I just wanted to choose one to make it consistent and happened to pick zero. It shouldn't really affect solutions too much anyway. I figured this choice would make things simpler because the minutes also have a 0..11 range.

CJam, 61 bytes
l~5/]:A{;L[TT][XXYZ5]{4mr_2bW%Mf*@.+\Ps=M*aM*@+W%z\}fMA=!}gN*

Takes two space-separated integers via STDIN, and uses 3.14 instead of WRGB respectively. Try it online.
Here is the "sane" RGBW version for a few extra bytes:
l~5/]:A{;L[TT][XXYZ5]{4mr_2bW%Mf*@.+\"WRGB"=M*aM*@+W%z\}fMA=!}gN*

Explanation
The algorithm is the same as my Python answer — rejection sampling by generating clocks until we get one that's correct.
l~5/]:A            Read input and make array [<hours> <minutes>/5]
{...}g             Do...

  ;                  Pop the only element on the stack
  L                  Push empty array, which will become our clock
  [TT]               Push [0 0] for [h m], to keep track of our sample
  [XXYZ5]{...}fI     For I in [1 1 2 3 5]...
    4mr                Push random number from [0 1 2 3]
    _2bW%              Copy and get reversed base 2 rep for one of [0] [1] [0 1] [1 1]
    If*                Multiply bit(s) by I
    @.+                Add element-wise to [h m] array
    \Ps=               Index the random number into stringified pi for one of "3.14"
    I*aI*              Make into I by I square
    @+W%z\             Add above clock and rotate clockwise

  A=!              ... while the resulting clock is incorrect
N*                 Riffle clock with newlines

Python 2, 194 182 bytes
from random import*
h=m=H,M=input()
while[h,m]!=[H,M/5]:
 h=m=0;s=[]
 for n in 1,1,2,3,5:c=randint(0,3);h+=c%2*n;m+=c/2*n;s=zip(*(["WRGB"[c]*n]*n+s)[::-1])
for L in s:print"".join(L)

The algorithm is just rejection sampling, so it keeps generating clocks until it gets one that's right. The clock is built by starting with nothing, then doing "add a square above and rotate clockwise" 5 times.
Takes two comma-separated integers via STDIN.
>>> ================================ RESTART ================================
>>>
7,17
BBBWWWWW
BBRWWWWW
RRRWWWWW
RRRWWWWW
RRRWWWWW
>>> ================================ RESTART ================================
>>>
7,17
GGBRRRRR
GGRRRRRR
WWWRRRRR
WWWRRRRR
WWWRRRRR

Python 2, 421 bytes
Ugh, I'm sure this can be golfed more.
from itertools import*
from random import*
f,r=[1,1,2,3,5],range
c={_:[x for x in chain(*[combinations(f,i)for i in r(6)])if sum(x)==_]for _ in r(13)}
k=[[2,1,4],[2,0,4]]+[[3,4]]*3
def b(h,m):
 o=['W']*5;m/=5;h,m=choice(c[h]),choice(c[m])
 l=dict(zip(zip('WWR',[m,h,m]),'GRB'))
 for x in h,m:
    d={1:[0,1],2:[2],3:[3],5:[4]}
    for _ in x:j=d[_].pop();o[j]=l[o[j],x]
 print'\n'.join([''.join(o[i]*f[i]for i in _)for _ in k])

Test case:
>>> b(7,20)
WWBRRRRR
WWRRRRRR
GGGRRRRR
GGGRRRRR
GGGRRRRR
>>> b(7,20)
RRBWWWWW
RRRWWWWW
BBBWWWWW
BBBWWWWW
BBBWWWWW

@Optimizer now we just have to get IDL into the google prettify system so i can get IDL syntax highlighting XD

Ruby, 286 bytes
It may be golfable, but will try some other time.
z=[]
13.times{z<<[]}
(0..5).to_a.permutation{|p|l=p.take_while{|n|n<5};z[l.map{|n|[1,1,2,3,5][n]}.reduce(0,:+)]<<l}
t=Time.now
h,m=z[t.hour%12].sample,z[t.min/5].sample
5.times{|y|puts (0..7).map{|x|a=(x>2?4:y>1?3:x<2?2:y<1?1:0);q=m.include?(a);h.include?(a)?q ? ?B:?R: q ??G:?W}*""}

Explanation:
z=[]
13.times{z<<[]}                 # Initialize the array where we will have all the combinations
(0..5).to_a.permutation{|p|     # Get all the permutations of the 5 positions plus a 5, which will be used as a separator
    l=p.take_while{|n|n<5};     # Get the permutation until the separator. This way we get all the possible sum combinations of the other five numbers
    z[l.map{|n|[1,1,2,3,5][n]}.reduce(0,:+)]<<l}     # Add the permutation to the list with id=the permutation's sum

t=Time.now # Get current time
h,m=z[t.hour%12].sample,z[t.min/5].sample     # For the hour and the minute, get a random permutation that has the expected sum
5.times{|y|                 # For each row
    $><<(0..7).map{|x|      # For each column
        a=(x>2?4:y>1?3:x<2?2:y<1?1:0);     # Get the panel we are in
        q=m.include?(a);h.include?(a)?q ? ?B:?R: q ??G:?W     # Get the color this panel is painted
    }*""}                   # Join the string and print it

You can replace (0..5).to_a with [*0..5]

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/3.0/


text:
Non-crossing X's and crossing non-X's
You should write a program or function which given a text as input outputs or returns the sum of the following three integers:

Number of lowercase x's which are not part of a cross-formation.
Number of uppercase X's which are not part of a cross-formation.
Number of cross-formations which are made of neither x nor X.

A cross-formation is 5 copy of the same character positioned to each other in the following manner:
  A A
   A
  A A

Cross-formations can overlap with each other.
Detailed example
Input:
x-x+x+X++
-x-x+x++asd
x-x+x+X+

Info:
There is 1 x and 2 X's not in cross-formation and
there are 2 cross-formations of +'s as shown here:
   + +X+
    +x+
   + +X+

Output:
5

Input

A string containing only printable ascii characters (codepoint 32-126) and newlines.
The string will contain at least one printable character.

Output

A single positive integer, the sum of the number of occurrences for the three property.

Examples
After each output the values of the 3 properties (x's, X's and crosses) are provided in parens but note that those are not part of the output.
Input:
a
Output:
0 (0,0,0)

Input:
x xxx
 X x
x xxx
Output:
5 (4,1,0)

Input:
########
#####
########
Output:
4 (0,0,4)

Input:
a-a-a
0a0a
a-a-axXxX
0a0a
a-a-a
Output:
9 (2,2,5)

Input:
a c efghi
ab defgh
a c e ghij
abcd fgh
abc e g
Output:
2 (0,0,2)

Input:
/\/\/\/\/\/\/\
\/\/\/\/\/\/\/
#####x-x+x+X++
#####-x-x+x++###XX
#####x-x+x+X+
/\/\/\/\/\/\/\
\/\/\/\/\/\/\/
Output:
10 (1,4,5)

Input:
xxxxxxxxxx
xxxxxxxXX
xxxxxxxxxx
xxxxxxxxxx
xxxxxxxxxx
xxxxxxxx
Output:
5 (3,2,0)

This is code-golf so the shortest entry wins.

Example 4 contains 2 cross formation of printable character codepoint 32 (space) that are not counted in output. Do spaces count?

@edc65 i think space isnt allowed as counted for a cross , but i had similar question about if the line must be filled up with spaces until a newline , my work ll be based on positive assumption .

@edc65 Spaces do count, sorry about the incorrect example. :/ Corrected it.

so this s whole different thing , :S

@Agawa001 The lines are not necessary of equal lengths as you can see in the examples.

i was talkin about space bars , that wuld extend a line to similar size , but now everything is clear , too late thu , imust redo my code from beginning :(

No vote on any answers? Did we get somethign wrong?

@edc65 Don't think so. I guess I was waiting for some more submissions to go through them and upvote at one run but the more submissions part never happened. :)

JavaScript (ES6) 234 246
Longer than I expected ...
Run snippet to test (in Firefox)

// Golfed

F=t=>t.split('\n').map((r,j,t)=>(
  [...r].map((c,i)=>(
    f=c==r[i+2]&c==u[i+1]&c==v[i]&c==v[i+2],
    c!='x'&c!='X'?z+=f
    :(++z,f?k[j+[,i]]=k[2+j+[,i]]=k[1+j+[,i+1]]=k[j+[,i+2]]=k[2+j+[,i+2]]=1:0)
  )),v=u,u=r),
k={},u=v=z=0)&&z-Object.keys(k).length

// Ungolfed

U=t=>{
  var k={}, u=0,v=0,z=0, t=t.split('\n')
  t.forEach((r,j)=> {
    [...r].forEach((c,i)=> {
      x = c=='x'|c=='X' // is any X
      f = c==r[i+2] & c==u[i+1] & c==v[i] & c==v[i+2] // is in a formation
      if (x)
      {
        ++z
        if (f)
        { // remember the position of X involved in a formation, avoid counting duplicates more tha once
          k[j+[,i]]=k[2+j+[,i]]=k[1+j+[,i+1]]=k[j+[,i+2]]=k[2+j+[,i+2]]=1
        }
      }
      else
      {
        z+=f
      }
    })
    v=u,u=r
  })
  return z-Object.keys(k).length
}

// TEST

Out=s=>OUT.innerHTML=OUT.innerHTML + s;

['a','a a\n a\na a','x xxx\n X x\nx xxx', 'x-x+x+X++\n-x-x+x++asd\nx-x+x+X+'
,'########\n#####\n########','a-a-a\n0a0a\na-a-axXxX\n0a0a\na-a-a'
,'a c efghi\nab defgh\na c e ghij\nabcd fgh\nabc e g'
,'/\\/\\/\\/\\/\\/\\/\\\n\\/\\/\\/\\/\\/\\/\\/\n#####x-x+x+X++\n#####-x-x+x++###XX\n#####x-x+x+X+\n/\\/\\/\\/\\/\\/\\/\\\n\\/\\/\\/\\/\\/\\/\\/'
,'xxxxxxxxxx\nxxxxxxxXX\nxxxxxxxxxx\nxxxxxxxxxx\nxxxxxxxxxx\nxxxxxxxx']
.forEach(t=>Out(t+'\n'+F(t)+'\n\n'))
b { color: #00f }

C (562 b)

Golfed Code:
int main(){wchar_t *q,*y,*w,*b,a[50][50];int l,c,t,i,j,u,v,h,s,x,r;l=c=i=0;do l=(t=wcslen(q=_getws(a[i++])))>l?t:l;while(t);for(j=0;j/l<i-1;j++)c+=(x=((t=*(b=a[u=j/l]+(v=j%l)))==120|t==88|t==344|t==376))&(s=(((t&(h=0xff))!=(*(b+2)&h))|((t&h)!=(*(w=a[u+1]+(v+1))&h))|((t&h)!=(*(y=a[u+2]+v)&h))|((t&h)!=(*(y+2)&h))))?(t==(t&h)):(x?0*(*b=*(b+2)=*w=*y=*(y+2)=(t+256)):(((t&h)==(*(b+2)&h))&((*w&h)==(*y&h))&((*(y+2)&h)==(*y&h))&((*y&h)==(t&h))?(r=(t==(t&h))+(*(b+2)==(t&h))+(*w==(t&h))+(*y==(t&h))+(*(y+2)==(t&h)))+0*(*b=*(b+2)=*w=*y=*(y+2)=t+256):0));printf("%d",c);}

unpacked Code:
#include <stdio.h>
#include <conio.h>
#include <string.h>
int main(){
wchar_t *q,*y,*w,*b, a[50][50];int l,c,t,i,j,u,v,h,s,x,r;l=c=i=0;
do
l=(t=wcslen(q=_getws(a[i++])))>l?t:l;
while (t);
for(j=0;j/l<i-1;j++)
c+=(x=((t=*(b=a[u=j/l]+(v=j%l)))==120|t==88|t==344|t==376 ))&(s=(((t&(h=0xff))!=(*(b+2)&h))|((t&h)!=(*(w=a[u+1]+(v+1))&h))|((t&h)!=(*(y=a[u+2]+v)&h))|((t&h)!=(*(y+2)&h))))?(t==(t&h)):(x?0*(*b=*(b+2)=*w=*y=*(y+2)=(t+256)):(((t&h)==(*(b+2)&h))&((*w&h)==(*y&h))&((*(y+2)&h)==(*y&h))&((*y&h)==(t&h))?(r=(t==(t&h))+(*(b+2)==(t&h))+(*w==(t&h))+(*y==(t&h))+(*(y+2)==(t&h)))+0*(*b=*(b+2)=*w=*y=*(y+2)=t+256):0));
printf("%d",c);getch();
}


text:
METAscii Code Golf
Introduction
Here at code colf SE, we appear to love meta-problems. Here, I've tried to compose a meta-problem that's an interesting, not-straightforward challenge.
Challenge
The answer code is allowed to read its own source code, but not allowed to use external resources.
All characters should be 5-lines tall. Characters used in the ascii representation are also not important, though they must be visible. Each visible character in the output will count as one byte, regardless of cheaty byte-values. Spaces used in the code are necessary, and may be only one byte wide if desired.
Lowest Byte Count of the output wins. Output must exist and include at least 1 visible byte.
Example Input and Output
Input:
For an example code:
print theanswer

One possible answer is:
Output:
PPPP  RRRR  III N   N TTTTTT  TTTTTT H  H EEEE   AA  N   N  SSS  W     W EEEE RRRR
P   P R   R  I  NN  N   TT      TT   H  H E     A  A NN  N S     W     W E    R   R
PPPP  RRRR   I  N N N   TT      TT   HHHH EEE   AAAA N N N  SSS  W  W  W EEE  RRRR
P     R R    I  N  NN   TT      TT   H  H E     A  A N  NN     S  W W W  E    R R
P     R  RR III N   N   TT      TT   H  H EEEE  A  A N   N SSSS    W W   EEEE R  RR

The alphabet used should consist of the following patterns, the characters used are not important:
:
 AA  BBBB   CCC DDD  EEEE FFFF  GGG  H  H III     J K  K L    M   M N   N  OOO  PPPP   QQQ   RRRR   SSS  TTTTTT U   U V     V W     W X   X Y   Y ZZZZZ
A  A B   B C    D  D E    F    G     H  H  I      J K K  L    MM MM NN  N O   O P   P Q   Q  R   R S       TT   U   U V     V W     W  X X   Y Y     Z
AAAA BBBB  C    D  D EEE  FFF  G  GG HHHH  I      J KK   L    M M M N N N O   O PPPP  Q   Q  RRRR   SSS    TT   U   U  V   V  W  W  W   X     Y     Z
A  A B   B C    D  D E    F    G   G H  H  I  J   J K K  L    M   M N  NN O   O P     Q  Q   R R       S   TT   U   U   V V    W W W   X X    Y    Z
A  A BBBB   CCC DDD  EEEE F     GGG  H  H III  JJJ  K  K LLLL M   M N   N  OOO  P      QQ Q  R  RR SSSS    TT    UUU     V      W W   X   X   Y   ZZZZZ

 11   22  333  4  4 5555   6   77777  888   9999  000       //!!!  @@@   # #  %   %%  ^^   &&    ((  ))
111  2  2    3 4  4 5     6       7  8   8 9   9 0  00     // !!! @   @ #####    %%  ^  ^ &  &  ((    ))
 11    2   33  4444 555  6666    7    888   9999 0 0 0    //  !!! @  @@  # #    %%         &&& &((    ))
 11   2      3    4    5 6   6   7   8   8    9  00  0   //       @     #####  %%         & & & ((    ))
11l1 2222 333     4 555   666    7    888    9    000   //    !!!  @@@   # #  %%   %       &&&&  ((  ))   ____

For other characters, the equivalent produced by this generator using the 'Alphabet' font will be acceptable.   If the output generated by the tool is more than 5 characters tall, use the central 5 characters for output.
Edit - I've allowed the program to read its own source code to possibly open this question up to interesting answers.

You should precisely describe the "font" to be used, otherwise you'll have lots of people deciding separately whether W needs to be 6 or 5 or fewer columns wide, etc.

Commonly these types of problems forbid a program from reading its own source code (or external resources and such). Is this the case here, and if so can you specify so in the problem.

Are spaces necessary, I don't see them in the example?

So we can no longer just use *?

edited for these questions- spaces existing in the code are necessary and can be as small as one bit wide. You can use any character in place of the alphanumerics used in the font.

@ThomasCleberg The A looks like it's missing a space on the first line (AA would look better than the current AA  )

Ew... the $ generated by the linked page is 7 lines tall instead of 5. :(

Does the middle 5 lines of that character seem like a reasonable solution?

Seems reasonable to me!

Edited to include these instructions.

Here's another odd one: underscore is four blank lines followed by two lines of four underscores (and no trailing space).

Let's call that one 4 underscores at the bottom of a 5x4 block. I will edit it into the description when at a computer.

No- boring loopholes are boring.

Also, specifically has to have at least one visible character in the output as specified.

I didn't (and still don't) see the 1 in the output. Please note that spaces are significant characters in the output and must be represented as well :)  Interesting loopholes are interesting!

Ah, I see it now. This is a valid answer once the spaces involved are represented in the output (by an at-least 1w,5h set of spaces per space in the source), and likely close to an optimal solution, though ^ and L use fewer characters in the output. White space is not included in the score calculation, but is required in the output.

Whitespace's winning

Python 2, 2142 bytes
Should work, it's pretty confusing to read the output.
n=["","","","",""]
t=["EEEE","E  E","EEE ","E   "," EE "," E "," EEE ","E   E","E    ","  EE  ","EEEE "," EEEE","   ","EEE","     ","EE EE","    "]
e=[[t[4],t[1],t[0],t[1],t[1]],[t[2],t[1],t[1],t[1],t[2]],[t[0],t[3],t[2],t[3],t[0]],[t[0],t[3],t[2],t[3],t[3]],[t[6],t[8],"E  EE",t[7],t[6]],["EEE",t[5],t[5],t[5],"EEE"],[t[3],t[3],t[3],t[3],t[0]],[t[7],"EE  E","E E E","E  EE",t[7]],[t[6],t[7],t[7],t[7],t[6]],[t[10],t[7],t[10],t[8],t[8]],[t[10],t[7],t[10],"E E  ","E  EE"],[t[6],"E    ",t[6],"    E",t[6]],["E"*6,t[9],t[9],t[9],t[9]],[t[4],t[2],t[4],t[4],t[0]],[t[4],t[1],"  E "," E  ",t[0]],[t[2],"   E",t[4],"   E",t[2]],[t[1],t[1],t[0],"   E","   E"],[t[0],t[3],t[2],"   E",t[2]],["  E  "," E   ",t[10],t[7],t[6]],["EEEEE","   E ","  E  ","  E  ","  E  "],[t[6],t[7],t[6],t[7],t[6]],[t[11],t[7],t[11],"   E ","  E  "],[t[6],"E  EE","E E E","EE  E",t[6]],["EE    "," EE   ","  EE  ","   EE ","    EE"],[t[12],t[13],t[12],t[13],t[12]],[t[0],"EE  ","EE  ","EE  ",t[0]],[t[0],"  EE","  EE","  EE",t[0]],[t[15],t[15],t[14],t[14],t[14]],["  ","  ","  ","  ","EE"],[" EE","EE ","EE ","EE "," EE"],["EE "," EE"," EE"," EE","EE "],[t[12],t[5],t[13],t[5],t[12]],[t[16],t[16],t[16],t[16],t[0]],["  ","EE","  ","EE","  "],["  ","EE","  ","EE"," E"]]
def s(i):
 if i==" ":r()
 if i=="a":g(e[0])
 if i=="d":g(e[1])
 if i=="e"or i=="E":g(e[2])
 if i=="f":g(e[3])
 if i=="g":g(e[4])
 if i=="i":g(e[5])
 if i=="l":g(e[6])
 if i=="n":g(e[7])
 if i=="o":g(e[8])
 if i=="p":g(e[9])
 if i=="r":g(e[10])
 if i=="s":g(e[11])
 if i=="t":g(e[12])
 if i=="1":g(e[13])
 if i=="2":g(e[14])
 if i=="3":g(e[15])
 if i=="4":g(e[16])
 if i=="5":g(e[17])
 if i=="6":g(e[18])
 if i=="7":g(e[19])
 if i=="8":g(e[20])
 if i=="9":g(e[21])
 if i=="0":g(e[22])
 if i=="\\":g(e[23])
 if i=="=":g(e[24])
 if i=="[":g(e[25])
 if i=="]":g(e[26])
 if i=="\"":g(e[27])
 if i==",":g(e[28])
 if i=="(":g(e[29])
 if i==")":g(e[30])
 if i=="+":g(e[31])
 if i=="_":g(e[32])
 if i==":":g(e[33])
 if i==";":g(e[34])
 r()
def g(p):
 for i in range(5):n[i]+=p[i]
def r():g([" "," "," "," "," "])
for l in open(__file__).read().split("\n"):
 for i in l:s(i)
 print"\n".join(n);n=["","","","",""]

Output is 47965 bytes.
Can probably be golfed a lot more.
The code above uses half of the alphabet, all numbers and some symbols/special characters. I used the letter E for the output.
The characters are a list of five strings, each for one line. Also, to save a few bytes, there's a list with common lines ("EEEE", "E  E", etc.)
The , has two lines, and one of them is below most characters, so I only included the upper one (same for underscore).

Perl 5, 266
34721 bytes code, 177815 total bytes of output, 266 bytes of which are non-whitespace.
eval'                                                                                '=~s' +\t'chr length$&'ger
Based on the scoring confirmed by @Thomas Cleberg, something like this is likely optimal, but feels a little cheaty. This encodes a program that prints the desired output as space and tab characters, which are replaced with the result of running ord on the length of each run (spaces, terminated by a tab). To cater for this in the output, each tab is represented with two spaces (over the five lines) and all spaces are shown as described above.
TIO limits the output to 128KiB so you can't see it all there, but if you run this program locally, it should work as expected. Something like:
perl -M5.010 metascii-code-golf.pl > metascii-code-golf.txt

and view metascii-code-golf.txt in a text editor with word-wrap disabled.
Try it online!

Better late than never! Nevertheless, very great answer!

@Dada thanks! I'm hoping to get the output down further as I've really enjoyed this challenge. Sad I missed it when it was first posted, but glad I caught it when it was updated recently!


text:
Tile the plane with this modified circle
Take a unit circle centered on the origin. In any two neighboring quadrants, mirror the curve of the circle across the lines connecting the circle's x and y intercepts.
With the resulting shape, you can tile the plane:

I made this image with the awesome 2D physics sandbox Algodoo!
Write a program that outputs an image similar to this one in some common lossless image file format. You may save the image as a file with the name of your choice or you may simply display it. No input should be taken.
Rules:

The entire image must be tessellated with the modified-circle tiles using any two visually distinct RGB colors: one for the vertically pointing tiles, one for the horizontally pointing tiles.
The radius of the circle tiles should be at least 32 pixels. (The radius in the image above is about 110 pixels.)
The image should be at least 4 tiles wide and 4 tiles tall. This, combined with the rule above, means that images can have a minimum size of 256×256 pixels. (The image above is 4 tiles by 4 tiles.)
The tessellation may be translated by any amount. For example, the top left corner of the image does not need to be the vertex where tiles meet. (The tessellation should not be rotated, however.)
You may use external graphics libraries that have commands for drawing circles and outputting images and the like.
The curves really should approximate circles, as can done with the midpoint circle algorithm, which most graphics libraries will do for you.
Anti-aliasing around the edges of the tiles is allowed but not required.

The shortest submission in bytes wins.

gs2, 49 bytes
50 31 05 0d 1f 2a 48 0a 1e 2e 40 83 2c e8 64 2d
1e 73 ed 1e 33 40 20 30 9a a2 22 e8 e9 40 20 30
9a 30 40 20 30 ee 40 20 30 12 32 e9 12 32 55 e8
2b

Generates a PBM image:

Mnemonics:
# Print header
"P1" space 256 double
2dup new-line

# Make 1/4 circle
64 range dup cartesian-product
square m1 sum sqrt 64 >= m6
64 /

# Make tile
dup reverse + transpose
@2 not m1 m2
dup reverse + transpose
+

# Make quarter of image
dup reverse + z1
dup reverse +

# Loop
2 * m2
2 *

# Format
show-words m1
unlines

POV-Ray, 199 163
Old version
camera{location -9*z}light_source{-9*z}#declare L=union{#for(X,-9,9,2)#for(Y,-9,9,2)cylinder{X*x+x+Y*y,<.001*pow(-1,(X+Y)/2),0,.1>+X*x+x+Y*y,1}#end#end}object{L pigment{color x}}object{L rotate z*90}

Same output, but golfed down further by using default light/camera, so I dont even need to specify them
#declare L=union{#for(X,-9,9,2)#for(Y,-9,9,2)cylinder{<X+1,Y,9>,<.001*pow(-1,(X+Y)/2),0,.1>+<X+1,Y,9>,1}#end#end}object{L pigment{color rgb x}rotate z*90}object{L}

I am using as many default parameters for camera and lightsource as possible, thats why it is a little dark. Lets ungolf it first
camera{location 9*z look_at 0}
light_source{9*z color 1}
#declare L=union{
    #for(X,-9,9,2)
        #for(Y,-9,9,2)
            cylinder{<1+X,Y,0>,                                 //central axis, start
                     <1+X,Y,0> + <.001*pow(-1,(X+Y)/2), 0, .1>, //central axis, end
                      1}                                        //radius
        #end
    #end
}
object{L pigment{color x}} // x is the <1,0,0> vector, here interpreted as RGB
object{L rotate<0,0,90>}

It is obvious what is happening once we increase the offset of the cylinder axis and change the perspective

Won't the edges be slightly distorted thanks to 3d perspective?

With a height of 0.1 and an offset of 0.001 the disk is tilted by $\phi=\arctan(0.01) = 0.57°$, looking from the top the disks appear squeezed by a factor of $\cos(\phi) = 0.99995$, thats far less than a pixel.

@DenDenDo is pov-ray not able to put a camera at infinity?

@Random832 it can, with camera{orthographic location -9z}. But since the scene is basically 2D it makes no difference, you can even render it with a viewing angle 170 without any fisheye distortion in the result.

Gnuplot, 182
I noticed that the boundaries between the cells look very sinusoidal, so i went for an analytical solution with a very simple core equation

set view map
set isosamples 900
f(x,y)=.3*sin(x*3.14)+y
splot(ceil(f(x,y))+ceil(f(y,x)))%2?1:NaN   #can only modulo integers

While it looks similar, the circles are way too square. With the same idea, I replace sin by a curve made from concatenated quartercircle-arcs and rotate it 45° by replacing x and y with x+y and x-y
set view map
set samples 800
set isosamples 800
d=.5**.5
c(x,k)=(-1)**k*sqrt(1-(x-d*(1+2*k))**2)-(-1)**k*d  # k-th circle arc
# s(x)=c(x,floor(x/d/2))                           # circlified sinus
# f(x,y)=d*s(x/d)+y
f(x,y)=d*c(x/d,floor(x))+y                         # combined commented functions
splot(ceil(f(x+y,x-y))+ceil(f(x-y,x+y)))%2?1:NaN

Context Free, 99 bytes
startshape d CF::Tile=[s 4]CF::Symmetry=CF::pmg,0,1,0path d{ARCTO(-1,1,1)ARCTO(1,1,-1)ARCTO(0,0,1)}

You can see the result at the Context Free Gallery.

Nice one, that's an amazing use of Context Free. :)

HTML+JavaScript, 277
<canvas id=C></canvas><script>r=50,C.width=C.height=9*r,T=C.getContext('2d');
for(f=1,P=Math.PI,i=0;i<45;f=-f,i+=i&7?1:2)x=2*r*(i%8-2),y=2*r*(i>>3),T.moveTo(x,y+f*r),
T.arc(x+r,y+f*r,r,P,-f*P/2,f<0),T.arc(x,y,r,0,P,f>0),T.arc(x-r,y+f*r,r,-f*P/2,0,f<0);
T.fill()</script>

To test, save as html file and open with a browser. Or else, run the snippet

r=50,C.width=C.height=9*r,T=C.getContext('2d')
for(f=1,P=Math.PI,i=0;i<45;f=-f,i+=i&7?1:2)
  x=2*r*(i%8-2),y=2*r*(i>>3),
  T.moveTo(x,y+f*r),
  T.arc(x+r,y+f*r,r,P,-f*P/2,f<0),
  T.arc(x,y,r,0,P,f>0),
  T.arc(x-r,y+f*r,r,-f*P/2,0,f<0)
T.fill()
<canvas id=C></canvas>

Due to popular demand, here is the output image. Not so exciting after all...

You may want to post an image so the code doesn't have to be run each time someone wants to see the output.

@Calvin'sHobbies oh well it's fast enough and run in every modern browser. I'll make the image bigger instead

That's true. I thought it used => like a lot of your posts and would only work in Firefox. But no worries.

Better reason for posting an image: These snippets don't work very well on mobile :(

IDL 8.3, 201 193 183 bytes
The image is output into an IDL graphics window; I took a screenshot, below.
EDIT: thanks to @AlexA. and @Sp3000 for helping me shave some bytes
p=!pi/99*[0:99]
q=p[49:0:-1]
o=p[99:50:-1]
window,xs=(ys=400)
for i=0,24 do cgpolygon,i mod 5*100+50*[cos(p),cos(q)-1,cos(o)+1],i/5*100+(-1)^i*50*[sin(p),sin(q)-1,sin(o)-1],/d,/fi
end

Mathematica: 86 bytes (or 82 bytes)
Thanks to the infinite @alephalpha for a clever array-based method:
Image@ArrayFlatten@Array[DiskMatrix@32~RotateLeft~32/.a_/;OddQ@+##:>1-Thread@a&,{5,5}]

Inside the array is an anonymous function, which uses a clever trick to add its arguments (+##) and determine whether the sum is odd.  That boolean is used as the conditional to a pattern that replaces the whole 'white' tile with the transformed, 'black' tile.  From there, ArrayFlatten joins together the tiles and Image displays them.
Note the use of the shorter Thread to replace Transpose.  We can still save 4 bytes by using the transpose symbol instead.
Previous: 97 bytes (or 90 bytes)
Image@ArrayFlatten@Partition[
 Join@@Table[{#,1-Transpose@#}&@RotateLeft[DiskMatrix@32,32],{13}],5]

You can reduce the number of bytes by replacing Transpose@# with the superscript-t symbol (codepoint U+F3C7, shortcut ESCtrESC).  In UTF-8 that brings the total to 90 bytes in 88 characters.

We start with DiskMatrix, which generates a binary matrix:
DiskMatrix@32 // Image

We then circular-shift the rows of the matrix to produce the unit cell for the tiling:
RotateLeft[DiskMatrix@32, 32] // Image

If the plane is a chessboard, these are the 'white' squares.  For the 'black' squares, we need to invert the colors and rotate by 90 degrees.  We can invert by subtracting from 1 (1 - 1 -> 0 and 1 - 0 -> 1), and rotate by taking the transpose:
Image /@ {#, 1 - Transpose@#} &@RotateLeft[DiskMatrix@32, 32]

If the dimensions of the image are even (like the minimum size, 4), then a tile on the right edge will be the same as the next one on the left edge.  However, adding one tile to get an odd size (5) then concatenating the rows produces a regular alternating pattern.
This suggests that we can get the full image by wrapping a single row of alternating tiles with Partition.  We use Table to make a list of 13 black/white tile pairs, and Join to flatten the list of pairs to a list of 26 tiles.  Then we Partition the list into a 5 by 5 matrix of tiles (Partition discards the trailing 26th tile):
Map[Image] /@
  Partition[
   Join @@ Table[{#, 1 - #\[Transpose]} &@
      RotateLeft[DiskMatrix@32, 32], {13}], 5] // MatrixForm

Finally ArrayFlatten turns the matrix of tile matrices into a flat matrix, and Image displays the result.
Previous: 111 bytes
Image[ArrayFlatten[{{#, #}, {#, #}}] &[
  Join[#, Reverse@#, 2] &[
   Join[1 - Transpose@#, #] &@RotateLeft[DiskMatrix[32], 32]]]]

Image@ArrayFlatten@Array[RotateLeft[DiskMatrix@32,32]/.a_/;OddQ[+##]:>1-Thread@a&,{5,5}]

Java, 550 540 508 504 bytes
This is a java applet.
import java.awt.*;public class T extends java.applet.Applet{int a=98,b=49,x,y;public void paint(Graphics g){for(x=0;x<5;x++)for(y=0;y<5;y++)a(g.create(x*a,y*a,a,a),x%2^y%2);}void a(Graphics g,int c){if(c>0){g.translate(a,0);((Graphics2D)g).scale(-1,1);}g.setColor(Color.red);g.fillRect(0,0,b,b);g.fillRect(b,b,b,b);g.setColor(Color.blue);g.fillRect(b,0,b,b);g.fillRect(0,b,b,b);g.fillArc(0,-b,a,a,180,90);g.fillArc(0,b,a,a,0,90);g.setColor(Color.red);g.fillArc(-b,0,a,a,0,-90);g.fillArc(b,0,a,a,90,90);}}

Expanded with boilerplate:
import java.awt.*;
public class T extends java.applet.Applet{
    int a = 98, b = 49, x, y; //Make these larger for better quality pictures. a = b * 2
    public void paint(Graphics g) {
        for (x=0; x < 5; x++)      //Make these larger for more tiles.
            for (y=0; y < 5; y++)  //
                a(g.create(x * a, y * a, a, a), x % 2 ^ y % 2);
    }

    void a(Graphics g, int c) {
        if (c > 0) {
            g.translate(a, 0);
            ((Graphics2D) g).scale(-1, 1);
        }
        g.setColor(Color.red);            //Change colors for nicer looking colors.
        g.fillRect(0, 0, b, b);
        g.fillRect(b, b, b, b);
        g.setColor(Color.blue);
        g.fillRect(b, 0, b, b);
        g.fillRect(0, b, b, b);
        g.fillArc(0, -b, a, a, 180, 90);
        g.fillArc(0, b, a, a, 0, 90);
        g.setColor(Color.red);
        g.fillArc(-b, 0, a, a, 0, -90);
        g.fillArc(b, 0, a, a, 90, 90);
    }
}

Applet: A small application program that can be called up for use while working in another application.
Example image:

Explanation:
This works by using a method to print each tile. Before the method is created, it is given a graphics object that uses a coordinate system centered on the upper left corner of each tile:

To create a tile, we use the following method:
void a(Graphics g, int c) {
    g.setColor(Color.red);
    g.fillRect(0, 0, b, b);
    g.fillRect(b, b, b, b);
    g.setColor(Color.blue);
    g.fillRect(b, 0, b, b);
    g.fillRect(0, b, b, b);
    g.fillArc(0, -b, a, a, 180, 90);
    g.fillArc(0, b, a, a, 0, 90);
    g.setColor(Color.red);
    g.fillArc(-b, 0, a, a, 270, 90);
    g.fillArc(b, 0, a, a, 90, 90);
}

However, every other tile must be reflected horizontally in order to produce the correct image.
To reflect a tile, we simply modify the supplied graphics object with this code:
g.translate(a, 0);
((Graphics2D) g).scale(-1, 1);

Thanks @CoolGuy for 4 bytes.

You can golf it more by declaring x and y as fields of the class:int a = 98, b = 49,x,y;

Mathematica 299 256
Wordy but it was nice to figure out.
The basic tile is r (shown below),which is a region displayed by RegionPlot.  A left-right reflection of the tile is made and joined with r.  The two tile assembled figure  is then repeated to tile the space.

a_~f~b_ := (x + a)^2 + (y + b)^2 <= 1;
a = ImageAssemble;
r = RegionPlot[(0~f~0 && y <= 0 && ! f[-1, 1]) \[Or] (0~f~2 &&
      y >= -2 && ! f[1, 1]), {x, -1, 1}, {y, -2, 0}, Frame -> False,
    BoundaryStyle -> None];
s = ImageCrop@Rasterize@r;
t = s~ImageReflect~Right;
i = a@{s, t};
j = a@{t, s};
a@{k = {i, i, i, i}, m = {j, j, j, j}, k, m, k, m}

C, 237 209 180 bytes
180 bytes. This version includes changes suggested by edc65 in a comment. It gives 9 compiler warnings when building on a Mac with clang and default options:
a,b,c,d,x,y;main(){for(puts("P1 256 256");b=a+32&64,a<256;++a){for(c=0;d=c+32&64,x=(a&64)-d?31-a&31:a&31,y=(c&64)-b?c&31:31-c&31,c++<256;)putchar(48+(x*x+y*y<962^b==d));puts("");}}

209 bytes, using some suggestions from comments by Martin. Compiles without warnings with clang:
#include <stdio.h>
int a,b,c,d,x,y;int main(){puts("P1 256 256");for(;b=a+32&64,a<256;++a){for(c=0;d=c+32&64,x=(a&64)-d?31-a&31:a&31,y=(c&64)-b?c&31:31-c&31,c<256;++c)putchar(48+(x*x+y*y<962^b==d));puts("");}}

Original version, 237 bytes:
#include <stdio.h>
int main(){puts("P1 256 256");for(int a=0;a<256;++a){int b=a+32&64;for(int c=0;c<256;++c){int d=c+32&64;int x=(a&64)-d?31-a&31:a&31;int y=(c&64)-b?c&31:31-c&31;putchar(48+(x*x+y*y<962^b==d));}puts("");}}

Result (256x256):

Original code with whitespace for better readability:
#include <stdio.h>
int main()
{
    puts("P1 256 256");
    for (int a = 0; a < 256; ++a)
    {
        int b = a + 32 & 64;
        for (int c = 0; c < 256; ++c)
        {
            int d = c + 32 & 64;
            int x = (a & 64) - d ? 31 - a & 31 : a & 31;
            int y = (c & 64) - b ? c & 31 : 31 - c & 31;
            putchar(48 + (x * x + y * y < 962 ^ b == d));
        }
        puts("");
    }
}

This does not use any graphics library, the rendering is completely contained in the code.
The basic idea is to simply loop over all 256x256 pixels, and see if they are inside/outside the circular arc of the 32x32 sub-square they are in. The bottom 5 bits of the overall pixel coordinates define the relative coordinates of the pixel within the sub-square. The inside/outside test of (x, y) being inside the arc with radius r is then the standard:
x * x + y * y < r * r

Most of the logic is for placing the center of the arc in the correct corner of the sub-square, and determining which color is inside/outside.
Some comments on the solution:

The code generates the image in the PBM ASCII format. I loaded the result into GIMP, and did a copy&paste into Paint to generate the actual file I posted here. So the format was converted, but the content is exactly as the original output.
If you look closely, you may notice that the quality is not great. This is because the inside/outside calculation is done for the corner of the pixel, instead of the pixel center, causing the whole thing to be 1/2 pixel off. I don't think it would be very difficult to do better, but it would make the code somewhat longer. And since there were not specific quality requirements, I believe this is sufficient.
Code was compiled using clang on a Mac. Latest version gives warnings, initial version did not.
This is the first time I ever attempted one of these, so I probably missed a few tricks to save the last byte possible.

Welcome to PPCG! I'm not a big C golfer, but I think I can see a few improvements: group your declarations like int a,b,c,d,x,y; ... I think you might even be able to just do main(a,b,c,d,x,y) I remember something that the default type is int. Once you're rid of that, you can move the assignments to d, x and y into the inner for's increment statement like d=c+32&64,...,++c (probably even move the ++ into some other place where you mention c anyway), and then you can omit the braces of the inner for. Nice job, btw! :)

Thanks! I saw the trick with declaring arguments without types in a list of tips, but it seemed so dirty that I couldn't get myself to go there. ;) I don't think having non-standard arguments for main() is standard compliant. I should certainly group the declarations. And moving the increments will save a couple of bytes, too. The puts() for the newline is in the outer loop, so I'm not sure if I can get rid of the braces.

We're usually okay with it as long as it compiles in some common compiler (so it doesn't have to be entirely standard C). Also yeah I don't think you can get rid of the outer braces, but you should be able, to remove the inner ones.

Got it down to 210 bytes. Thanks for the ideas.

Actually, I think the puts can go with the ++a.

Hints: stdio not needed, use default declaration of function. int is default for globals and can be omitted (variables and main). First puts can go inside the for. c var is not used inside the inner loop, so increment in condition. 180: a,b,c,d,x,y;main(){for(puts("P1 256 256");b=a+32&64,a<256;++a){for(c=0;d=c+32&64,x=(a&64)-d?31-a&31:a&31,y=(c&64)-b?c&31:31-c&31,c++<256;)putchar(48+(x*x+y*y<962^b==d));puts("");}} (compiles with many warnings but runs)


text:
Largest and smallest values from concatenated integers
This problem is from Five programming problems every Software Engineer should be able to solve in less than 1 hour which itself is an interesting read.  The first few problems are trivial, but the fourth one can be a bit more interesting.

Given a list of integers separated by a single space on standard input, print out the largest and smallest values that can be obtained by concatenating the integers together on their own line.

For example:
Input:
5 56 50

Output:
50556
56550

Various points of order:

The order of the results are smallest then largest.
Only the smallest and largest values may be printed out (iterating over all the variations and printing them out isn't valid).
There will always be two or more integers in the list.
It is possible for the largest and smallest results to be the same.  In the case of input 5 55, the number 555 should be printed twice.
The integers are not necessarily distinct. 5 5 is valid input.
Leading 0s on integers are not valid input.  You will not need to account for 05 55.

As this is code golf, shortest entry wins.

If one of the input numbers contain a leading 0 (like 05), do we consider it as 05 or simply 5 ?

@Optimizer leading zeros are not valid input.

Are leading 0s allowed in output?

@Tim Where would those come from if there are no leading zeroes in the input?

@MartinBüttner oh yes, being silly!

CJam, 14 13 bytes
qS/e!:s$(N@W=

Pretty straight forward. This is how it works:
qS/                  e# Split the input on spaces
   e!                e# Get all permutations of the input numbers
     :s              e# Join each permutation order into a single string
       $             e# Sort them. This sorts the strings based on each digit's value
        (N@W=        e# Choose the first and the last out of the array separated by '\n'

Try it online here

OK, I give up. I didn't now e! existed (doesn't even appear in the wiki yet).

@Dennis there you go

Sweet read. Lots of useful new stuff.

It might be useful to update Tips for golfing in CJam with these additional tricks.

@MichaelT tips generally are not supposed to contain answer which explain the in built features of a language. A couple of answer might need updating as they might benefit from these new features though.

Pyth, 14 13 bytes
hJSmsd.pcz)eJ

Generates all permutations and sorts them, printing the first and last element.

Assign J inline: hJSmsd.pcz)eJ

@isaacg Good one! I just knew we wouldn't be inferior to that filthy filthy CJam!

Python 2, 104 99 bytes
Yep.
from itertools import*;z=[''.join(x)for x in permutations(raw_input().split())];print min(z),max(z)

Edit: thanks to xnor for -5 bytes!

The comprehension inside sorted works without brackets, but you also can avoid sorting and just take min and max.

hah, yes. thank you!

Mathematica, 64 58 bytes
Print/@Sort[""<>#&/@Permutations@StringSplit@#][[{1,-1}]]&

This defines an unnamed function taking a string and printing the two lines. It's pretty straightforward as the others: get all permutations, join them together, sort them and print the first and last result.
Six bytes saved thanks to alephalpha.

{#&@@#,Last@#}=>#[[{1,-1}]]

@alephalpha Sometimes simpler is better. Thanks! :D

JavaScript (ES6) 54 72 85
That's easier than it seems. Just sort them lexicographically. The good news is: that's exactly how plain javascript sort works.Well ... no, that's wrong ... still a (more convoluted) lexicograph compare can do the job.
Note: having a and b numeric, a+[b] is a shortcut for a+''+b, as we need a string concatenation and not a sum.
Note 2: the newline inside `` is significant and must be counted
Edit Don't argue with a moderator (...just kidding)
Edit2 Fixed I/O format using popups (see Default for Code Golf: Input/Output methods)
// Complete program with I/O
// The sorting function is shorter as input are strings

alert((l=prompt().split(' ')).sort((a,b)=>a+b>b+a).join('')+`
`+l.reverse().join(''))

// Testable function (67 chars)
// With an integer array parameter, the sorting function must convert to string

F=l=>(l.sort((a,b)=>a+[b]>b+[a]).join('')+`
`+l.reverse().join(''))

Test In Firefox / FireBug console
F([50, 2, 1, 9])
F([5,56,50])
F([52,36,526])
F([52,36,525])
F([52,36,524]

12509
  95021
50556
  56550
3652526
  5265236
3652525
  5255236
3652452
  5252436

I think your input format is wrong. Should be "integers separated by a single space on standard input".

@nimi you're right.Fixed

J, 34 36, 42 bytes
simple brute force:
h=:3 :'0 _1{/:~;"1":&.>y A.~i.!#y'

h 5 50 56
50556
56550

h 50 2 1 9
12509
95021

Haskell, 98 bytes
import Data.List
g=sort.map concat.permutations.words
h i=unlines[g i!!0,last$g i]
main=interact h

Split input string at spaces, concatenate every permutation and sort. Print first and last element.

Julia, 77 bytes
v->(Q=extrema([int(join(x)) for x in permutations(v)]);print(Q[1],"\n",Q[2]))

This creates an unnamed function that accepts a vector as input and prints the minimum and maximum of the permutations of the joined elements. To call it, give it a name, e.g. f=v->....
Ungolfed + explanation:
function f(v)
    # Create an integer vector of the joined permutations using comprehension,
    # then get the minimum and maximum as a tuple using extrema().

    Q = extrema([int(join(x)) for x in permutations(v)])

    # Print the minimum and the maximum, separated by a newline.
    print(Q[1], "\n", Q[2])
end

Suggestions are welcome!

Javascript (ES6) 134
Sadly, there's no built-in permutation function in JS :(

f=(o,y,i,a)=>y?o.concat(a[1]?a.filter((k,j)=>j^i).reduce(f,[]).map(z=>y+z):y):(q=o.split(' ').reduce(f,[])).sort().shift()+`
`+q.pop()

<input id="input" value="5 56 50" />
<input type="button" onclick="output.innerHTML=f(input.value)" value="Run" />

R, 59 bytes
write(range(combinat:::permn(scan(),paste,collapse="")),"")

Nice work. You can save a byte by using just two colons though, i.e. combinat::permn.

I thought :: required the package to be loaded (via library or require) but not :::. I could be wrong; need to read a little more about it. Thanks.

If the library is loaded, you don't need the colons at all; you can just call the function directly since the package is attached to the namespace. If the package is installed but not loaded, you can reference functions in a particular package with two colons.

So 58 it can be. I would not allow myself using permn directly without a library(combinat).

Yeah, because you have to load the library with library(combinat) before you could use permn anyway. ;)

Ruby 75
Not my 'native' language, but one I thought I'd give a try at... thus this could (possibly) use some golfing tips. Still, not a bad entrant.
puts STDIN.read.split(" ").permutation.map{|x|x.join}.sort.values_at(0,-1)

I wouldn't say it is elegant other that everything is built in to the language.  It should be fairly obvious exactly how this works.

You can replace {|x|x.join} with (&:join) for a 3 byte savings.

A few more ruby shortcuts for 48 bytes: puts$<.read.split.permutation.map(&:join).minmax

If pattern is omitted, the value of $; is used. If $; is nil (which is the default), str is split on whitespace as if ` ‘ were specified.

gets is even shorter for reading input: puts gets.split.permutation.map(&:join).minmax

Perl, 79 70B (68+2)
use Math::Combinatorics;say for(sort map{join'',@$_}permute@F)[0,-1]
Call with echo 13 42 532 3 6|perl -M5.10.0 -an scratch.pl. There's a +2 byte penalty for -an. Shame about the length of the module name...

05AB1E, 8 bytes
#œJ{¬sθ»

Try it online.
Explanation:
#         # Split the (implicit) input by spaces
 œ        # Get all permutations of this list
  J       # Join each permutation together to a single string
   {      # Sort this list
    ¬     # Push the first item (without popping the list)
     s    # Swap to get the list again
      θ   # Pop and push its last item
       »  # And join all (both) values on the stack by newlines
          # (after which the result is output implicitly)

Scala, 90 bytes
val x=Console.in.readLine.split(" ").permutations.map(_.mkString).toSeq
print(x.min,x.max)

Try it online!

JavaScript (ES6), 85 bytes
F=a=>(c=a.split(" ").sort((b,a)=>b+a-(a+b)),`${c.join("")}
${c.reverse().join("")}`)

usage:
F("50 2 1 9")
/*
    12509
    95021
*/

Don't fall in love with template strings. a+` `+b is shorter than `${a} ${b}`

Stax, 11 bytes
ú∙n90≤╣*.vâ

Run and debug it
Link is to unpacked version of code.
Explanation
L|T{$mc|MP|mp implicit input
L             put all inputs in a list
 |T           get the unique orders of the list of inputs
   {$m        convert each list to string
      c       duplicate the array of strings
       |mP    print the minimum element
          |mp print the maximum element

Jelly, 6 bytes
Œ!VṢ.ị

Try it online!
Input and output as lists of integers. +3 bytes to input with spaces and output with newlines
How it works
Œ!VṢ.ị - Main link. Takes a list L on the left e.g. [5, 56, 50]
Œ!     - All permutations of L                      [[5, 56, 50], [5, 50, 56], [56, 5, 50], [56, 50, 5], [50, 5, 56], [50, 56, 5]]
  V    - Concatenate each into numbers              [55650, 55056, 56550, 56505, 50556, 50565]
   Ṣ   - Sort                                       [50556, 50565, 55056, 55650, 56505, 56550]
    .ị - Take the first and last elements           [56550, 50556]