Wikipedia:Reference desk/Archives/Computing/2011 July 6

From Wikipedia, the free encyclopedia
Computing desk
< July 5 << Jun | July | Aug >> July 7 >
Welcome to the Wikipedia Computing Reference Desk Archives
The page you are currently viewing is an archive page. While you can leave answers for any questions shown below, please ask new questions on one of the current reference desk pages.


July 6[edit]

10-line C++ program that would change the world[edit]

Resolved

I'd like a sample 10-line C++ program that could change the world (you don't have to include the part that would change the world). the point is, there would be one part, maybe inside the loop, that's ?????, and then I would just figure out that one part to change the world. any takers? 188.29.111.138 (talk) 23:40, 6 July 2011 (UTC)[reply]

note: it has to be possible. 188.29.111.138 (talk) 23:41, 6 July 2011 (UTC)[reply]
Sure, just say what in the world you want changed. Shall we sit very still while you debug the code? You are really asking for the power of Aladdin's jinni (genie). The jinni met a blonde and offered her one wish that could be literally anything in the World. Blondie responded "I want Gucci sunglasses!". The jinn replied "Of course I can give you that. But don't you want to use this unique opportunity to remove all the hunger, war and suffering in the World?". Blondie replied "Yes, I'll do that instead. Let's have Gucci sunglasses for everyone". Cuddlyable3 (talk) 23:58, 6 July 2011 (UTC)[reply]
#include <iostream>
using namespace std;
int main()
{
  int theWorld = 0;
  cout<<theWorld;
  // ???
  cout<<theWorld;
  return theWorld;
}
Strictly, I think the ANSI standard for C++ requires a newline at the end of the file; but that would make this program 11 lines. Fortunately, most modern C++ compilers are not so pedantic; this compiles in g++ and in XCode. In case it is not obvious, theWorld is changed on line 7. Nimur (talk) 00:46, 7 July 2011 (UTC)[reply]
Put the newline at the end, get rid of using namespace std; (using is usually a bad idea anyway — why have namespaces if you're not going to use them?), and use std::cout. --Trovatore (talk) 02:20, 7 July 2011 (UTC)[reply]
Honestly! You have a chance to change the world in any way you want, and the best you can do is to increment it? 188.29.86.142 (talk) 00:53, 7 July 2011 (UTC)[reply]
My change to theWorld is merely incremental. I've made peace with that. But of course, you still have the opportunity to change line 7 to anything you like, as you said you were going to. All you have to do is "just figure out that one part"... Nimur (talk) 01:23, 7 July 2011 (UTC)[reply]
I took the liberty of removing your highly offensive "theWorld++;" in the middle of the program, replacing it with // ??? per your indication. I mean, come on. The world - the real world - already gets incremented in the main loop, namely the number of nanoseconds, without anyone doing anything. Hopefully we could make a more fundamental change.
I suspect I could turn it back-to-front in 10 lines. I'd like to be able to turn it upside down though, which might be harder. AndyTheGrump (talk) 01:01, 7 July 2011 (UTC)[reply]
Thinking further, the Bible tells us that in the beginning the World was without form and void - presumably a null pointer. I think that what is required is to make theWorld point to an instance of class World. (Though personally, I suspect that the Creator programs in Java...). AndyTheGrump (talk) 01:38, 7 July 2011 (UTC)[reply]

And, not to be flippant guys, but I meant actual code that would actual do something. For example:

void SUPERquickSort(int arr[], ???) {

     int i = ???, ???
     ???
     /* recursion */
     if ???
           SUPERquickSort(arr, ???);
     if ???
           SUPERquickSort(arr, ???);

}

Would be the PERFECT example of what I'm asking about... before 1960. That's because quicksort was invented in 1960, so if it were before 1960 now, then I could fill in the ???'s in the above to get quicksort. You see how that works? So, please give me the same thing that I can use today to change the world, just by filling in the ????'s. Ten lines or fewer. Thank you! 188.28.246.47 (talk) 02:19, 7 July 2011 (UTC)[reply]

OK, you've answered your own question. Invent a sorting algorthm that's faster than quicksort.
But since you asked, here's one I'd like to see :
// Pathfinding algorithm significantly faster than A* with finite runtime in all situations.
NodeList* A_ultra_star(graph* pGraph, node* pStart, node* pEnd )
{
    if( pStart == pEnd ) return NULL;
    else
    {
       NodeList* BestPath = NULL;
       // ?????
       return BestPath;
    }
}
APL (talk) 02:39, 7 July 2011 (UTC)[reply]
Thanks! I marked this resolved. 188.28.246.47 (talk) 02:57, 7 July 2011 (UTC)[reply]
p.s. don't get your hopes up - I meant the thread! 188.28.246.47 (talk) 02:58, 7 July 2011 (UTC)[reply]
Perhaps you would be interested in List of unsolved problems in computer science? I think it is generally agreed that a significantly faster Integer factorization algorithm would have far-reaching implications. 130.88.73.71 (talk) 14:13, 7 July 2011 (UTC)[reply]