Tagged Questions

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

9
votes
2answers
256 views

Sabotage the coding standards [on hold]

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 ...
-6
votes
2answers
186 views

What? This should run in seconds [duplicate]

Your task is simple. Write a program that should obviously run in a small time (less than 10 seconds), but instead runs in a huge time (hours or even more). This is a popularity contest, so be ...
13
votes
1answer
410 views

Sabotage a Train to Make It Run Late

"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 ...
11
votes
2answers
552 views

Underhanded Bank Account

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

Start a revolution in Oceania

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

Memory leak, without any fork bombs or looping of any kind [duplicate]

Your mission (if you choose to accept it) is to create a memory leak. In a vein similar to this question, you must write a program that will continuously allocate/consume memory until the system runs ...
76
votes
15answers
15k views

Possibly quit your job with a polyglot

Despite your protest, you have been put to work by your boss on a program that takes a single unsigned integer as input and prints the string "prime" if that integer is prime and "not prime" if it ...
0
votes
0answers
360 views

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

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 on out. The first iteration must be ...
1
vote
7answers
600 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
11answers
1k 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
753 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
331 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); ...
48
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 ...
33
votes
8answers
3k 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 ...
97
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 ...
32
votes
28answers
7k 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 ...
11
votes
0answers
659 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 ...
12
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 ...
28
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 ...
22
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() ...
274
votes
100answers
145k 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
668 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 ...
11
votes
5answers
1k 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
845 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 ...
101
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 ...
84
votes
65answers
14k 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 ...
23
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 ...
161
votes
45answers
26k 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
599 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 ...
179
votes
78answers
17k 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
557 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 ...
27
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
17answers
4k 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
750 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 ...
25
votes
77answers
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 # ...
10
votes
3answers
1k 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 ...
10
votes
2answers
785 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. ...
27
votes
7answers
3k 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, ...