text:
Pi Calculation Code Golf
The Challenge
You must calculate pi in the shortest length you can. Any language is welcome to join and you can use any formula to calculate pi. It must be able to calculate pi to at least 5 decimal places. Shortest, would be measured in characters. Competition lasts for 48 hours. Begin.

Note: This similar question states that PI must be calculated using the series 4 * (1 – 1/3 + 1/5 – 1/7 + …). This question does not have this restriction, and in fact a lot of answers here (including the most likely to win) would be invalid in that other question. So, this is not a duplicate.

Does it actually have to calculate pi? The shortest answers will cheat by just storing 3.14159 in a variable, start calculating from there, see that it is already known to 5 decimal places, and just print it.

It has to actually calculate pi and not just display a predefined variable or function containing pi.

Presumably anyone that just does 4*atan(1) should be disqualified, but it does actually calculate pi, and uses a function that does not itself contain pi.

@hvd Why do you think it should be disqualified? It fits the specs ...

@belisarius Well, if my objection is with the specs, pointing out that the specs allow it doesn't help. :) The OP's comment isn't part of the specs either, so if I find a language that allows π+0, that's a three-character answer, and the OP has already clarified that such answers are intended to be invalid. I don't really see 4*atan(1) as less of a cheat than that one.

@hvd Ok. Perhaps a better definition of "calculation" is in order hre

@hvd acos(-1). I win!

@hvd - i've seen answers , like mine that can beat a variable with 3.14159 in it

I was originally more thinking of calculating an actual equation, like the "Libenz"(I think that is how it is spelt) equation or something similar. Not just a simple calculation, however, well done for thinking outside of the box, to those who did just do simple calculation. I am unsure as to whether to pick the actual equation ones or the just simple calculation answers as the best. Anyway, there's still over 29 hours to go, so carry on!

The question that is linked (making this a supposed duplicate) state that PI must be calculated using the series 4 * (1 – 1/3 + 1/5 – 1/7 + …). This question does not have this restriction, and in fact a lot of answers here (including the most likely to win) would be invalid in that other question. So, this is not a duplicate.

Very true Victor.

@Poseidon Re: Libenz: You would have done well to put "no trig functions" in the question. However none of the three most popular answers at the moment uses a trig function, and first and third most popular (ace, jpjacobs) are among the shortest anyway. Neither of the 6 char answers uses a trig function (but one of them uses a conversion of 180 degrees.)

This looks weird, inconsistent. Calculating π has to be dividing a circle by its diameter, or some other operation giving π. If we accept doing 355/113 — which has nothing to do with π except luck —, like @ace, then logically we should accept doing 3.14159.

But @poseidon wants the solution to calculate. Let’s calculate… :-)

I don't get why people like this question. This is one of the most ill-defined and uninteresting questions I've seen on here. The only difference between this and hello world, is that this has something to do with Pi.

@Cruncher It is a simple and easy question where everyone, even with poor programming skills, can answer something acceptable in less than 10 minutes, not a hard question where I need 1 hour just to understand what I am supposed to do.

x86 Machine Language - 2 bytes The FLDPI assembly instruction translates to 0xD9EB in machine language - thus it could count as a 2-byte solution.

@poseidon Can you please add a rule that explicitly prohibits the use of built-in trigonometric functions? Seriously guys, you can't honestly believe that typing your favorite language's variant of acos(-1) is somehow in the spirit of this question (and for that matter, neither is your favorite approximate reduction of 314159 / 100000).

I just finished looking through all the answers here so far. I mean really guys, of course you can find a language that let's you call somebody else's implementation of the calculation in as few characters as possible, but how is that even remotely interesting? Saying "hey guys don't forget, language X has an atan() too" is roughly equivalent to posting a link to your favorite language's documentation. Who wants to see that? If you can't be bothered to find a solution like Yimin Rong's, don't bother.

To make this question interesting it needs a scoring function that rewards digits of pi per byte of code.

It should be obvious that almost none of these people are actually calculating pi (piet solution aside). They either use Pi as part of their solution (trig identities), or are calculating an approximation of pi. It's impossible to use their solutions to ever actually get closer than they provided to PI without already having it. Anyone arguing against is just trying to make this question boring and prohibitively easy because they don't know enough math to be creative.

@JasonC Is this a joke? This isn't a popularity contest. This is tagged code golf. Why would somebody not use the shortest code that solves the problem. That IS what code golf is. When something leads to uninteresting answers, its because of an uninteresting question (see my earlier comment).

@JasonC The question explicitly says calculate it to 5 decimal places. That is literally equivalent to saying "Make your program output 3.14159". It could potentially be much more interesting if the program had to accept the accuracy as a parameter.

@Cruncher because it doesn't actually solve the problem. The question asks you to "Calculate Pi" to 5 digits. Identities aren't calculation, you might as well go pi = 3.14159. Typing it in isn't the same as calculating it, you're merely asserting a reality. If I asked how you got it you would just shrug.

@VoronoiPotato "Calculate Pi" isn't particularly well defined. Especially saying "Calculate Pi" to 5 decimal places, means calculate an approximation. Anything the computer does is some form of computation. Again, it would be much more interesting if the program had to take accuracy as a parameter. Otherwise hardcoding is always the best solution. Programs should be formed in an input => output fashion. Restrictions on how the output is to be found, leads to questions like this.

@Cruncher you do realize that saying that because a computer did it it's some kind of computation is ridiculously reductive. Could someone with appropriate rep edit the question so that it excludes these identity driven answers.

@VoronoiPotato And invalidate the highest voted answer that was valid when it was posted? In any case, you're welcome to edit it and try to get it approved. In doing so you will arrive at the intrinsic problems here. You can't exclude a special case for everything.

@Cruncher I'd argue that it wasn't valid, because it's not a calculation it's a thinly veiled assertion. I think there's a difference from trying to exclude a special case for everything and responding to literally the first comment on the question.

@JasonC No I don't think its what the OP had in mind. It's just a bad question.

@poseidon Does it need to display the answer, or does it just need to calculate the value and store it somewhere?

Come on guys, really... no more forms of 3.14159*a/a - The only difference between 355/113 and 3.14159/1 is a=113 instead of 1; what's the cut off for a? And how many levels of algebraic identities must be present for it to count? pi is not OK but ln(e^pi) is... ? (Sorry, I deleted my first previous comment by accident, then had to delete the second due to lack of context).

Backrolled to revision 3. A competition which last 48 hours shouldn't have it's rules changed less than 8 hours before it ends. Also, @poseidon, if you tag a competition as [tag:code-golf], common courtesy would dictate that you also select the shortest answer.

@poseidon Why did you pick ace's answer? Ignoring the fact that selecting a trig function / algebraic identity answer makes this question a categorical fail, it's not even the shortest solution posted. Double fail; or maybe that's 226*fail/113.

Yup.  Level of unimpressed exceeds 9000 on this.

@Primo — Shortest does not mean nicest. In fact, it is often the opposite.

@NicolasBarbulesco Shortest is an objective winning criteria. Nicest is not.

You should have made this a  [tag:popularity-contest] at least...

Python3, 7
Runs in the interactive shell
355/113

Output: 3.1415929203539825, correct to 6 decimal places
And finally I have a solution that beats APL!
Oh, and in case you are wondering, this ratio is called the 密率 (literally "precise ratio"), and is proposed by the Chinese mathematician Zu Chongzhi (429-500 AD). A related wikipedia article can be found  here. Zu also gave the ratio 22/7 as the "rough ratio", and he is known to be the first mathematician to propose that 3.1415926 <= pi <=3.1415927

mhmh - that is actually a polyglot answer. Works in Smalltalk too!

Blasphemy! It's barely a calculation!

well, it is a division, and it's precision satisfies the requirement...
(and even the bible is less accurate; you would not label that blasphemy - would you? 3* ;-)

@blabla999 http://i.imgur.com/QlJaLdt.jpg

Holy Kruppe, this is really ingenious. And it does beat APL (unless one is using the Pi constant or Arctan.) Bravo!

This shouldn't be a serious answer... It works on paper, chalk boards, hand calculators, cellphones, google and almost every language and object you can write (if you have brains to solve this)...

@Ismael — So the more compatible an answer is, the worse it should be ?

when the answer is a joke, yes.

The awkward moment when I wrote this as a serious answer but everyone interprets it as a joke...

The ratio isn't beaten until you get to 52163/16604, and that doesn't hold for long, with 52518/16717, 52873/16830, 53228/16943, etc., being better ratios than the previous.

This answer works also in the google search. Pretty nifty!

@Yimin Rong Given that this ratio is proposed before 500 AD, and that this challenge is a code golf question, I think this ratio is pretty good.

Also works in windows calculator, and mac spotlight search lol

I really don't think people's favorite approximate simplification of 314159/100000 should count here.

Highest voted answer: 355/113. Lowest voted answer: 3+.14159. I don't see much difference, really.

This answer no longer fits the question. As it cannot be used to generate an arbitrary number of digits of pi.

@primo I believe the difference is that using 3+.14159 is too trivial (and is longer), and voters prefer an interesting solution to a boring one. I mean, even an idiot can figure out 3+.14159 as long as he knows how to add and subtract, but not many people are aware of the approximation ratio 355/113

@ace "Not many." The population considered as a whole, perhaps. Anyone who would even care, I would propose, has known about it since high school, at the latest.

@ace Not many people may be aware that it is the closest approximation with 3-digit integers, but pretty much everybody is aware that a*b/b==a, it doesn't really become more mysterious just because a is almost pi and b is 113. In your defense, though, it is the only one with 3-digit integers that is approximate to 5 decimal places.

@ace it doesn't matter because it does not fit the new requirements. 355/113 is arguably as trivial as typing 3+.14159 anyway, instead of addition you're doing division. The historical anecdote is neat, but this should have all been a comment not an answer.

@VoronoiPotato fine, if you don't like it, down vote it. Or, if you already have downvoted it, does it bug you so much when others like things you hate? I know that this currently doesn't fit the rules, when I posted it, it did.

I can't I don't have enough rep to downvote :P. It doesn't bug me much I'm just vocalizing because I feel it missed the spirit of the competition, and this wasn't the only post that exploited poor wording in the question, it's just the highest voted.

@poseidon Ignoring the fact that selecting a trig function / algebraic identity answer makes this challenge a categorical fail, this isn't even the shortest solution posted. Double fail for accepting it; or maybe that's 226*fail/113.

