Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm experimenting with a new platform and I'm trying to write a program that deals with strings that are no longer than 60 characters and I'd like to populate the data store with some famous or well-known small chunks of code and equations, since programming and math goes along with the theme of my software. The code can be in any language and the equations from any discipline of mathematics, just so long as they're less than a total of 60 characters in length. I suspect people are gonna break out some brainfuck for this one.

For example,

int main(){printf ("Hi World\n");return 0;}

60 characters exactly!

Thanks so much for your wisdom!


locked by ChrisF May 13 '13 at 19:46

This question exists because it has historical significance, but it is not considered a good, on-topic question for this site, so please do not use it as evidence that you can ask similar questions here. This question and its answers are frozen and cannot be changed. More info: help center.

closed as not constructive by gnat, MichaelT, GlenH7, ChrisF May 13 '13 at 19:46

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.If this question can be reworded to fit the rules in the help center, please edit the question.

Why was brainfk censored? Can't we be adults and not tell everyone what they can and cannot read? In this context brainfk is not an obscenity. – ChaosPandion Nov 6 '10 at 21:28
I suspect this question will be closed. Try improve it to be more constructive. See: – bigown Nov 6 '10 at 23:41
@bigown: This is a good subjective one and is constructive. It's no different than asking for famous quotes. In fact, it's better, because it's asking for famous code/equation "quotes." :-) – Macneil Nov 7 '10 at 0:30
@Macneil:I think the same, but the question is poor, it can be improved. – bigown Nov 7 '10 at 4:22
@bigown: honestly, I can't really see how this question could be any more constructive. Not to doubt you or so, but very genuily asked, could you suggest an improvement to @BeachRunnerJoe? I actually very much enjoyed the answers and learned a lot from them. I'd love to see this question reopen. – Joris Meys Nov 7 '10 at 20:31

35 Answers 35

For cheap, fast, easy approximation of rotation around the "x" axis:

d = 0.0001;
y = y + z * d;
z = z - Y * d;

It's an approximation, but not one that you'd ever notice the error on


Infinite Fibonacci Sequence in Scala:

val fibs: Stream[BigInt] = 0 #:: 1 #:: { for((x, y) <- 
                                           yield x + y }

Reverse of a string recursively

 if ( str.length() <= 1)  { return str; // stopping case } 
 else { return reverse(str.substring(1)) + str.charAt(0); // recursion   } 
But in 60 characters or less! (He did say "two-liner", so does the limit apply only per line?) – Mark C Nov 8 '10 at 19:01
Oooh My answer wont qualify here! – pramodc84 Nov 9 '10 at 1:50
Sorry for the confusion, I just updated the question to specify a total of 60 characters or less, but it's a great code snippet. Question, should you be using block comments in there? – BeachRunnerJoe Nov 9 '10 at 14:42

Not famous, but a hideous way of calculating the square root of n, with the result as n.

for(double r=1;r!=n;n=r==(r=0.5*(r+(n<0?-n:n)/r))?r:n);

And yes, negative number handling is incorrect.


I like the newer feature of C# to return not null value:

var notnull = userInputName ?? "Captain NEMO";

And their lambdas are pretty sweet also:

Func<int, int, int> addfn = (a, b) => a + b;
Func<int, int> addtwofn = (a) => addfn(a, 2);
var result = addtwofn(5); // returns 7

Not the answer you're looking for? Browse other questions tagged or ask your own question.