This tag exists for historical reasons. New questions of the type previously posted under this tag are not welcome.

learn more… | top users | synonyms

8
votes
1answer
974 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
938 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
1k 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 ...
6
votes
3answers
1k views

Recognize Twin Primes by Crashing [closed]

Background Story Bob was handed the following assignment for his programming class. Please note: this is not the actual challenge. Homework assignment 11: Twin primes Input: an integer n ...
19
votes
6answers
2k views

Confuse the Dakotas

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 ...
7
votes
0answers
1k 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 ...
33
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
902 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 ...
13
votes
2answers
968 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 ...
2
votes
2answers
695 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 on out. The first iteration must be ...
2
votes
7answers
695 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
456 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); ...
34
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 ...
20
votes
1answer
1k views

Efficient error-free* encoding [closed]

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
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 ...
39
votes
47answers
6k 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): alert(([0][1]+"").slice(4,8)) Explanations: ...
13
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. ...
14
votes
2answers
861 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 ...
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 ...
1
vote
1answer
952 views

Underhanded contest (?): Anti-Virus wars [closed]

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 ...
23
votes
31answers
6k 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 ...
11
votes
3answers
727 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 ...
6
votes
8answers
640 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 sort ...
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
983 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: ...
16
votes
1answer
3k 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 ...
17
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 ...
13
votes
3answers
1k views

Write a java code to detect the JVM version [closed]

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
921 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. ...
28
votes
7answers
3k 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, ...
33
votes
3answers
2k views

Underhanded Password Hashing [closed]

In the spirit of the Underhanded C Contest, I'm starting an Underhanded Code Contest. The objective of this contest is to straightforwardly implement some code, while subtly hiding a nefarious bug ...