This challenge was inspired by this StackOverflow Meta post. In it, @hakre says:

I've seen a project really written by Stackoverflow (a noob copies together from SO here and SO there), attribution normally never is done which results in rights termination under CC. (sic)

Your mission is to make the most interesting program you can -- without ever writing a single line of code. You can only use code which is already written for you, both in questions and answers from StackOverflow. All you can do is duct tape it all together the best you can. And of course, it's very important that we provide appropriate attribution so that we don't get our rights terminated.


  1. You must include links to the questions/answers you used in your answer.
  2. You may not modify the code you find, with the following exceptions:

    a. You may rename variables, functions, and methods. (This doesn't mean you can change a method invocation, by changing, say scanner.nextInt() to scanner.nextLine() and claiming that you're changing a method name. The change must be in the definition or reference to the same entity.)

    b. You may adjust indentation appropriately.

    c. You can assume that the proper modules are loaded for the code snippets to work. (e.g., import statements for Java and Python, using statements for C# and C++, and their equivalents in all languages) If the code snippet includes the imports for you, you can move them to the top of the code.

    d. If the language requires the code to be in some kind of method body to execute (e.g., public static void main(String[] args) for Java, static int Main(string[] args) for C#, and so on), you can wrap your code in the appropriate method. But the contents of that main method must remain unmodified.

  3. You must supply an explicit list of any variable/method/function/class rename-ings performed.

  4. You can't take snippets of snippets (meaning if you take a code block from a post, you take the whole thing)
  5. Provide a brief description of what the code does for people who aren't intimate with the language you're using.
  6. Popularity contest, so the most upvotes wins!

Boring Five Minute Example (Python 3)

Description: Reads a bunch of log files from the current directory and randomizes the lines in them (exciting, right? This would totally win a popularity contest)


import glob
import random

for file in glob.glob('log-*-*.txt'):
    # Etc.
    with open(file) as f:
        content = f.readlines()
        # shuffle the list in place 

        # print it

Legal Modifications

  • Renamed fname to file from link 1
  • Renamed b to content from link 2


  1. https://stackoverflow.com/a/3277516/1435657
  2. https://stackoverflow.com/a/16737991/1435657
  3. https://stackoverflow.com/a/4918520/1435657
  • 8
    \$\begingroup\$ I really like the idea, but I think this question would immensely benefit from limiting the scope to a particular task. That would a) inspire more creativity because you can't just copy together anything and b) it would leave open the possibility to reuse this (interesting) type of question later on in a different context. If you just leave it as "do whatever you want", all further questions like this will be duplicates. I'm afraid as it stands, I have to close-vote as "too broad" because it torpedoes possibly interesting future questions. \$\endgroup\$ May 8, 2014 at 1:33
  • 2
    \$\begingroup\$ I should add, no I don't want this to become the next code-trolling, where everyone posts a "Add two numbers", "Split this string", with a "duct-tape-coding" tag. I think we can handle this more creatively than that. I would just like to leave some room for other interpretations of this kind of restricted-source competition. \$\endgroup\$ May 8, 2014 at 1:35
  • 1
    \$\begingroup\$ @m.buettner I'm also not sure that CodeGolf.SE would necessarily benefit from lots of questions like this, for the same reasons you mention: why have "split a string using SO code", "get a random number from 1-100 using SO code", and so forth? But that's just my opinion. I'm far from a CodeGolf.SE pro. :) \$\endgroup\$
    – asteri
    May 8, 2014 at 1:41
  • 3
    \$\begingroup\$ I'm going to remove the random custom tag for now because the need for it hasn't been established (and it will very likely be unnecessary and add no value). \$\endgroup\$
    – asteri
    May 8, 2014 at 2:16
  • 1
    \$\begingroup\$ I agree that we need to be careful with flooding PPCG with questions like this, just because it's fun and novel. But I think a few genuinely different questions could come of this... like a maths-based, a graphics-based one, one that uses code-golf scoring and a polyglot challenge maybe. Hence, I'd prefer the scope to be limited. In terms of people just copying the challenge without anything substantial, I think it's the duty of the community to be a bit stricter in "closing as duplicate" when it comes to new challenge types. \$\endgroup\$ May 8, 2014 at 9:45

1 Answer 1


C - one operation calculator

Let's have this for a start.
It's actually quite hard to find pieces of C programs that aren't whole programs. I had most trouble with declarations.

// http://stackoverflow.com/a/2911978 Block #1 (changed i to a)
static int a = 10;
// http://stackoverflow.com/a/2911978 Block #1 (changed i to b)
static int b = 10;
// http://stackoverflow.com/a/442647 Block #1 (changed c to op)
unsigned char op = (unsigned char)-1;
// http://stackoverflow.com/q/3711048 Inline block #1
int main()
// http://stackoverflow.com/a/14902422 Inline block #1
// http://stackoverflow.com/q/217074 Inline block #2 (changed i to a)
scanf("%d", &a)
// http://stackoverflow.com/a/23353870 Inline block #2
// http://stackoverflow.com/q/217074 Block #2 (changed c to op)
scanf("%c", &op)
// http://stackoverflow.com/a/23353870 Inline block #2
// http://stackoverflow.com/q/217074 Inline block #2 (changed i to b)
scanf("%d", &b)
// http://stackoverflow.com/a/23353870 Inline block #2
// http://stackoverflow.com/a/4173188 Block #2
int result = 0;
result = (op == '*') ? a * b : result;
result = (op == '/') ? a / b : result;
result = (op == '+') ? a + b : result;
result = (op == '-') ? a - b : result;
// http://stackoverflow.com/a/3245525 Block #2
printf("\n");  /* prints newline */
// http://stackoverflow.com/q/4138649 Inline block #1
return 0;
// http://stackoverflow.com/a/14902422 Inline block #2

Takes a simple integral operation like 3+151 or 41/2 on stdin and outputs the result to stdout.

  • 1
    \$\begingroup\$ Interesting re-use of the same code block and renaming the variable twice. I didn't even think of that! +1 \$\endgroup\$
    – asteri
    May 8, 2014 at 13:04

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