That answer is not pi though, you'd need to do the truncate to 5-6 digits to make it correct.

This is brilliant use of code golf. The purpose is to do it in as many chars as possible, the question should be voted down not the answer.
The question could have stated to find pi to at least 20 characters where this would not have worked

PHP — 132 127 125 124 bytes
Basic Monte-Carlo simulation. Every 10M iterations, it prints the current status:
for($i=1,$j=$k=0;;$i++){$x=mt_rand(0,1e7)/1e7;$y=mt_rand(0,1e7)/1e7;$j+=$x*$x+$y*$y<=1;$k++;if(!($i%1e7))echo 4*$j/$k."\n";}

Thanks to cloudfeet and zamnuts for suggestions!
Sample output:
$ php pi.php
3.1410564
3.1414008
3.1413388
3.1412641
3.14132568
3.1413496666667
3.1414522857143
3.1414817
3.1415271111111
3.14155092
...
3.1415901754386
3.1415890482759
3.1415925423731

Up for an answer which really computes!

Don't know about PHP, but in JS you can do something like: $j+=$x*$x+$y*$y<=1; which would save you four bytes.

Also $k+=1/4; and print $j/$k could be reduced to $k++; and print 4*$j/$k for another byte.

@cloudfeet - Changes made, confirmed code still runs the same. Thank you!

nothing mind blowing, but: using echo vs print saves you 1 byte, and <2 instead of <=1 in $j+=$x*$x+$y*$y<=1; saves you another byte. lastly, using an actual line feed instead of \n saves you yet another byte (in the src). ... +1 nice work.

@zamnuts - it's in floating point, so <=1 is required - will try echo, not sure about direct line feed, might confuse some people

What is it doing?

@MarkC - Conceptually it is throwing darts randomly in a rectangle 0,0 to 1,1. Those less than or equal to distance 1 from 0,0 are considered inside, else outside. The shape of this distance 1 happens to be a quarter circle or π/4. The [number of darts inside the quarter circle] / [total number of darts] will approximate π/4 as the number of samples increases.

