Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

All Questions

9
votes
13answers
3k views

Reversed language name [closed]

You should code a piece of code that looks like it outputs the language name but actually outputs the name reversed. E.g. a Python program should look like it outputs ...
4
votes
4answers
2k views

April Fools Day! [closed]

Your challenge is simple: write a program or function which appears to print the first ten numbers of any integer sequence (on OEIS, the answerer may choose which sequence), but instead prints the ...
9
votes
1answer
3k views

You call this optimized? [closed]

The task is simple, post 2 code snippets that perform the same task, where one seems very optimized at first glance, but actually is significantly slower than the other. Only one rule: Both ...
2
votes
5answers
2k views

Like a quine, but not [closed]

Very simple, write a program that at first glance appears to be a quine, but is not. Upon running, the program actually prints the source to a real quine, obviously distinct from the original program ...
18
votes
8answers
2k views

Classic Proof Fallacy [closed]

The Background So, we all know the classic proof that goes like this: a = b a² = ab a² - b² = ab - b² (a-b)(a+b) = b(a-b) (a+b) = b b+b = b 2b = b 2 = 1 (Ha ha!) Of course, the mistake is that ...
52
votes
3answers
5k views

Quiche Lorraine [closed]

Since it was Pi day recently, I have noticed a number of challenges that ask you to calculate pi. Of course, a quiche lorraine is not quite a pie (you can claim a Bonus Score¹ of +1 if you guessed ...
20
votes
7answers
3k views

Confuse the Dakotas [closed]

You have been hired by the government of North Dakota to encrypt the state's communications. Write two programs, one to encrypt a message and one to decrypt that message. The government is not really ...
9
votes
0answers
2k views

Break Stack Exchange [closed]

Trick the user that StackExchange is broken: It can be done in several ways: Your program starts a browser in some certain way (with a proxy server, for example); Your program shows static picture; ...
35
votes
9answers
2k views

Sabotage the coding standards [closed]

There are various coding standards enforced at software companies which have the goal of increasing code reliability, portability, and, most importantly, readability in code written jointly by ...
15
votes
1answer
2k views

Sabotage a Train to Make It Run Late [closed]

"I want to go to the Araby bazaar to buy a present for the one I have fallen in love with. However, if I arrive too late all the stores will be closed and I won't be able to buy anything. Can you help ...
13
votes
2answers
1k views

Underhanded Bank Account [closed]

You are working as a programmer for a bank. Your task is to write a program that handles the transactions from one bank account to another. The program should do the following: Run in an infinite ...
78
votes
7answers
9k views

Start a revolution in Oceania

Winners (decided 14/09/14) Winning answer by Markuz (Python) - 63 votes Runner up by kuroi neko (PHP) - 55 votes Introduction You are in the world of the book Nineteen Eighty-Four by George Orwell....
3
votes
2answers
801 views

Print all multiples of 32 from 0 to `n`…imperfectly [closed]

Objective: Print all multiples of 32 from 0 to an arbitrary number n. Rules: One argument will be given: a single integer from 0 to 231 - 1. This will be n here ...
2
votes
7answers
943 views

Break out of a loop [duplicate]

Now that we have over a hundred ways to get stuck in a loop, the next challenge is to get out. Specifically, write a piece of code with a (seemingly) infinite loop, but somehow manage to break out. ...
0
votes
11answers
1k views

Implement map()…with bugs [closed]

EDIT: The behavior may be inconsistent. Also, associative arrays are permitted. Make a function that iterates through an indexed array, mapping a function of a single argument to each member of the ...
1
vote
1answer
595 views

Fake infinite loop [closed]

The challenge is to write a fake infinite loop in any imperative programming language. At first sight, the code should seem not to halt at all. As a naive example: ...
49
votes
13answers
11k views

“Disprove” Fermat's Last Theorem [closed]

Write a program, in the language of your choice, that appears to successfully find a counterexample to Fermat's Last Theorem. That is, find integers a, b, c > 0 and n > 2 such that an + bn = cn. Of ...
33
votes
8answers
3k views

It's not who votes that counts; it's who counts the votes [closed]

The scenario You live in a country that is having a presidential election. Each voter gets one vote, and therefore there is a firmly-entrenched two-party system. (Third parties exist, but get ...
107
votes
65answers
20k views

Random script that isn't actually random

As a little joke in the office someone wanted a script that randomly picks a name, and said person will make a round of drinks. Let's call the people John, Jeff, Emma, Steve and Julie. I thought it ...
38
votes
32answers
10k views

Deletion of a blank line in source code which causes unexpected functionality [closed]

Write a script that works fine when a blank line is present in the flow of program logic, but breaks or causes unexpected behaviour when that line is removed. Avoid standard loopholes and stupid ...
278
votes
33answers
75k views

Make it look like I'm working

Often, I find myself running a script or query that will take a significant amount of time to run. I can leave that script open and enjoy some guilt-free procrastination. Now, what if I could write ...
12
votes
6answers
2k views

Write a sorting program that looks erroneous but it is actually correct [closed]

Write a program that sorts a vector of numbers (or any type of element) that looks like having one or more bugs, but it is actually ok. The code must be clear. Someone looking over the code must ...
42
votes
47answers
7k views

Produce an unexpected word [closed]

The goal is to write program that will produce a word unexpectedly (program doesn't look like it is going to produce a word). Example (JavaScript): ...
27
votes
8answers
8k views

Pi is still wrong [closed]

Pi is Wrong A common method of computing pi is by throwing "darts" into a 1x1 box and seeing which land in the unit circle compared to the total thrown: ...
393
votes
156answers
235k views

Write a program that makes 2 + 2 = 5 [closed]

Write a program that seemingly adds the numbers 2 and 2 and outputs 5. This is an underhanded contest. Your program cannot output any errors. Watch out for memory holes! Input is optional. ...
53
votes
18answers
8k views

Program that adds all natural numbers and yields -1/12 [closed]

As you might know there is a mathematical fun-fact that if you add all natural numbers you end up with... -1/12 (see Wikipedia here). Of course this is very strange result and can not be obtained by ...
14
votes
14answers
3k views

Throw a null-pointer exception [closed]

Your task is to generate a null-pointer exception. That is, your program must accept a value which it expects to be non-null, and throw an exception/error or crash because the value is null. ...
15
votes
2answers
1k views

Pathological Sorting

Pathological Sorting Your boss has demanded that you develop a sorting algorithm to improve the performance of your company's application. However, having written the application, you know that you'...
10
votes
5answers
1k views

Cheap, Fast, Good - Common Factor (Greatest) [closed]

Inspired by Cheap, Fast, Good, we're going to implement an algorithm which has exactly two of them. The Math Given two nonzero integers a and b, the GCF d is the largest integer that divides both a ...
111
votes
7answers
24k views

So obviously, P = NP [closed]

SAT is the problem of determining whether a boolean expression can be made true. For example, (A) can be made true by setting A=TRUE, but (A && !A) can never be true. This problem is known to ...
95
votes
73answers
18k views

Why isn't it ending? [closed]

Your task: To write a program that should obviously terminate, but it never (to the extent of a computer crash) does. Make it look like it should perform a simple task: adding numbers, printing ...
24
votes
32answers
7k views

Obfuscation Challenge [closed]

You are to write a program that does one of the following. Only displays "Hello World" does nothing else Quits and nothing else (no output, no errors.) Takes one line of input, parses it as an ...
184
votes
50answers
35k views

Trolling the troll [closed]

A troll has captured you and is forcing you to write malware (defined as a program that damages the computer that runs it). The troll can read and understand code, but is not so good at spotting bugs. ...
10
votes
3answers
862 views

These are my lucky dice [closed]

Implement a program or function which simulates common dice for role playing games. It should handle at least the d6 and d20, the two most common dice. However, it should work as stereotypical gamers ...
197
votes
81answers
24k views

What? No error? [closed]

Your task is simple. Write a program that should obviously produce an error on first glance either when compiled or run, but either doesn't or produces some other unrelated error. This is a popularity ...
7
votes
4answers
525 views

Create a flaky test [closed]

Create a piece of code and a genuinely-looking test for it. However, the test must be flaky: when run multiple times, it must sometimes fail, sometimes succeed. Be creative and try to hide the ...
6
votes
8answers
741 views

Loophole for other challenge [closed]

You are to post an answer you posted that exploited a loophole in the challengers question. Bonus points if it caused them to rewrite the question. For example, one challenge was to write a program ...
28
votes
2answers
2k views

Underhanded code contest: Not-so-quick sort [closed]

The Task Write a program, in the language of your choice, that reads lines of input from standard input until EOF, and then writes them to standard output in ASCIIbetical order, similar to the ...
26
votes
17answers
4k views

Write a line in program that looks useless [closed]

Write some program (the size doesn't matter), and put a line that looks useless, but it's actually not - if it would be removed, the program would crash, or do something wrong. Feel free to mark the ...
7
votes
7answers
1k views

Find the largest prime under a number… but only for the test cases [closed]

The Code Your program should take an input of n > 2 and output the largest prime less than or equal to n. You can choose how the number is input (standard input, read from a file, etc). For example: ...
17
votes
1answer
3k views

Hide evil code - print files containing a given string anywhere in a directory tree [closed]

The point of this puzzle is to learn how a malicious code can be hidden and discovered in a program. A person is asking the question: Plz give me some code that how can I search a file may be in ...
19
votes
6answers
2k views

An unintentional-looking but crash-causing bug [closed]

There are a range of questions revolving around this concept, but these all seem to just involve causing a crash, resulting in many answers which are very obviously designed to cause a crash. So the ...
39
votes
86answers
9k views

Challenge: Write a piece of code that quits itself [closed]

I'm searching (am I?) for a piece of code that quits immediately - in an absolutely unconventional way. This does not mean: System.exit((int) 'A'); (Java). It ...
11
votes
2answers
1k views

Underhanded launcher [closed]

Your goal is to write a super-secret program which launches another (independent) program. You don't have to provide the payload in your answer, it can be any program name your program will launch. ...
29
votes
7answers
4k views

Underhanded contest: The OS war [closed]

We all know how the discussion about which is the best operating system caused a lot of flame-wars. Your goal is now, to provide decisive "proof" that your favorite operating system is better... ah, ...