All Questions
129
votes
46answers
3k views
Code Chess: Fibonacci Sequence [closed]
Building upon the proven success of Code Golf, I would like to introduce Code Chess.
Unlike Code Golf, which strives for concision, Code Chess will strive for cleverness.
Can you create a clever or ...
89
votes
54answers
44k views
We're no strangers to code golf, you know the rules, and so do I
Write the shortest program that prints the entire lyrics of "Never Gonna Give You Up" by Rick Astley.
Rules:
Must output the lyrics exactly as they appear in the above pastebin. Here's the raw ...
67
votes
37answers
6k views
Write a program that always outputs “2012” - even if it's modified!
This idea is not mine, though I don't know where it originated. I once met it in a programming contest very long ago (1998, if I remember correctly). The task is to write a program in your favorite ...
56
votes
8answers
5k views
Emulate an Intel 8086 CPU
Note: A couple of answers have arrived. Consider upvoting newer answers too.
Postscript from luser droog
C++ from
JoeFish
Javascript from entirelysubjective
C from RichTX
C++ from Dave C
Haskell ...
56
votes
23answers
6k views
Contest: fastest way to sort a big array of Gaussian-distributed data
Following the interest in this question, I thought it would be interesting to make answers a bit more objective and quantitative by proposing a contest.
The idea is simple: I have generated a binary ...
51
votes
65answers
2k views
Code Golf Christmas Edition: How to print out a Christmas tree of height N
Given a number N, how can I print out a Christmas tree of height N using the least number of code characters? N is assumed constrained to a min val of 3, and a max val of 30 (bounds and error ...
51
votes
52answers
5k views
-ENDED- Do something that looks like something else
Write a snippet, a function, a programm, ... that is obfuscated in a way that it looks clear at the first sight that it does something else.
For example: write a bit of code that adds two number, but ...
44
votes
71answers
8k views
When does (x == x+2)?
The challenge:
Define x in such a way that the expression (x == x+2) would evaluate to true.
I tagged the question with C, but answers in other languages are welcome, as long as they're creative or ...
39
votes
23answers
5k views
Implement Sleep Sort
Sleep Sort is an integer sorting algorithm I found on the Internet. It opens an output stream, and for each input numbers in parallel, delay for the number seconds and output that number. Because of ...
37
votes
81answers
7k views
99 Bottles Of Beer
Recreate '99 bottles of beers on the wall'.
The desired output is this:
99 bottles of beer on the wall, 99 bottles of beer.
Take one down and pass it around, 98 bottles of beer on the wall.
98 ...
36
votes
29answers
4k views
Interpret Brainfuck
Write the shortest program in your favourite language to interpret a Brainfuck program. The program is read from a file. Input and output are standard input and standard output.
Cell size: 8bit ...
36
votes
19answers
3k views
1P5: Nested boxes
This task is part of the First Periodic Premier Programming Puzzle Push.
You get a hierarchy of items in the following format:
2
Hat
1
Gloves
which need to be put in boxes, like so:
...
35
votes
54answers
7k views
Obfuscated Hello World
Create the shortest possible obfuscated program that displays the text "Hello World".
In order to be considered an obfuscated program, it must meet at least two of the following requirements:
...
33
votes
30answers
3k views
Can you Golf Golf?
You are required to generate a random 18-hole golf course.
Example output:
[3 4 3 5 5 4 4 4 5 3 3 4 4 3 4 5 5 4]
Rules:
Your program must output a list of hole lengths for exactly 18 holes
Each ...
32
votes
63answers
5k views
Anagram Code Golf!
Challenge
Given two strings, work out if they both have exactly the same characters in them.
Example
Input
word, wrdo
This returns true because they are the same but just scrambled.
Input
...
32
votes
7answers
2k views
Robot Finds Kitten
The challenge
The shortest code by character count to help Robot find kitten in the fewest steps possible.
Golfers, this is a time of crisis - Kitten gone missing and it's Robot's job to find it! ...
31
votes
26answers
4k views
Tips for golfing in Python
What general tips do you have for golfing in Python? I'm looking for ideas that can be applied to code golf problems in general that are at least somewhat specific to Python (e.g. "remove comments" is ...
30
votes
50answers
3k views
How to randomize letters in a word
According to some controversial story, the odrer of ltteres in a wrod deos not mttaer much for raednig, as lnog as the frist and lsat lteter macth with the orignial wrod.
So, for fun, what would be ...
30
votes
2answers
1k views
Help Indiana Jones to get the treasure
Story
Indiana Jones was exploring a cave where a precious treasure is located. Suddenly, an earthquake was happen.
When the earthquake was ended, he noticed that some rocks fell from the ceiling ...
29
votes
51answers
4k views
Print the alphabet without using each vowel
Inspiration: in 1939, a man named Ernest Vincent Wright wrote a novel called Gadsby without using the letter 'e'.
Your task is to write a set of (up to 5) programs in any language (which has a ...
29
votes
7answers
3k views
Write the shortest program that generates the most compiler warnings and errors
The challenge:
Write a very short program that, when compiled, creates the most amount of compiler warnings and errors. It can be written in any programming language.
Scoring:
The score is ...
28
votes
46answers
3k views
Hello World 0.0!
I'm hoping to add a new twist on the classic "Hello World!" program.
Code a program that outputs Hello World! without:
String/Charachter literals
Numbers (any base)
pre-built functions that ...
27
votes
75answers
4k views
What's my name? Produce the name of the language indirectly
Produce only the name of a programming language using only the facilities of the language itself. The name of the language can only be invoked indirectly, i.e., from non custom environment variables, ...
27
votes
8answers
1k views
Encode Images into Tweets (Extreme Image Compression Edition)
Based on the very successful Twitter image encoding challenge at Stack Overflow.
If an image is worth 1000 words, how much of an image can you fit in 114.97 bytes?
I challenge you to come up with a ...
27
votes
22answers
2k views
HelolW rdlo (A threading challenge)
I have a challenge for you:
Print "Hello World" using any language.
Each character must be printed from its own, unique thread
That's it. Obviously, as there's no guarantee that the threads will ...
27
votes
4answers
900 views
Underhanded Password Hashing
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 ...
26
votes
6answers
2k views
Create a User-Profile Mini-Game
Yesterday, I stumbled on a very clever thing.
Yes, that's a working implementation of Tic-Tac-Toe on a user profile page, from @minitech. Of course, the moment I saw it, I had to reverse engineer ...
25
votes
8answers
2k views
Swapping heightmaps to depthmaps
Description
Your task is to output a 'depthmap' - that is, a heightmap of an object but not seen from its top but from its front.
For example, consider the following object as shown on the image. ...
25
votes
2answers
2k views
What can you do in a 4k data URI?
Bounty is over, thephpdeveloper wins with Conway's Game of Life
The web platform today is advancing at a rapid rate. Features like CSS3 animations, transforms, drop shadows and gradients, ...
25
votes
1answer
794 views
Facial Recognition
The aim of this task is to identify, clean up, and mark out all the faces in any given 'image'.
What's in a face?
A face will be a ZxZ square where Z is an odd integer greater than 1. The top left ...
24
votes
59answers
3k views
The alphabet in programming languages
Our task is to, for each letter of the (English) alphabet, write a program that prints the alphabet, in a language whose name starts with that letter.
Input: none
Output:
abcdefghijklmnopqrstuvwxyz
...
24
votes
53answers
4k views
Fibonacci function or sequence
Write the shortest code that either:
Generates a Fibonacci sequence (either in standard output, or as a stream)
Calculates, given n, the nth Fibonacci number
(I gave both options in case one is ...
24
votes
24answers
2k views
Print a string in as few distinct characters as possible
The task is simple: print The quick brown fox jumps over the lazy dog using as few distinct characters in your source code as possible.
print "The quick brown fox jumps over the lazy dog" has a score ...
24
votes
9answers
2k views
Advanced Code Golf - Write a small HTTP server
Your challenge is to write a code-golf HTTP server that accepts GET requests. It obviously doesn't have to be fully featured, but it must serve files from a directory.
Rules:
The HTTP server must ...
23
votes
5answers
1k views
Fault-Tolerant Hello World (a.k.a. the Interview)
At the end of your interview, the Evil Interviewer tells you, "We make all of our applicants take a short coding test, to see if they really know what they are talking about. Don't worry; it's easy. ...
23
votes
19answers
2k views
1P5: Iterated Prisoner's Dilemma
This task is part of the First Periodic Premier Programming Puzzle Push and is
intended as demonstration of the new king-of-the-hill challenge-type proposal.
The task is the write a program to play ...
22
votes
53answers
3k views
Print a line 10 times (in the most creative way possible!) [closed]
Inspired by some of the other answers to this SO question http://stackoverflow.com/questions/11567823/print-a-line-10-times-in-obj-c/11568151#11568151 your task is to print "Print this line" 10 times ...
22
votes
12answers
2k views
Shortest Game of Life
Conway's Game of Life is the classic example of cellular automation.
Your mission, should you choose to accept it, is to code the shortest Game of Life implementation in your favourite language.
The ...
22
votes
3answers
2k views
Solve the eight queens problem at compile-time
Can you solve the eight queens puzzle at compile-time?
Pick any suitable output format.
I'm particularly interested in a C++ template metaprogramming solution, but you can use languages that have ...
22
votes
31answers
4k views
Rand5() to Rand7()
You are provided with a function Rand5(). This function returns perfectly random (equal distribution) integers between 1 and 5.
Provide the function Rand7(), which uses Rand5() to produce perfectly ...
22
votes
6answers
2k views
Bridges and Tunnels
You are responsible for building a new freeway. However, it leads through
mountainous lands and therefore needs numerous bridges and tunnels. The
freeway itself should stay at a single level.
Input
...
21
votes
13answers
2k views
Generate the Stack Overflow logo
The challenge is to generate an image similar to the StackOverflow logo:
The output must contain:
Image size 64*64 or greater
A gray |__| shaped base
A curved segmented stack coming up from the ...
20
votes
57answers
4k views
Print a Christmas Tree
The Challenge
Print a nice Christmas tree with it's own star at the top using the shortest code possible. The tree star is an asterisk (*) and the tree body is made out of 0 The tree must be 10 rows ...
20
votes
50answers
2k views
Golf you a quine for great good!
Using your language of choice, golf a quine.
No cheating -- that means that you can't just read the source file and print it. Also, in many languages, an empty file is also a quine: that isn't ...
20
votes
25answers
3k views
Draw A Sierpinski Triangle
The Sierpinsky Triangle is a fractal created by taking a triangle, decreasing the height and width by 1/2, creating 3 copies of the resulting triangle, and place them such each triangle touches the ...
20
votes
20answers
4k views
Print 1 to 1000 in C++ without semi-colons
Following this popular question, present your solution which prints the numbers 1 to 1000 (all of them, not the string "1 to 1000" verbatim or something funny) in C++ without using any semi-colons. ...
20
votes
22answers
2k views
Shortest code to determine if a string is a palindrome
A palindrome is some string that is spelled the same way both backwards and forwards. For instance, 'Eva, can I stab bats in a cave?' is a palindrome (EVACANISTAB | BATSINACAVE)
For this code golf, ...
20
votes
11answers
3k views
Drawing a cube in ASCII art
Task description:
Draw a cube in ASCII art in roughly a cabinet projection.
Monospaced fonts often have characters that are about twice as high as they are wide. Since the input is the length of the ...
19
votes
16answers
2k views
Tips for golfing in C
What general tips do you have for golfing in C? I'm looking for ideas that can be applied to code golf problems in general that are at least somewhat specific to C (e.g. "remove comments" is not an ...
19
votes
10answers
1k views
Meta Golf Challenge
On that challenge you have to solve that challenge.
Contest is over! Check the end of the question
Specs:
Write the smallest code (Any language*).
The score of an answer is the sum of:
Code ...