J 6
{:*._1

Explanation: *. gives length and angle of a complex number.
The angle of -1 is pi. {: takes the tail of the list [length, angle]
Just for the slowly-converging-series-fettishists, for 21 bytes, a Leibniz series:
      +/(4*_1&^%>:@+:)i.1e6
 3.14159

In other words, this is atan(0) + pi. I don't think the use of trigonometric functions and pi itself should count as a "calculation".

@JasonC Arg (that is, argument of a complex number) is not a trigonometric function, despite having values similar to that of arctangent

@mniip Yes, it is. It's just a synonym for atan (well, atan2) on the real and imaginary parts. As you can see there, it is precisely equal, by definition, to atan(0) + pi.

Perl, 42 bytes
map{$a+=(-1)**$_/(2*$_+1)}0..9x6;print$a*4

It's calculates π using the Leibniz formula:

999999 is used as largest n to get the precision of five decimal digits.
Result: 3.14159165358977

This is cool! It inspired me to write one in Java 8.

TECHNICALLY I'M CALCULATING, 9
0+3.14159

TECHNICALLY I'M STILL CALCULATING, 10
PI-acos(1)

I'M CALCULATING SO HARD, 8
acos(-1)

I ACCIDENTALLY PI, 12
"3.14"+"159"

And technically, this answer stinks.

So header, much big title, very pain for my eyes, wow.

pluzz wan for much lulz, thankz

Hey baby, wanna expand my Taylor series?

http://meta.codegolf.stackexchange.com/questions/1061/standard-loopholes-which-are-no-longer-funny?cb=1

@SimonT You didn't answer my question about the Taylor series. But while you're thinking about it, see my comments on the question and most of the other answers here. :P

e^iπ = -1, so iπ = (log -1) / i

Piet, many codels
Not my answer, but this is the best solution I've seen to this problem:

My understanding is that it adds up the pixels in the circle and divides by the radius, and then once again.  That is:
A = πr²  # solve for π
π = A/r²
π = (A/r)/r

A better approach in my mind is a program that generates this image at an arbitrary size and then runs it through a Piet interpreter.
Source: http://www.dangermouse.net/esoteric/piet/samples.html

Could you explain what it actually does? (I know the general idea behind Piet but an explanation on how this particular program work would be a nice addition to your answer).

I don't really know Piet, but I think this literally measures the area of the red circle and then divides by the radius twice, solving for π = A/(r*r)

Well the area is quite clear, as when the pointer enter the red circle it counts the number of codels in the red area and push it to the stack when exiting (since the exit point is dark red, hence no hue change but one step darker), it's the "dividing by the radius squared" part that I had trouble understanding.

@plannapus I guess the radius is hard-coded?  Looks like you grok Piet 10x more than I do.

I've seen this before, it's really cool. I threw together a C implementation inspired by this here.

@plannapus The radius is "hard-coded" in the dark red line extending from the top-left corner to halfway down the left edge (it's hard to see in the image). Piet is hard to follow but the gist is blocks of color have a value equal to their area (line at left edge has r pixels, circle has area pixels), and the stuff in between is just a bunch of stack and arithmetic operations. Programs start in the top left. The text in the top right is essentially a comment.

@JasonC ah of course! The circle touches both upper and lower side so the dark red line descending from the upper side to the exact middle is necessary the radius! Smart!

 J - 5 bytes
|^._1

This means |log(-1)|.

Clever use of Euler's Identity.

Cool, another algebraic identity answer. About as clever as ln(e^(42*pi))/42 or pi*113/113.

Also works in TI-BASIC

@JasonC except that 1) it's not a simple algebraic expression, 2) it's not a trig function, and 3) the answer is not at all obvious; many programming languages would return an error. I chose to upvote this answer, because it made me stop and think about why it would even work. The examples you list of "similar" solutions, do not.

@primo Sorry, I guess I mistakenly assumed rearranging e^iπ+1=0 (you yourself recognized Euler's identity) in terms of π was more algebra. It's yet another badly-specified-question-loophole identity answer. (And it's precisely the same form as the example I gave except substitute i for 42.)

@JasonC lim n→∞ (1 + iπ/n)ⁿ = -1. I do not find this result to be obvious. ln(e^(42*π))/42 = π. I do find this result to be obvious.

@primo The evaluation of the limit you stated is Euler's identity; it's precisely e^(i*pi)+1=0... and log(-1) is a (and the only) direct algebraic solution to that identity for pi (sorry, the character isn't in my clipboard any more, ha). log(-1) is not an attempt to evaluate that limit.

(Totally unrelated, I wish we could use LaTeX on codegolf.)

(Answer to totally unrelated question, I get by with google charts, for example here.) On topic, this is the sortest answer, and thus should have been accepted.

Well, given the fact that the OP deemed these types of answers acceptable (by accepting the silly 355/113 answer), regardless of how strongly I disagree with these answers, I can definitely agree with you that this should have been the accepted one. If you really lower the bar, there's also fldpi with 5, and that TI CAS degrees-to-radians one with 4 (and another with 4 that I can't find... and I think there's a really bad 2 character one on the second page).

@Primo Well I did the same thing in a comment up there (iπ = ln -1 div i), but strictly speaking, e^iθ is a trigonometric function.

@MarkC MathWorld disagrees. Any other source you can find will also. That e^iθ = cos(θ) + i·sin(θ) does not demonstrate that the complex exponential function is a trigonometric function. You could just as well claim that since ∫1/(1+x²) = tan⁻¹(x), that integration must be a trigonometric function.

APL - 6
2×¯1○1

Outputs 3.141592654. It computes twice the arcsine of 1.
A 13-char solution would be:
--/4÷1-2×⍳1e6

This outputs 3.141591654 for me, which fits the requested precision.
It uses the simple + 4/1 - 4/3 + 4/5 - 4/7 ... series to calculate though.

Wow, that's one slow convergence!

My first thought was “why not ¯2○¯1?” (i.e acos -1). But that gives a complex approximation on repl.it (3.1415926425236J¯1.1066193467303274e¯8). Any idea why? Do all implementations do that?

+1 for your second solution. 2 * asin(1) is a bit of a cheat, though.

@JamesWood I don't know APL but if I had to guess I'd say it tried to do a sqrt(1-theta^2) (which pops up in a lot of trig identities) at some point and lost some precision somewhere, ending up with a slightly negative 1-theta^2.

What's strange is that there's still a tiny imaginary part for acos -0.75. There's no way it could calculate 1 - 0.75 ^ 2 to be negative.

@JamesWood You're right, that is weird. Huh.

Is it likely to be an implementation-dependent thing? As I said, I tested on repl.it, which uses NGN APL, which seems quite unofficial.

Octave, 31
quad(inline("sqrt(4-x^2)"),0,2)

Calculates the area of one quarter of a circle with radius 2, through numerical integration.
octave:1> quad(inline("sqrt(4-x^2)"),0,2)
ans =     3.14159265358979

Nice! +1 when my votes recharge.

Python, 88
Solution :
l=q=d=0;t,s,n,r=3.,3,1,24
while s!=l:l,n,q,d,r=s,n+q,q+8,d+r,r+32;t=(t*n)/d;s+=t
print s

Sample output in Python shell :
>>> print s
3.14159265359

Manages to avoid any imports.  Can easily be swapped to use the arbitrary precision Decimal library; just replace 3. with Decimal('3'), set the precision before and after, then unary plus the result to convert precision.
And unlike a whole lot of the answers here, actually computes π instead of relying on built-in constants or math fakery, i.e. math.acos(-1), math.radians(180), etc.

 Mathematica 6
180N@°
-->3.14159

x86 assembly language (5 characters)
fldpi

Whether this loads a constant from ROM or actually calculates the answer depends on the processor though (but on at least some, it actually does a calculation, not just loading the number from ROM). To put things in perspective, it's listed as taking 40 clock cycles on a 387, which is rather more than seems to make sense if it were just loading the value from ROM.
If you really want to ensure a calculation you could do something like:
fld1
fld1
fpatan
fimul f

f dd 4

[for 27 characters]

Can you explain, please ?

And, on some processors, what calculcation would fldpi do ?

@NicolasBarbulesco: if memory serves, it did something like 6*asin(0.5), apparently because it converges quite quickly.

I don't think using a command that loads pi (or even computes it based on somebody else's asin implementation or any existing trig function implementations at all) really counts in the spirit of "calculating" anything (the "omg assembler" factor doesn't really change that). Perhaps port this to the shortest assembler implementation possible, and it can be called a "calculation".

@JasonC: I might agree if even a significant minority of those using higher level languages were using something like an expansion of a Taylor series or some such, but virtually all of them also using predefined sin, cos, atan, sqrt, etc.

What I mean to say is, I think fldpi doesn't count in the same way the higher level acos doesn't count (i.e. 99% of the answers here don't count). When I said "port this to assembler" above, that applies to most of the questions here, just replace "assembler" with the relevant language.

@JasonC: Sounds like an entirely arbitrary notion to me, with no more real sense than my deciding that people had to implement addition, subtraction, multiplication and division on their own if they're doing to use them.

@JerryCoffin Instead of arguing technicalities, suffice it to say that neither asin(-1) nor fldpi are particularly interesting or creative. There's not much purpose in competing to see whose favorite language has the shortest name for predefined trig functions and pi constants.

bc -l, 37 bytes
for(p=n=2;n<7^7;n+=2)p*=n*n/(n*n-1);p

I don't see any other answers using the Wallis product, so since its named after my namesake (my History of Mathematics lecturer got a big kick out of that), I couldn't resist.
Turns out its a fairly nice algorithm from the golfing perspective, but its rate of convergence is abysmal - approaching 1 million iterations just to get 5 decimal places:
$ time bc -l<<<'for(p=n=2;n<7^7;n+=2)p*=n*n/(n*n-1);p'
3.14159074622629555058

real    0m3.145s
user    0m1.548s
sys 0m0.000s
$

bc -l, 15 bytes
Alternatively, we can use Newton-Raphson to solve sin(x)=0, with a starting approximation of 3. Because this converges in so few iterations, we simply hard-code 2 iterations, which gives 10 decimal places:
x=3+s(3);x+s(x)

The iterative formula according to Newton-Raphson is:
x[n+1] = x[n] - ( sin(x[n]) / sin'(x[n]) )

sin' === cos and cos(pi) === -1, so we simply approximate the cos term to get:
x[n+1] = x[n] + sin(x[n])

Output:
$ bc -l<<<'x=3+s(3);x+s(x)'
3.14159265357219555873
$

+1 now that's more like it!

@JasonC What is your opinion of application of Newton-Raphson to solve sin(x)=0 (see edit)?

Perl - 35 bytes
$\=$\/(2*$_-1)*$_+2for-46..-1;print

Produces full floating point precision. A derivation of the formula used can be seen elsewhere.
Sample usage:
$ perl pi.pl
3.14159265358979

Arbitrary Precision Version
use bignum a,99;$\=$\/(2*$_-1)*$_+2for-329..-1;print

Extend as needed. The length of the iteration (e.g. -329..-1) should be adjusted to be approximately log2(10) ≈ 3.322 times the number of digits.
3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211707

Or, using bigint instead:
use bigint;$\=$\/(2*$_-1)*$_+2e99for-329..-1;print

This runs noticably faster, but doesn't include a decimal point.
3141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067

Javascript, 43 36
x=0;for(i=1;i<1e6;i++){x+=1/i/i};Math.sqrt(6*x)

x becomes zeta(2)=pi^2/6 so sqrt(6*x)=pi. (47 characters)
After using the distributive property and deleting the curly brackets from the for loop you get:
x=0;for(i=1;i<1e6;i++)x+=6/i/i;Math.sqrt(x)

(43 characters)
It returns:
3.14159169865946

Edit:
I found an even shorter way using the Wallis product:
x=i=2;for(;i<1e6;i+=2)x*=i*i/(i*i-1)

(36 characters)
It returns:
3.141591082792245

python - 47 45
pi is actually being calculated without trig functions or constants.
a=4
for i in range(9**6):a-=(-1)**i*4/(2*i+3)

result:
>>> a
3.1415907719167966

Should be able to save a byte by dropping the zero after the decimal place for forced float interpretation.  :)  Bonus points for brevity, but I like mine for arbitrary accuracy and lower memory utilization.  (Edited to scratch the parenthesis idea; I see what's going on there and my isolated test didn't catch the issue.)

Uh… no.  After your modification this no longer gives valid output.  (265723 ≭ π)  You still need the period, just not the trailing zero.

@amcgregor use python 3?

I do, though I primarily develop under 2.7 and make my code work in both.  However on the stock Mac 10.9 python3 installation your code causes a segmentation fault.

@amcgregor I just tested it, it works for me (python 3.3.4)

C, 99
Directly computes area / r^2 of a circle.
double p(n,x,y,r){r=10000;for(n=x=0;x<r;++x)for(y=1;y<r;++y)n+=x*x+y*y<=r*r;return(double)n*4/r/r;}

This function will calculate pi by counting the number of pixels in a circle of radius r then dividing by r*r (actually it just calculates one quadrant). With r as 10000, it is accurate to 5 decimal places (3.1415904800). The parameters to the function are ignored, I just declared them there to save space.

Python, Riemann zeta (58 41 char)
(6*sum(n**-2for n in range(1,9**9)))**0.5

Or spare two characters, but use scipy
import scipy.special as s
(6*s.zeta(2,1))**0.5

Edit: Saved 16 (!) characters thanks to amcgregor

Can potentially avoid the math import and sqrt call by pivoting to exponentiation instead: (6*sum(n**-2 for n in range(1,9**9)))**0.5

Game Maker Language, 34
Assumes all uninitialized variables as 0. This is default in some versions of Game Maker.
for(i=1;i<1e8;i++)x+=6/i/i;sqrt(x)

Result:
3.14159169865946

very nice. also, in C float k(){double x=0,i=0;for(;i++<999999;)x+=6/i/i;return sqrt(x);} is shorter than this one

even shorter with 1e8 instead of 999999

Could you use for(i=1;i<1e8;)x+=6/i/i++;sqrt(x) to save a byte (or alternatively for(i=1;i++<1e8;))?

@mbomb007 Unfortunately not, GML requires all 3 parameters.

TI CAS, 35
lim(x*(1/(tan((180-360/x)/2))),x,∞)

I looked back at this and i completely forget how it works :P

Javascript: 99 characters
Using the formula given by Simon Plouffe in 1996, this works with 6 digits of precision after the decimal point:
function f(k){return k<2?1:f(k-1)*k}for(y=-3,n=1;n<91;n++)y+=n*(2<<(n-1))*f(n)*f(n)/f(2*n);alert(y)

This longer variant (130 characters) has a better precision, 15 digits after the decimal point:
function e(x){return x<1?1:2*e(x-1)}function f(k){return k<2?1:f(k-1)*k}for(y=-3,n=1;n<91;n++)y+=n*e(n)*f(n)*f(n)/f(2*n);alert(y)

I made this based in my two answers to this question.

Ruby, 54 50 49
p (0..9**6).map{|e|(-1.0)**e/(2*e+1)*4}.reduce :+

Online Version for testing.
Another version without creating an array (50 chars):
x=0;(0..9**6).each{|e|x+=(-1.0)**e/(2*e+1)*4}; p x

Online Version for testing.

It's interesting to see the language differences that such compact solutions can give.  For example, the Python translation of the above is 105 characters (after using some trivial code compression tricks): a=__import__;reduce(a('operator').__add__,a('itertools').imap(lambda e:(-1.0)**e/(2*e+1)*4,xrange(9**6))) -- note the use of xrange/imap; in Python 3 you can avoid this; basically I don't want all of your RAM to get consumed constructing a list with so many entries.

You're absolutely right. It is often very convenient to use (especially Ruby's) Array and Enumerable functions, though it might really not be the best idea in terms of performance and speed... Well, thinking about that, it should be possible to do the calculation with the Range.each method instead of creating a map.

Yes, it's possible - just one character more...

Your first answer is not as precise as your second.

Could you elaborate, please? Same algorithm, same output for me?

C# 192
class P{static void Main(){var s=(new System.Net.WebClient()).DownloadString("http://www.ctan.org/pkg/tex");System.Console.WriteLine(s.Substring(s.IndexOf("Version")+21).Split(' ')[0]);}}

Outputs:
3.14159265

No math involved. Just looks up the current version of TeX and does some primitive parsing of the resulting html. Eventually it will become π according to Wikipedia.

I'm 5 years late, but this is a standard loophole that was created 4 days before this answer.

Python 3 Monte Carlo (103 char)
from random import random as r
sum(1 for x,y in ((r(),r()) for i in range(2**99)) if x**2+y**2<1)/2**97

Java - 83 55
Shorter version thanks to Navin.
class P{static{System.out.print(Math.toRadians(180));}}

Old version:
class P{public static void main(String[]a){System.out.print(Math.toRadians(180));}}

This doesn't do any calculation.

I don't understand the downvote, although - I'd answered with "Math.toRadians(180)". It is also questionable, who computes pi: the compiler or the program. But that was not part of the question.

@user2509848 It most certainly does: it multiplies 180 by pi/180.

You mean it multiplies pi by 1?  It is essentially the same thing.  I did not downvote it, but I don't think it really counts.

Can be shorter: http://codegolf.stackexchange.com/a/22057/14610

You can't convert degrees to radians without already knowing pi; this computes "output = 180 * pi / 180", which just multiplies pi by 1 and prints it. whistle Red flag on the play!

R: 33 characters
sqrt(8*sum(1/seq(1,1000001,2)^2))
[1] 3.141592

Hopefully this follows the rules.

JavaScript - 19 bytes
Math.pow(29809,1/9)

Calculates the 9th root of 29809.
3.1415914903890925

Ruby, 12
p 1.570796*2

I am technically "calculating" pi an approximation of pi.

No, you are not technically calculating pi. You are technically calculating 3.141592, which happens to be close to pi, but will never converge to exactly acos(-1).

@Wchar Ok, edited

I don't think hard-coding pi/2 then multiplying it by 2 really counts; the point is to calculate pi, not obfuscate a numeric literal.

Ruby, 82
q=1.0
i=0
(0.0..72).step(8){|k|i+=1/q*(4/(k+1)-2/(k+4)-1/(k+5)-1/(k+6))
q*=16}
p i

Uses some formula I don't really understand and just copied down. :P
Output: 3.1415926535897913

53 characters of Javascript:
x=3;d=1;while(d>1e-8){d=Math.sin(x);x+=d;};alert(x);
With an arbitrary numeric precision implementation of sin (e.g. taylor expansion), this will give an arbitrarily exact result with good convergence and a roughly estimated precision while keeping the code very simple.

Save some characters with alert(x), and also remove the var statements

R
A few years back I was taking a math course and the instructor asked the class how we might compute pi from scratch. A guy at the back of the class suggested drawing a circle of diameter 1 and then laying a piece of string around it.
I couldn't figure out how to do that in R. I decided the second most primitive approach would be to approximate the circle with a regular polygons. A 4096-gon gets us 5 digits. The polygons are approximated with a simple binary search using only the midpoint and distance formulae (i.e. no trigonometric functions are used).
a <- c(0,1); b <- c(0,0); c <-c(1,0)
eps <- 0.000000001
mid  <- function(a,b) { c(mean(c(a[1],b[1])), mean(c(a[2],b[2])))}
dist <- function(a,b) { sqrt((a[1]-b[1])^2 + (a[2]-b[2])^2)}
for (i in 1:10)
{
    ab1 <- mid(a,b)
    ab2 <- mid(b, ab1)
    bc1 <- mid(b,c)
    bc2 <- mid(b, bc1)
    repeat
    {
        newab <- mid(ab1,ab2)
        newbc <- mid(bc1, bc2)
        corner <- dist(newab,newbc)
        side   <- dist(a,b) - 2*dist(newab,b)
        dif <- side - corner
        if (abs(dif) < eps)
        {
            a <- c(0,newab[2]+dist(newab,newbc))
            b <- newab
            c <- newbc
            break
        }
        if (dif > 0){ab2 <- newab;bc2 <- newbc}
        if (dif < 0){ab1 <- newab;bc1 <- newbc}
    }
}
print((2^(i+2))*dist(newab,newbc))

Python, 37 chars
Using zeta(10) for fast convergence:
    sum(93555./i**10 for i in[1,2,3])**.1
    3.1415923154068

Using the same serie to get 15 correct digits:
    sum(93555./i**10 for i in range(1,40))**.1
    3.141592653589793

AppleScript, 8 characters
Solution :
3+.14159

Result :
3.14159

When you have one sourcecode that works on multiple languages, it is better to post only one answer and include the name of both languages in the same answer.

bc -l, 6
4*a(1)

This requires the -l option to bc.  Do I need to declare extra points for that?
Using -l calculates to 20 decimal places:
$ bc -l<<<"4*a(1)"
3.14159265358979323844
$

I don't think 4 * atan(1) really qualifies as calculating anything. All these answers with trig functions eventually rely on pi itself being part of the equation at some point; it's really a glorified 4 * pi / 4.

@JasonC - point taken.  So here's another answer which I think should satisfy your thirst for real calculation ;-)

I count 6 chars, not 7!

@JasonC Try this: time bc -l <<<"scale=10000;pi=4*a(1);1". This output only 1, (not pi with 9999 decimals) but load your CPU to compute. So I think that it's not only 4*pi/4 but really 4*atan(1)!

@JasonC In fact, you are partialy right in that: bc use precomputed strings for quick answer on less than 60 decimal presicion calculation: see source code but if presicion requested if greater than 60 decimals, then bc will effectively compute the answer.

@F.Hauri Oh, no doubt it's actually performing an atan. It's just that atan(1) is equal to pi/4. Even though bc doesn't make any kind of special optimizations for that case (why should it?), 4*atan(1) is still equal to 4*pi/4. My real point was that general trig functions that require pi to be known in order to be calculated seem like a cheat (these are all solutions that can only calculate pi because at some point, pi is known; even if it is buried in an atan implementation).

@F.Hauri Re: precomputed strings; hey, that is interesting, I didn't know bc did that, and thanks for the link!

@F.Hauri - thanks - I don't know how I counted 7!

@JasonC so if I read the source code correctly, then -4*a(-1) would be a valid answer, as precomputed strings are only given for x=1 and 0.2.  The arctan() is computed using one of two convergent series, neither of which has any pre-computed knowledge of Pi, when x=-1.

@DigitalTrauma In my opinion, no. But if you could implement a full arctan function that didn't require pi or other trig library calls in as few characters as possible, now that would be interesting and acceptable.

TI CAS , 4
Assuming you're in radians mode,
180°

If you really insist, to put it into radians mode:
Radians:180°

(suggested by AJMansfield)
(similar to the Mathematica answer)

Assuming you're in radians mode is dangerous, as in "assuming you have Pi/2 loaded in some var". If that's the machine default, it's Ok (I think). If it's not the default mode you should include the appropriate settings. If the settings aren't programmable, the environment can't compete.

Agreed with @belisarius I'd consider Radian->Mode or similar at least 10 chars.

Radian mode is the default

Ok! Just a rant: I don't like this one (or my answer, or a lot of other ones around). We are just exploiting a weak problem definition.

At least on the TI-84 (on which this is also a legal program), the command token for changing modes is only 2 bytes. Just insert Radians: at the beginning, and you have a 7 char program that works regardless of the current mode.

I think that's also allowable on the 89

You have to know pi to convert degrees to radians; I don't think displaying "pi*180/180" really counts...

Python - 68 characters
Quite a long solution.
_=lambda x,y=1:x^y and y*2-1+y**2/_(x,y+1)or x*2.0+1
print 4/_(99)

Groovy, 77
def x=0;for(k in 0..99){x+=Math.pow(-1/3,k)/(2*k+1)};println x*Math.sqrt(12)

This uses the Madhava-Leibniz series, which converges more quickly than the plain Leibniz series:

Output:
3.141592653616969

AppleScript, 4 characters !
Solution :
pi+0

Displayed result :
3.14159265359

Windows Calculator - cheat: 1, less cheating: 5
p (not my final answer, but I just had to include this for lulz)
or
F₁ 1 i t * 4 ↲
F₄ 1 F₉ i o
(F₄ sets mode to radians, F₉ negates the buffer)
If it must be a pasteable/savable string, and mode is already set to radians and the buffer is 0.0: io*2=

TI BASIC, 24
Disp fnInt(√(4-X²),X,0,2

returns:
3.141593074
Done

This does not use any trig function, instead it uses numerical integration of the function of half a circle with radius 2. That circle has area 4pi, so half that circle has area 2pi, but i integrate from 0 to 2 wich is half of that, so a quarter of the circle, area pi.

Groovy: 25
print Math.log(10691/462)

Output is 3.141592653932079
de Jerphanion approximation

APL : 2 chars
    ○1
3.141592653589793

Reference for monadic circle: http://www.microapl.co.uk/apl_help/ch_020_020_230.htm

JavaScript 50 (30 decimal places, including alert call...)
alert((m=Math).log(pow(640320,3)+744)/pow(163,.5))
....5....0....5....0....5....0....5....0....5....0

Based on the entry under Miscellaneous Approximations section in wikipedia: http://en.wikipedia.org/wiki/Approximations_of_%CF%80
Or for less accurate...
JavaScript 40 (10 decimal places, including alert call)
alert(Math.pow(1e100/11222.11122,1/193))
....5....0....5....0....5....0....5....0

Output:
3.1415926536438223
...........^ Accuracy finishes after this digit!)

Or for even less accurate...
JavaScript 28 (8 decimal places, including alert call!)
alert(Math.pow(2143/22,.25))
....5....0....5....0....5..8

Output:
3.1415926525826463
.........^ Accuracy finishes after this digit!)

alert(Math.pow(2143/22,.25) gives me a syntax error. did you forgot the last ) ?

@WolleVanillebarLutz Oops! Fixed!

Julia
Hiperarmonic series:
julia> s=0;sqrt(6*([s+=1/i^2 for i=1:8^6][end]))
3.1415890108270967

Zeta function:
julia> sqrt(zeta(2)*6)
3.141592653589793

Bailey-Borwein-Plouffe formula:
julia> s=0;[s+=(-1)^k/4^k*(2/(4k+1)+2/(4k+2)+1/(4k+3)) for k=0:7]
8-element Array{Any,1}:
 3.33333
 3.11429
 3.14636
 3.14068
 3.14178
 3.14155
 3.1416
 3.14159

Ramanujan formula (fastest convergence):
julia> !n=factorial(n);s=0;([s+=!4n*(1103+26390n)/(!n*396^n)^4 for n=0][end]*(sqrt(8)/9801))^-1
3.1415927300133055

Javascript 44
I am new to golfing, so this is my best shot:
p=0;for(i=1;i<1e7;i+=4)p+=8/i/(i+2);alert(p)

Ruby, 35
Using Euler's formula.  No reliance on trigonometric functions that might store π somewhere (though CMath might use Math::PI internally...).
require('cmath');CMath.log(-1).imag

Returns
3.141592653589793

Smalltalk, 9
1arcSin*2

will do

How is using somebody else's implementation of trig identities that rely on pi to begin with in the spirit of this question?

in the same spirit as acos, swrt, fpatan, degrees-to-radians, tan.
I agree in general, but I don't see why your particularly blaming me.
And btw: why "someone else's" ?

Python : 8 bytes
acos(-1)

do i have to include imports??

This is 8 bytes, not 7. At least it is definitely 8 characters. (Aside from the fact that my identical version of this in the question comments predates this by 1 hour.)

Yes, you have to include imports.

q [7 chars]
acos -1

Example
acos -1
3.141593

355%113       // [7 Chars]
3.141593

2*asin 1      // [8 Chars]
3.141593

Java: 89
class j{public static void main(String[]a){System.out.print(4-Math.pow(105./166,1./3));}}

unGolfed:
class j {
    public static void main(String a[]){
        //E. Pegg approximation
        System.out.print(4-Math.pow(105./166,1./3));
    }
}

Python, 27
import math
math.atan(1)*4

I'm morally opposed to this cop-out solution, but you can make it even shorter.  __import__('math').atan(1)*4 -- 28, and it prints the result in the REPL shell.

Java 8, 155
class P{public static void main(String[] s){System.out.print(4*java.util.stream.IntStream.range(0,999999).mapToDouble(x->Math.pow(-1,x)/(2*x+1)).sum());}}

Uses the same approach as @HeikoOberdiek's Perl solution i.e., the Leibniz formula.

Here's the same program in a longer form, formatted for easier reading:
import static java.lang.Math.pow;
import static java.util.stream.IntStream.range;

public class Pie {
    public static void main(String[] args) {
        System.out.println(4 * range(0, 999_999).mapToDouble(x -> pow(-1, x) / (2*x + 1)).sum());
    }
}

Output:
3.1415936535907933

I chose not to use @Navin's static block trick as I'm not sure whether it's valid.

Also, one other difference between this and @HeikoOberdiek's Perl program is that this goes over the range [0, 999,999) whereas the Perl uses the range [0, 999,999]. I could change the constant to 1_000_000 or use rangeClosed instead of range, but those would both increase the character count.

PHP, 281
Not going to win, but more of a challenge for myself.
Calculates PI to the nth precision (determined by the value of $d, currently 5). This is a PHP implementation of the Gauss–Legendre algorithm. I discovered after the fact this was almost exactly done by someone 7 years ago... *smh* ...posting anyway.
Golfed:
$d=5;$r=$d+4;$n=floor(log($r)/log(2));bcscale($r);$a=1;$b=bcdiv(1,bcsqrt(2));$t=.25;$p=1;while($n--){$x=bcdiv(bcadd($a,$b),2);$y=bcsqrt(bcmul($a,$b));$t=bcsub($t,bcmul($p,bcsub(bcpow($x,2),bcpow($y,2))));$p=bcmul(2,$p);$a=$x;$b=$y;}echo bcdiv(bcpow(bcadd($a,$b),2),bcmul(4,$t),$d);

$d = 5 outputs 3.14159
$d = 19 outputs 3.1415926535897932384
$d = 41 outputs 3.14159265358979323846264338327950288419716
etc...

Community Help: I would like to set the scale/precision more appropriately on each iteration (rather than fixed at 4: $r=$d+4), but I can't seem to find a way to reliably determine the error precision, i.e. the rate of convergence isn't constant.

Windows Calculator,  1 click
Inspired by This Answer

This answer is a blatant advertisement for your other answer. There is no relation whatsoever.

This was originally a comment to this answer, but since the full program is shorter than the other C solution (which is only a function), I might as well post it as an answer:
C, 64
double x,i;main(){for(;i++<1e8;)x+=6/i/i;printf("%f",sqrt(x));}

output:
3.141593

C
main(){printf("%f",22/7.0);}

"It must be able to calculate pi to at least 5 decimal places."

bc -l, 9 chars
2*a(2^99)

Even with bc(1)'s default scale this is correct up to as many digits as I memorised. Raise the potence (and the scale) to get more precisions.

JavaScript, 94 characters
+function p(n){return~n?(4/(8*n+1)-1/(4*n+2)-1/(8*n+5)-1/(8*n+6))/Math.pow(16,n)+p(n-1):0}(9)

Can somebody help me golf this further with some bitshifts?

R, Monte Carlo 68
Old square inscribed in circle method.
z=n=0;repeat{z=z+ifelse(sum(runif(2)^2)<1,1,0);n=n+1;write(4*z/n,1)}

Check if x^2 + y^2 <= r^2, if yes z += z, else n += n. Pi ~= 4z/n as iteration -> inf.

C++ 26
main(){cout<<6*asin(0.5);}

Python 3.x - 123
Sadly this has very little precision... giving only 1-2 decimal places correct.
Anyway this is a fun method of calculating pi.
import random
R = lambda: random.uniform(-1,1)
print(sum(1 for _ in range(10**6) if abs(R() + R()*1j) < 1)*4/10**6)

"It must be able to calculate pi to at least 5 decimal places."

Ruby 8
-0.0.arg

Output takes 2 more chars:
p -0.0.arg  # => 3.141592653589793

Python 3, 91 (with display), 82 (just calculation)
This knows that Pi is 3, then it uses the Nilakantha method to calculate Pi accurately to 6 decimal places.
p,n,s=3,2,1
while s<99:
 n,s,z=n+2,s+1,4/(n*(n+1)*(n+2))
 if s%2<1:p+=z
 else:p-=z
print(p)

It starts with the humorous 3,2,1, but also with the rather distasteful p,n,s...
Output
3.141592 395970107
The space is to separate the correct output from the incorrect.

bc, 8 characters
Solution :
3+.14159

Usage :
$ bc <<< "3+.14159"
3.14159
$

+1 amazing technique! HOW DOES THIS EVEN WORK??

Python, 27 chars
print "%.5f"%(355.0/113.0)

Java, 55
class P{static{System.out.print(Math.toRadians(180));}}

Hooray for static blocks ^_^

-1. This is a direct copy of http://codegolf.stackexchange.com/a/22025/9498 . You thought of using the static block, but since this is identical to the other answer, you should have posted this idea in a comment.

Also, that will never compile without a main method.

@Quincunx That is why I linked it.

@impinball IIRC, main() is only needed at runtime in Java (unlike most other languages which need an entry point to compile). The static block will run before it crashes.

It doesn't, though. When Java sees it doesn't have a main() method, it doesn't even load the class and the static block never runs. At least, that's the result I get with the latest Java 8 build.

Hmm. It works with 1.6.0_45 but not 1.7.0_40 or 1.8.0-b129.

@DavidConrad Odd.... I've been using this forever 0_0 I just call System.exit(0); after the static block so it does not crash

Matlab or Octave
0+pi

So short stackexchange won't let me post it without this. The output:
octave:5> 0+pi
ans =  3.14159265358979

authors: نورا الجماعي

authors: อาทิตย์ พลทอง


text:
Make a golfing language
In this challenge, you get to create a language. Although you have to provide code in other languages, you will only be rated based on the language. Here are the requirements.

You must invent a programming language that is Turing complete.
You will choose a real (as in existed before this question did) language. It must be a different paradigm then the made up language.
You will write a boot strapping compiler. This means you write a program in your new language, that will take code in your new language, and translate it to code in your real language.
So people can run it initially, you will provide an interpreter (or compiler) in a real language (which may or may not be written the real language you choose above) to run programs in the new language. This does not need to be golfed.

Note: Your language can't have builtin functions for generating code in the real language. This basically means that if the real language were proprietary, your language wouldn't violate its copyright by making it to easy to generate its code.
Scoring:
Your score is the size of your compiler. Your will find your programs' sizes using roundup(s*log_2(a)) where s is the number of characters in your program and a is the number of available characters in your language (meaning huge penalties if you use Chinese characters or something.)
Tip: String characters count too, so if you are looking to really shrink how many characters are available, you will need to find a way to represent strings with few characters.
Smallest score wins!
So in summary, you invent a turing-complete language X. Then you implement an interpreter or compiler for it in Y. Finally, you implement a compiler for X in X itself. (Based on a comment from Victor.)

So I must to write a code in language A that translates code in language B to language C. Isn't writing an interpreter in language A to interpret language B acceptable?

No no no. You write code in A to translate code in A to B and C. Code in A that interprets A would be pointless. You just write code in D (which may or may not be B or C) to interpret A so you can run it the first time.

We have to write TWO??

Well, I didn't want a pig latin of one of the languages. Should I make it one you think?

Well, this will take a considerably large amount of time...

Okay, I will make it one. But then it has to be a different paradigm than it.

Translating brainfuck to haskell doesn't seem too hard,  one can think of something abusing the state monad. Translating brainfuck to python is a piece of cake

Except you would have to do it in brainf***.

And it should be a new language you come up with.

What if the language isn't character based, like Piet?

So this is basically 1. Invent a turing-complete language X. 2. Implement an interpreter or compiler for it in Y. 3. Implement a compiler for X in X itself. Got it right?

According to the rules, taking C and swapping { and } would be a valid entry? You may have a tough time coming up with a definitive line for how different the languages have to be.

@KendallFrey Rule 2 would stop you from doing that. But probably there is some way to circunvent that anyway.

@Victor Well, most languages don't have a defined paradigm. Some languages are functional, procedural, imperative, object-oriented, etc.

It is sort of a guideline. I don't think there is a way to make it definite. Is there a tag for that?

I feel like the spec for this is too ambiguous.

@Victor, that's not how I understand it. I think your step 2 corresponds to the question's step 4, but for your step 3 to correspond to the question's step 3 the question would need to relax from writing a source-source translator to writing a compiler.

Aw man, why is this closed? It's one of the only genuinely interesting challenges I've seen on this site.

Plus it really isn't that hard. It sort of seems like it's been closed on the basis that it sounds a bit too much like hard work, which is kind of a bad sign for a site that's meant to be about puzzles and challenges.

Brainfuckoff -> Javascript, 527 characters, 3463 points
My language, Brainfuckoff is a brainfuck-derived language with the following changes:

It has a new instruction * which sends everything in input to the output, until the end-of-input is reached.
It has a new instruction ^ which sends everything following this and before the following backtick to the output.
It takes a line of the input at a single shot in the start of the program, consuming each char with the , instruction.

So, here is a partially-golfed javascript compiler for my language:
function bfg(j){
  w=String.fromCharCode;
  r='(function(n){m=[];p=0;c=0;t=n.substring(0,0);';
  for(x=0;x<j.length;x++){
    q=j.charCodeAt(x);
    if(q==91)r+='while(~~m[p]){';
    if(q==93)r+='}';
    if(q==62)r+='p++;';
    if(q==60)r+='p--;';
    if(q==43)r+='m[p]=1+~~m[p];';
    if(q==45)r+='m[p]=-1+~~m[p];';
    if(q==46)r+='t+=String.fromCharCode(~~m[p]);';
    if(q==44)r+='if(c<n.length)m[p]=n.charAt(c++);';
    if(q==94){z=j.indexOf(w(96),x+1);r+='t+='+w(34)+j.substring(x+1,z)+w(34)+';';x=z}
    if(q==42)r+='t+=n.substring(c);c=n.length;'
  }
  return r+'return t})'
}

Here is a brainfuck Hello World program:
++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.

Compiling it:
program = '++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.';
jsprogram = bfg(program);
alert(jsprogram);

The output:
 (function(n){m=[];p=0;c=0;t=n.substring(0,0);m[p]=1+~~m[p];m[p]=1+~~m[p];m[p]=1+~~m[p];m[p]=1+~~m[p];m[p]=1+~~m[p];m[p]=1+~~m[p];m[p]=1+~~m[p];m[p]=1+~~m[p];while(~~m[p]){p++;m[p]=1+~~m[p];m[p]=1+~~m[p];m[p]=1+~~m[p];m[p]=1+~~m[p];while(~~m[p]){p++;m[p]=1+~~m[p];m[p]=1+~~m[p];p++;m[p]=1+~~m[p];m[p]=1+~~m[p];m[p]=1+~~m[p];p++;m[p]=1+~~m[p];m[p]=1+~~m[p];m[p]=1+~~m[p];p++;m[p]=1+~~m[p];p--;p--;p--;p--;m[p]=-1+~~m[p];}p++;m[p]=1+~~m[p];p++;m[p]=1+~~m[p];p++;m[p]=-1+~~m[p];p++;p++;m[p]=1+~~m[p];while(~~m[p]){p--;}p--;m[p]=-1+~~m[p];}p++;p++;t+=String.fromCharCode(~~m[p]);p++;m[p]=-1+~~m[p];m[p]=-1+~~m[p];m[p]=-1+~~m[p];t+=String.fromCharCode(~~m[p]);m[p]=1+~~m[p];m[p]=1+~~m[p];m[p]=1+~~m[p];m[p]=1+~~m[p];m[p]=1+~~m[p];m[p]=1+~~m[p];m[p]=1+~~m[p];t+=String.fromCharCode(~~m[p]);t+=String.fromCharCode(~~m[p]);m[p]=1+~~m[p];m[p]=1+~~m[p];m[p]=1+~~m[p];t+=String.fromCharCode(~~m[p]);p++;p++;t+=String.fromCharCode(~~m[p]);p--;m[p]=-1+~~m[p];t+=String.fromCharCode(~~m[p]);p--;t+=String.fromCharCode(~~m[p]);m[p]=1+~~m[p];m[p]=1+~~m[p];m[p]=1+~~m[p];t+=String.fromCharCode(~~m[p]);m[p]=-1+~~m[p];m[p]=-1+~~m[p];m[p]=-1+~~m[p];m[p]=-1+~~m[p];m[p]=-1+~~m[p];m[p]=-1+~~m[p];t+=String.fromCharCode(~~m[p]);m[p]=-1+~~m[p];m[p]=-1+~~m[p];m[p]=-1+~~m[p];m[p]=-1+~~m[p];m[p]=-1+~~m[p];m[p]=-1+~~m[p];m[p]=-1+~~m[p];m[p]=-1+~~m[p];t+=String.fromCharCode(~~m[p]);p++;p++;m[p]=1+~~m[p];t+=String.fromCharCode(~~m[p]);p++;m[p]=1+~~m[p];m[p]=1+~~m[p];t+=String.fromCharCode(~~m[p]);return t})

Running that:
program = '++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.';
input = '';
jsprogram = bfg(program);
alert(eval(jsprogram)(input));

The output:
Hello World!

This other brainfuckoff's Hello World is simpler:
program = '^Hello World!`'
input = '';
jsprogram = bfg(program);
alert(eval(jsprogram)(input));

The output:
Hello World!

Great, now a compiler of brainfuckoff to javascript written in brainfuckoff (527 characters):
^(function(j){w=String.fromCharCode;r='(function(n){m=[];p=0;c=0;t=n.substring(0,0);';for(x=0;x<j.length;x++){q=j.charCodeAt(x);if(q==91)r+='while(~~m[p]){';if(q==93)r+='}';if(q==62)r+='p++;';if(q==60)r+='p--;';if(q==43)r+='m[p]=1+~~m[p];';if(q==45)r+='m[p]=-1+~~m[p];';if(q==46)r+='t+=String.fromCharCode(~~m[p]);'; if(q==44)r+='if(c<n.length)m[p]=n.charAt(c++);';if(q==94){z=j.indexOf(w(96),x+1);r+='t+='+w(34)+j.substring(x+1,z)+w(34)+';';x=z}if(q==42)r+='t+=n.substring(c);c=n.length;'}return eval(r+'return t})')})('`*^')`

Compiling the compiler:
program = "^(function(j){w=String.fromCharCode;r='(function(n){m=[];p=0;c=0;t=n.substring(0,0);';for(x=0;x<j.length;x++){q=j.charCodeAt(x);if(q==91)r+='while(~~m[p]){';if(q==93)r+='}';if(q==62)r+='p++;';if(q==60)r+='p--;';if(q==43)r+='m[p]=1+~~m[p];';if(q==45)r+='m[p]=-1+~~m[p];';if(q==46)r+='t+=String.fromCharCode(~~m[p]);'; if(q==44)r+='if(c<n.length)m[p]=n.charAt(c++);';if(q==94){z=j.indexOf(w(96),x+1);r+='t+='+w(34)+j.substring(x+1,z)+w(34)+';';x=z}if(q==42)r+='t+=n.substring(c);c=n.length;'}return eval(r+'return t})')})('`*^')`";
jsprogram = bfg(program);
alert(jsprogram);

The compiled compiler:
(function(n){m=[];p=0;c=0;t=n.substring(0,0);t+="(function(j){w=String.fromCharCode;r='(function(n){m=[];p=0;c=0;t=n.substring(0,0);';for(x=0;x<j.length;x++){q=j.charCodeAt(x);if(q==91)r+='while(~~m[p]){';if(q==93)r+='}';if(q==62)r+='p++;';if(q==60)r+='p--;';if(q==43)r+='m[p]=1+~~m[p];';if(q==45)r+='m[p]=-1+~~m[p];';if(q==46)r+='t+=String.fromCharCode(~~m[p]);'; if(q==44)r+='if(c<n.length)m[p]=n.charAt(c++);';if(q==94){z=j.indexOf(w(96),x+1);r+='t+='+w(34)+j.substring(x+1,z)+w(34)+';';x=z}if(q==42)r+='t+=n.substring(c);c=n.length;'}return eval(r+'return t})')})('";t+=n.substring(c);c=n.length;t+="')";return t})

Running the compiled compiler to compile the first Hello World:
program1 = "^(function(j){w=String.fromCharCode;r='(function(n){m=[];p=0;c=0;t=n.substring(0,0);';for(x=0;x<j.length;x++){q=j.charCodeAt(x);if(q==91)r+='while(~~m[p]){';if(q==93)r+='}';if(q==62)r+='p++;';if(q==60)r+='p--;';if(q==43)r+='m[p]=1+~~m[p];';if(q==45)r+='m[p]=-1+~~m[p];';if(q==46)r+='t+=String.fromCharCode(~~m[p]);'; if(q==44)r+='if(c<n.length)m[p]=n.charAt(c++);';if(q==94){z=j.indexOf(w(96),x+1);r+='t+='+w(34)+j.substring(x+1,z)+w(34)+';';x=z}if(q==42)r+='t+=n.substring(c);c=n.length;'}return eval(r+'return t})')})('`*^')`";
jsprogram1 = bfg(program1);
input1 = '++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.'
jsprogram2 = eval(jsprogram1)(input1);
input2 = '';
alert(eval(jsprogram2)(input2));

The output:
Hello World!

Calculating the score:
roundup(527 * log_2(asciiCharOf('~') - asciiCharOf(' ') + 1))
roundup(527 * log_2(126 - 32 + 1))
roundup(527 * log_2(95))
roundup(527 * 6.5698556083309478416638388523962)
roundup(3462.3139055904095125568430752128)
3463

Note: There are indeed some ways to reduce the size of the interpreter in maybe ~20%. But this was already hard enough to do for me.

Very nice, exactly what I intended. You rounded up incorrectly though.

@PyRulez Fixed. Sorry for the mistake, I was a bit nervous at the time.

@PyRulez Since it is unlikely that this question will get any more attention, and since my answer is the only answer that is complete, detailed, not abusing the scoring, and meeting your expectations, could you please accept it?

Nice name (just get rid of brain from it)

Score = (Number too long for an SE post * log_2(1)) = 0
Given how the score is weighted by the number of characters available in the language, the less the better:
1.) My language (X) is called Compressed Unary.  It is similar to Unary in that it only has one available character in the language. Unlike Unary, it uses the number "1" instead of "0".  It improves on Unary by assigning the operators in a different bit order, with lower values assigned to operations that occur more often.  It is proven to be Turing complete in that it can be trivially converted to Brainfuck.
The code is a string of 1s, and the length of the code determines the logic (see the description of Unary from the link above for more details. The encoding is as follows:
Brainfuck   Binary
+           (1000)
-           (1001)
>           (1010)
<           (1011)
.           (1100)
,           (1101)
[           (1110)
]           (1111)

All the binary is combined from left to right and the resulting number is how many "1"s should be in the source code.  This should yield much smaller code that Unary, but will absolutely suck as a golfing language.  Much better for code bowling (see the compiler below and you'll see why).
2.) I chose C#. It was easy, I could port an existing BF implementation (props to the original author), and given that log_2(1) is zero, the length of the code doesn't have any effect my score.
3.) The source code is too long to include here (stupid 30k character limit), in fact the number is too long to post here (it is 123411 characters in hex notation).  The following link will give you the number in hex. You can create the bootstrap compiler simply by typing that many ones in a text file.
Like I said, this completely sucks as a golfing language. It's much worse than C# for golfing.
4.) Once you type out the source code (I'd include a download link, but it would take way too long even on a fast fiber connection), you can run it through the following interpreter:
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;

namespace CompressedUnary
{
    class Program
    {
        static void Main(string[] args)
        {
            BigInteger code = new BigInteger(0);
            int next = 0;

            try
            {
                using (FileStream source = new FileStream(args[0], FileMode.Open, FileAccess.Read))
                {
                    next = source.ReadByte();
                    while (next != -1)
                    {
                        if (next != 49)
                        {
                            System.Console.WriteLine("Syntax error.");
                            break;
                        }
                        code += 1;
                        next = source.ReadByte();
                    }
                }
            }
            catch (FileNotFoundException oops)
            {
                Console.WriteLine(oops.Message);
            }

            if (next == -1)
            {
                string processed = PreProcess(code);
                Interpreter runner = new Interpreter(Console.OpenStandardInput(), Console.OpenStandardOutput());
                runner.Run(processed);
            }
            Console.WriteLine("Done");
        }

        static string PreProcess(BigInteger input)
        {
            StringBuilder output = new StringBuilder("");
            BigInteger current;

            while (input > 0)
            {
                BigInteger.DivRem(input, 16, out current);
                switch ((int)current)
                {
                    case 0:
                        output.Append("+");
                        break;
                    case 1:
                        output.Append("-");
                        break;
                    case 2:
                        output.Append(">");
                        break;
                    case 3:
                        output.Append("<");
                        break;
                    case 4:
                        output.Append(".");
                        break;
                    case 5:
                        output.Append(",");
                        break;
                    case 6:
                        output.Append("[");
                        break;
                    case 7:
                        output.Append("]");
                        break;
                }
            }
            return output.ToString();
        }

        enum ILCode : byte
        {
            NextCell = (byte)'>',
            LastCell = (byte)'<',
            Increment = (byte)'+',
            Decrement = (byte)'-',
            Output = (byte)'.',
            Input = (byte)',',
            BeginLoop = (byte)'[',
            EndLoop = (byte)']'
        }

        class Machine
        {
            public int pointer = 0;
            private int cell = 0;
            private readonly byte[] cells;
            private readonly Stack<int> stack = new Stack<int>();

            public Machine(int memory)
            {
                cells = new byte[memory];
            }

            public byte CurrentCell
            {
                get { return cells[cell]; }
                set { cells[cell] = value; }
            }

            public void Increment()
            {
                if (CurrentCell == 255)
                    CurrentCell = 0;
                else
                    CurrentCell++;
                pointer++;
            }

            public void Decrement()
            {
                if (CurrentCell == 0)
                    CurrentCell = 255;
                else
                    CurrentCell--;
                pointer++;
            }

            public void NextCell()
            {
                cell++;
                pointer++;
            }

            public void LastCell()
            {
                cell--;
                pointer++;
            }

            public void BeginLoop()
            {
                stack.Push(pointer);
                pointer++;
            }

            public void EndLoop()
            {
                if (CurrentCell == 0)
                    pointer++;
                else
                    pointer = stack.Pop();
            }
        }

        class Interpreter
        {
            private readonly Stream output;
            private readonly StreamReader reader;
            private readonly Dictionary<byte, Action> actions;
            private readonly Machine machine;

            public Interpreter(Stream ioin, Stream ioout, int memorySize = 30000)
            {
                output = ioout;
                reader = new StreamReader(ioin);
                machine = new Machine(memorySize);
                actions = new Dictionary<byte, Action>
                    {
                        {(byte) ILCode.BeginLoop, machine.BeginLoop},
                        {(byte) ILCode.EndLoop, machine.EndLoop},
                        {(byte) ILCode.Increment, machine.Increment},
                        {(byte) ILCode.Decrement, machine.Decrement},
                        {(byte) ILCode.NextCell, machine.NextCell},
                        {(byte) ILCode.LastCell, machine.LastCell},
                        {(byte) ILCode.Input, InputCurrentByte},
                        {(byte) ILCode.Output, OutputCurrentByte},
                    };
            }

            public void Run(string program)
            {
                byte[] instructions = program.Select(c => (byte)c).Where(b => actions.ContainsKey(b)).ToArray();
                while (machine.pointer < instructions.Length)
                {
                    Action action = actions[instructions[machine.pointer]];
                    action.Invoke();
                }
                byte[] newLine = Environment.NewLine.Select(c => (byte)c).ToArray();
                output.Write(newLine, 0, newLine.Length);
            }

            private void InputCurrentByte()
            {
                byte next = (byte)reader.Read();
                machine.CurrentCell = next;
                machine.pointer++;
            }

            private void OutputCurrentByte()
            {
                output.WriteByte(machine.CurrentCell);
                machine.pointer++;
            }
        }
    }
}

FORE!

Nice exploit. I should have added log_2 of the length, but too late now.

source: Stack Exchange

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

sort: votes


text:
Hide a Brainf*** greeting in other code
The goal is to write a program (anything except explicit brainfuck) which prints Barney Stinson's best rule:

New is always better.

when interpreted normally, but

Legen... wait for it... dary!

When processed with a Brainfuck interpreter.
May the most popular bro win. You have 72 hours to be legendary.

Not sure code-golf is the best tag for this challenge. IMHO popularity-contest would be better.

@Florent, feel free to edit, I'm new here

Whose Barney? The purple dinosaur? Fred's BFF?

@LowerClassOverflowian How I met Your Mother character, see edit

Samoth, I agree with @florent, but neither he nor I can edit as you need 1000 reputation to edit someone else's question. You can do it yourself though if you think it's a good idea.

@steveverrill strange, on StackOverflow you can edit with 1 rep, but it have to be approved

Yeah, you can "suggest" with 1 rep, but the approval process the edit could take hours. It's better to do it yourself, as you have done.

Can someone please create the tag "bro-contest"?

@Florent if the challenge is intended to be won by the shortest answer, I don't think you should retag it to a popularity contest. Samoth, in case you don't know, in a popularity contest the winner is chosen by voters - the answer with the highest vote wins. If you want your contest to be won by the answer with shortest code, please retag your question as a code-golf, and if you want it to be a popularity contest, please edit your question.

I think reusing somebody else's Brainfuck code is poor sport for these competitions.

@grovesNL as it would be the exact same code, no. I could even have include it in the question

@Samoth: That assumes that everyone independently found the shortest way to write that string in Brainfuck, when there is no obvious shortest path to write strings. It's completely different than writing something like echo "text". An extra plus sign before a loop will change the entire procedure, because of how the characters have to be created. Likewise using two loops instead of one loop could either increase or decrease the length of your code, and due to the ASCII characters, it's not obvious which will occur until you've already written it.

C#
So I decided to get a little more... creative with my entry. The Brainfuck code is embedded into the C# as the various operators (not in comments or in hardcoded strings), while the C# code itself operates on a similar principal to the way Brainfuck prints characters (meaning there are no hardcoded strings, and C# generates each individual character as an integer then casts it to a char when printing).
I'm sure I could have made this more elegant, but it took me long enough to finish as it is.
Everything was tested on this JavaScript Brainfuck interpreter by Cal Henderson and with Visual Studo 2012's C# compiler (targeted at .NET framework v4.0).
using System;

namespace Polyglot
{
    internal static class Program
    {
        private static void Main()
        {
            var a = new short[50];

            short _1 = 72;
            short _2 = 0;
            short _3 = 0;
            short _4 = 0;
            short _5 = 0;
            short _6 = 0;
            short _7 = 97;
            short _8 = 0;
            short _9 = 0;
            short _10 = 0;
            short _11 = 0;
            short _12 = 0;
            short _13 = 0;
            short _14 = 0;
            short _15 = 0;
            short _16 = 46;
            short _19 = 0;
            short _20 = 0;
            short _21 = 0;

            if( 0 >= 0 )
            {
                ++_1;
                ++_1;
                ++_1;
                ++_1;
            }

            a[ -1 < 0 ? 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 : 0 + 1 > 1 ? 0 : 0 ] = 9001;

            if( 7 < 42 )
            {
                ++_1;
                ++_1;
            }

            Console.Write( (char)_1 );

            _2 = 101;
            _1 += 1 + 1 + 1 + 1 + 1;

            _3 = 42 > 7 ? 110 + 9 : 1 + 1;

            a[ -1 < 0 ? 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 : 0 > 0 ? 0 : 0 ] = 9001;

            if( 1 < 2 )
                _4 = 32;

            Console.Write( (char)_2 );

            ++_1;
            _5 = 105;

            Console.Write( (char)_3 );

            --_1;

            _6 = 115;

            Console.Write( (char)_4 );

            ++_1;
            ++_1;
            ++_1;
            _1 += 1 + 1 + 5;

            Console.Write( (char)_5 );

            --_1;
            --_1;

            if( 42 > 41 )
            {
                ++_1;
                ++_1;
                ++_1;
            }

            a[ -1 < 0 ? 0 : 10 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 > 5 ? 0 : 0 ] = 9001;

            if( 42 < 9001 )
                Console.Write( (char)_6 );

            Console.Write( (char)_4 );
            Console.Write( (char)_7 );

            if( 12 > 11 && 11 > 10 )
            {
                _8 = 108;
                _9 = _3;
            }
            else
            {
                ++_1;
                ++_1;
                ++_1;
            }

            a[ -1 < 0 ? 1 + 1 + 1 + 1 + 1 + 1 : 1 > 2 ? 0 : 0 ] = 9001;

            if( _4 < _1 )
            {
                ++_1;
                Console.Write( (char)_8 );
            }
            else if( _4 > _19 && _2 > _20 )
            {
                ++_21;
                ++_21;
                ++_21;
                ++_21;
                ++_21;
                _21 += (short)( _21 + 36 );
            }

            a[ -7 < 9 ? 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 : 4 > 8 ? 9 : 9 ] = (short)( 12 < 10 ? -_4 : _9 );
            Console.Write( (char)_9 );

            if( _4 > _9 )
            {
                ++_1;
                ++_1;
                ++_1;
            }

            a[ -9 < 7 ? 10 - 1 - 1 - 1 - 1 : 6 > 7 ? 0 : 0 ] = _21;

            if( 1 < 0 )
                return;
            else
            {
                ++_1;
                Console.Write( (char)_7 );
            }

            _10 += 5 + 4 + 1 + 2 + 8 + 9 + 1 + 91;
            Console.Write( (char)_10 );

            if( 10 > _4 ) ++_21; else a[ -0 < 0 ? 5 + 6 + 1 + 2 + 3 + 9 : 1 > 2 ? 0 : 9 ] = 50;

            if( _21 <= _4 )
                _11 = 58 + 57;

            Console.Write( (char)_11 );

            if( _2 <= _8 )
                Console.Write( (char)_4 );
            else if( 1 >= 2 )
                return;
            else if( 42 >= _4 )
                _1 += ++_21;
            else
            {
                a[ -99 < --_1 ? --_1 - _1 : 44 > 12 ? 9 : 7 ] = (short)( _2 < _4 ? _21 : 6 );
                throw new Exception();
            }

            switch( _4 )
            {
                case 32:
                    var x = (char)( (short)( _4 + 66 ) );
                    Console.Write( x );
                    break;
                default: break;
            }

            _12 += (short)( ++_12 + ( ++_1 ) + 1 + 1 + 1 );
            Console.Write( (char)_12 );

            _13 += (short)( 39 + 38 + 39 );
            Console.Write( (char)_13 );

            if( _12 < _13 )
                Console.Write( (char)_13 );

            if( _13 >= _4 )
            {
                _14 = (short)( 500 - ( - ( 50 ) ) - ( --_1 ) - 90 - ( -4 ) - 267 );
                Console.Write( (char)_14 );
            }

            switch( _1 )
            {
                case 52:
                    _15 += (short)( ++_1 + ( ++_21 ) );
                    break;
                default:
                    _15 += (short)( 15 + ( ++_1 ) + 2 );
                    break;
            }

            Console.Write( (char)_15 );

            if( _16 <= 3521 && _21 < _4 )
                Console.WriteLine( (char)_16 );

            _16 = (short)( Int16.Parse( "54" ) % 2 );
            _20 = (short)( Int16.Parse( "99" ) / ( _1 > _4 ? 3 : 0 ) );
            _1 = (short)( 02.23 );

            if( _16 > 9 || _20 >= 52 )
                _1 += (short)( ( ++_1 ) + _21 );

            a[ -0 < 0 ? -52 - ( --_20 ) : 1 > 0 ? 1 : 2 ] = (short)( _12 < _19 ? Int16.Parse( "19" ) : 44 );
            _12 -= (short)f( --_19 / 19.467d );

            if( _12 > _14 )
                _19 += (short)( _19 + 1 + _3 + 5 );

            a[ -904 < 409 ? 4 + ( ++_4 ) + 4 : 49 > 50 ? 49 : 50 ] = (short)( 50 < 99 ? _4 + 669.2452 : 0 );

            if( 44 > ++_4 )
                a[ -9 < 6 ? 6 + ( ++_4 ) : 9 > 2 ? 44 : 8 ] = 3;
        }

        private static double f( double x )
        {
            return x < 12 ? x + 13.22 : x < 6 ? x + 90.45 : 5555;
        }
    }
}

This is the original Brainfuck code I wrote for this challenge:
> +++++ +++
[ - < +++++ ++++ > ]
< ++++ .
+++++
> ++
[ - < +++++ +++++ > ]
< . ++ . -- . +++++ ++++ .
----
> +++++ +
[ - < ----- ----- > ]
< ... >>
+++++ +
[ - < +++++ > ]
< ++ . >>
+++++ +++++ ++
[ - < +++++ +++++ > ] <
- . >
+++++ +
[ - < ---- > ] <
++ . +++++ +++ .
> ++
[ - < +++++ > ]
< + . < . >>
+++
[ - < ----- > ] <
+ . +++++ ++++ . +++ .
< . > ----- ---- . +++++ +++++ + .
<< ... > . >>
++++
[ - < ---- > ] < .
--- . >
++++
[ - < ++++ > ]
< + .
> ++
[ - < +++ > ]
< + . < + .

When running the C# code through a Brainfuck interpreter, you end up with the following commands (notice the addition of the square brackets at the beginning, these are from the array declaration and don't do anything, since the cell under the memory pointer in the array will already be 0):
[] > +++++ +++
[ - < +++++ ++++ > ]
< ++++ .
+++++
> ++
[ - < +++++ +++++ > ]
< . ++ . -- . +++++ ++++ .
----
> +++++ +
[ - < ----- ----- > ]
< ... >>
+++++ +
[ - < +++++ > ]
< ++ . >>
+++++ +++++ ++
[ - < +++++ +++++ > ] <
- . >
+++++ +
[ - < ---- > ] <
++ . +++++ +++ .
> ++
[ - < +++++ > ]
< + . < . >>
+++
[ - < ----- > ] <
+ . +++++ ++++ . +++ .
< . > ----- ---- . +++++ +++++ + .
<< ... > . >>
++++
[ - < ---- > ] < .
--- . >
++++
[ - < ++++ > ]
< + .
> ++
[ - < +++ > ]
< + . < + .

Smalltalk
"adding adding all the time"
"1+1+1+1+1+1+1+1+1+1+1" "is not fine"
"more to come / going far"
"+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1"
"all that work for a single char"

"happy me / a loop to start"
"[>++>+++>++++>+++++<<<<-]"
"was it code or just a fart?"
"adding adding / thats not fine"
"+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1"

">>+" 'New is always better.' "shall I " print
">+.++.--.+++++++++.----------.<<----...<+++++++"
"the garbage here gives us no hint"
".>>+++++++++++.>---.++++++++"

"hurray a change to stop the pain"
".>---------.<<<<.>>"
"the author now has in his brain"
"-----------------.>>-----.+++.<<<<.>>>.>++."
"We all agree the time is here"
"<<<...<.>>--.>--------.>--.+++++++.<<<<."
"to finish this and have a beer"

type into a workspace and press "doIt", or send to BF.
BF stolen from the other posters - thanks.

Javascript / Brainfuck
Ungolfed version as it is not a code-golf contest :
var outputString='';
'+++++++@++++[>++@/+@@>@/+@+@++>++++++@/+>+@++@/+@@+++++@/>@+@+++++@/+++@+<@/<<<<-]>>>@-.>++.+@/+@@.--.>.<-@/.@<@<++...<-.@/>>>>+++++@++++.<-@/-@-.@+@/+@+@+++++@/.>-@--@/.<<<<.>>>@---.>---@/-@@-@/.@+@++.<<<@/<@.@>>>+++@/.@@>@/+@+@.<<<@/...<@.>>>--@/---.---.>--.+++++++.<<<<+.<'
  .split('/')
  .forEach(function(e) {
    var matched=e.match(/[^@]*@/g);
    if (matched) {
      var asciiCode=0;
      for(var i=0;i<matched.length;i++) {
        asciiCode=matched[i-0].length-1+10*asciiCode;
      }
      outputString+=String.fromCharCode(asciiCode);
    }
  });
  alert(outputString);

That was the occasion for me to learn BF and that was fun :)
The difficulty was to never use , as BF interprets it as user input and be sure that byte is 0 before using [] for accessing elements of arrays.
The JS encoding is pretty simple, each strings before / encode a character and each string length before @ defines ASCII code in decimal. (+++++++@++++[>++@ = 78 = N)
You can test Brainfuck here : http://copy.sh/brainfuck/

Cubically (TIO) / BF (TIO)
+5+1/1+5+3@6:2/1+5+5+1@6+2@6:5/1+3@6:5+1/1+5+5+1@6:5+2/1+5+5+2@6:5/1+3@6:5+2/1+5+5@6:5+5+2@6:2/1+5+53[@6>:5+2/1+5+5@6>:4/1+5+5+3@6+>:5+2/1+55+2@6:5/1+3@6>:5+3/1+55@6>:2/1+551@6<<<<<-]>:5+3./1+552-@66>+.:2/1+5+51.@6--.>:5+1/1+5+5+2@6:1/1+5@6+++++.>----...>+++++++.<<+++++++++.<----.++++++++.>---.>>.<<<---.>-----.+++.>>.<<<+++.>++.>...>.<<<-----.---.>--.+++++++.>>+.

(Updated 8/4/17 to account for language changes in Cubically)
Basically this just uses as many characters from the BF program as it can in the Cubically program, then sticks the rest of the BF program on the end of it. No forced termination with &/E in the Cubically program is necessary.

Python / BrainF**k, 362 chars
BrainF**k code taken from Clément Renaud's deleted answer.
Edit - Initial null character no longer printed.
t='++++++++++_+++++++|^+++++++|+[>++>+++%>++++>+++++<<<<-||]+++++++++++|*+++++++++++++@+>>+.>+||.++.|--.+++++++++.--|^--------.<<----..._<+++++|++.>|>+++++&++++++.>---.+=+++++++|.>---------.<<^<<.>>--||-----|--~-----|---.>>-----~.+++.<<<<.>|>>.*>++.<<<...<.>>--._>|--------|.>-^-.+++++++.<<<<!!!'
print ''.join((chr(93+len(x))if x else' ')for x in t.split('|'))

Uses a very simple trick - | characters were added to the BF program, and the distances between them encode the string printed in Python. The Python code is mostly ignored by BF.

Is it ok to print the '\0' at the beginning?

@V-X, Perhaps it isn't. The BF code is copied, and I noticed that .join added a ., but didn't see any harm (because \0 is invisible). The + is and .split are OK - I removed the characters from the original.

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


text:
Infinite Boolean Matrix
It's geeky to see a Boolean Matrix animation, but a live one would be better. Echoing only 1s and 0s create a program that creates an infinite loop of integer matrix.

1s and 0s are randomly echoed like an error.

Please clarify. First, what does "like an error" mean? Second, what counts as "predefined functions to randomise the output", and what source of randomness are we allowed to use?

I think I just don't have to mention that, "predefined functions to randomise the output", sorry for that...

"Using only 1s and 0s create a program ..." ... that means binary coding ...

:D Thanks for that I didn't noticed, I'm glad you commented

@Daniel, I suggest that you read some questions on this site, read some answers, and write some answers of your own. When you understand better what makes a good question, try to rewrite this one.

@ugoren I'm probably did wrote a bad question, I suppose... Should I leave this question idle or delete it?

@Daniel, If you think you can fix it with a bit of work, do so and ask to reopen. If not, delete and try again when you're ready.

Like this?
PHP, 28 22
for(;;)echo rand(0,1);

For a better view:
<div style="width:800px;margin:0 auto;background-color:black;color:green;">
    <?php for(;;)echo rand(0,1); ?>
</div>

i wonder if you can use for(;;) instead of while(true)

Sure, you're right! Edited :) I also removed brackets.

Delphi XE3  (30 28)
while 0<1do write(Random(2))

I don't know Delphi, but can you use 0<1 to replace true?

Can't you use while 1 in delphi?

@user689 Nope, it requires a boolean expression.

TI-BASIC, 46
A classic, in my opinion.
"101010101010101":While 1:Disp Ans,"0"+Ans:End

doesn't seem very random. It's mostly zeroes.

Perl, 24
print-+-(rand>.5)while+1

C# 112 - 109 Thanks @masterX244
using System;namespace N{class P{static void Main(string[]a){for(;;)Console.Write(new Random().Next(0,2));}}}

Without namespace, class name...
45
for(;;)Console.Write(new Random().Next(0,2));

Uncompressed
using System;namespace N{class P{
        static void Main(string[] a) {
            for (;;)
                Console.Write(new Random().Next(0, 2));
        }
    }
}

for(;;) is shorter btw