Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

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,

#include<stdio.h>
int main(){printf ("Hi World\n");return 0;}

60 characters exactly!

Thanks so much for your wisdom!

share
22  
Why was brainf**k censored? Can't we be adults and not tell everyone what they can and cannot read? In this context brainf**k is not an obscenity. –  ChaosPandion Nov 6 '10 at 21:28
2  
I suspect this question will be closed. Try improve it to be more constructive. See: blog.stackoverflow.com/2010/09/good-subjective-bad-subjective –  bigown Nov 6 '10 at 23:41
8  
@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
3  
@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
show 6 more comments

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.

35 Answers

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

share
add comment

Infinite Fibonacci Sequence in Scala:

val fibs: Stream[BigInt] = 0 #:: 1 #:: { for((x, y) <- fibs.zip(fibs.tail)) 
                                           yield x + y }
share
add comment

Reverse of a string recursively

 if ( str.length() <= 1)  { return str; // stopping case } 
 else { return reverse(str.substring(1)) + str.charAt(0); // recursion   } 
share
show 3 more comments

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.

share
add comment

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
share
add comment

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