A challenge to write a program that looks like it does one thing, but, in reality, does something else. Votes reflect how non-obvious the bug is.

learn more… | top users | synonyms

-4
votes
0answers
109 views

Take down the competition! [on hold]

The Story... After one short year, you have been promoted to senior executive vice president manager of programmers (now that looks good on a resume) at the esteemed company X productions. You ...
1
vote
7answers
451 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. ...
1
vote
10answers
778 views

Implement `map()`…with bugs

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 ...
2
votes
8answers
605 views

Return Zero in the Least Intuitive Way [closed]

Write a function which returns 0 (the number, or string "0" or "zero"). At first glance it should look like your function returns a different value. Standard loopholes apply. Winner will be the ...
1
vote
1answer
263 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: int f(int x) { return f(4.0); ...
-3
votes
0answers
161 views

Calculate pi - I mean e [duplicate]

Write a program which appears to calculate pi, but which actually calculates e. The program must actually calculate; it can not load from another file, library constants, or the Internet. (Built-in ...
47
votes
14answers
7k views

“Disprove” Fermat's Last Theorem

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 ...
31
votes
7answers
2k views

It's not who votes that counts; it's who counts the votes

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 ...
91
votes
63answers
15k 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 ...
31
votes
26answers
6k views

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

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 ...
8
votes
0answers
501 views

Efficient error-free* encoding

The mission As is well known, the genetic material of all known creatures on Earth is encoded in DNA; using the four nucleotides adenine, thymine, cytosine, and guanine. (Commonly represented by ...
9
votes
6answers
1k views

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

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 ...
24
votes
42answers
4k views

Produce an unexpected word

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): var ...
21
votes
8answers
7k views

Pi is still wrong

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: loop x = rand() y = rand() ...
259
votes
96answers
138k views

Write a program that makes 2 + 2 = 5

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. ...
48
votes
18answers
6k views

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

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 ...
11
votes
14answers
2k views

Throw a null-pointer exception

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. ...
12
votes
1answer
599 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 ...
9
votes
5answers
950 views

Cheap, Fast, Good - Common Factor (Greatest)

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 ...
3
votes
1answer
738 views

Underhanded contest (?): Anti-Virus wars

Prove anti-virus software is paranoid by making a program that simply opens and alphabetically sorts a CSV file, that will get flagged as a virus (or malware/spyware/any threat really) when run. You ...
98
votes
7answers
19k views

So obviously, P = NP

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 ...
80
votes
65answers
13k views

Why isn't it ending?

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 ...
22
votes
28answers
5k views

Obfuscation Challenge

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 ...
157
votes
43answers
25k views

Trolling the troll

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. ...
11
votes
3answers
556 views

These are my lucky dice

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 ...
170
votes
74answers
16k views

What? No error?

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 ...
6
votes
8answers
528 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 ...
25
votes
2answers
1k views

Underhanded code contest: Not-so-quick sort

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 sort ...
25
votes
16answers
3k views

Write a line in program that looks useless

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
712 views

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

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: ...
14
votes
1answer
2k views

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

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 ...
15
votes
6answers
1k views

An unintentional-looking but crash-causing bug

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 ...
24
votes
74answers
6k views

Challenge: Write a piece of code that quits itself

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 might mean: #!/usr/bin/env python3 # ...
8
votes
3answers
985 views

Write a java code to detect the JVM version

The objective is to write java code that detects the JVM version relying in compatibility changes, side effects, bugs and/or undefined behavior that works in a way in one version and another way in ...
8
votes
2answers
725 views

Underhanded launcher

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. ...
23
votes
7answers
2k views

Underhanded contest: The OS war

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, ...