Code-golf is a competition to solve a particular problem in the fewest bytes of source code. If you want to score by characters instead of bytes, state this explicitly in the challenge. If source code length is not the primary scoring criterion, consider using another tag instead.

learn more… | top users | synonyms

0
votes
0answers
55 views

Find the Bacon Number

Challenge Given the name of an actor, you must find their Bacon number. You must use IMDB, and if there are multiple actors of the same name, you must choose the first. You must only use the films ...
4
votes
1answer
143 views

Multiply two numbers without using any numbers

You are given as input two strings representing positive integers, such as "12345" and "42". Your task is to output a string containing their product, "51890" in this case. The twist is that you may ...
12
votes
3answers
264 views

Book Stack Sort

When stacking books you usually want to put the largest ones at the bottom and the smallest ones at the top. However, my latent OCD makes me feel very uneasy if I've got two books where one is shorter ...
26
votes
36answers
2k views

Write lines in detention

Introduction Bad news guys - you got detention. Your English teacher doesn't understand this site and wants you to "stop doing math on your digital dohickeys, this is English class!" She sentenced ...
5
votes
0answers
246 views

Circle packing in a rectangle

Your task is to write a program that finds the largest radius that N circles can have and still fit inside of a rectangle that is X by Y pixels large. (similar to this wikipedia article) Your program ...
0
votes
0answers
177 views

Find a representative submatrix [on hold]

You have a matrix of size m x n. Each cell in the matrix has a (uniformly) random integer value v, where 0 ≤ v < i, and i ≤ (m x n). (Meaning, the matrix contains a maximum of m x n distinct ...
12
votes
17answers
3k views

The Ackermann function

The Ackermann function is notable for being the one of the simplest examples of a total, computable function that isn't primitive recursive. We will use the definition of A(m,n) taking in two ...
17
votes
8answers
1k views

Short Deadfish Numbers

Deadfish is one of the best known non Turing-complete programming languages. It has only one accumulator (which starts at 0) to store data, and only four commands: i - Increment the accumulator s - ...
-6
votes
1answer
158 views

Print Hamlet's monologue using as few characters as possible [duplicate]

The task here is to print the text below, using as few characters as possible in your code. You can't use any external resource. (file, stdin, network) To be, or not to be: that is the question: ...
16
votes
17answers
2k views

Sierpinski Carpets

Who doesn't love a good fractal? The Sierpinski Carpet is a classic example of a fractal. To complete this task, you will be required to generate a carpet of type and print the resulting image to ...
5
votes
7answers
2k views

Catch some drug dealers

(spoilers on decade-old TV show below) In the HBO show "The Wire", the dealers use a system of encoding phone numbers where they "jump the 5" on the number pad. +-----------+ | 1 | 2 | 3 | ...
0
votes
2answers
76 views

Approximated (unsorted) square from a set of values [on hold]

So a colleaque came with this problem lately and I want to challange you to solve the problem in the code-golf style, shortest solution in any language wins. The Problem: Given is a random set of ...
39
votes
8answers
7k views

Draw the South Korean flag

When I stumbled upon this question I remembered that I had also once seen precise rules for the construction of the South Korean flag. And this is quite a different construction. Source: Wikipedia ...
12
votes
5answers
1k views

Tips for golfing in Pyth

Pyth is a Python-inspired procedural programming language, created by PPCG user isaacg. What general tips do you have for golfing in Pyth? I'm looking for ideas that can be applied to code golf ...
1
vote
4answers
101 views

Tips for Golfing in BBC BASIC

What general tips do you have for golfing in BBC BASIC? I'm looking for ideas that can be applied to code golf problems in general that are at least somewhat specific to BBC BASIC (e.g. "remove ...
15
votes
1answer
429 views

Give me a haircut!

This is my head: \ /-- -| / -\ | | | \ \ \ \ | --\ | \ | | / |--| / / | /|- //--| / | | | || //\ | | \ /| // \ | It consists of exactly eight hairs. My hair ...
6
votes
1answer
365 views

Animating the Separation of Fluids by Density

Let the characters 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ represent the particles of 36 immiscible fluids, each more dense than the last. So the 0 fluid is the least dense and floats on all the others, ...
13
votes
6answers
1k views

Pixel art, episode 2: Display the map 1-1 of Super Mario Bros

Last challenge (Pixel-art, episode 1: display Super Mario) was just a training... (and you completed it in amazing ways, thanks!) This time, you have to work a little bit more. You have to display ...
-1
votes
0answers
114 views

An expression in as few instructions as possible [closed]

( 7(x+2) + (y-1)/9 )^2 Solve this expression in as few assembly instructions as possible. I managed to do it in 9 instructions. x and y are declared in .data and are of type DWORD. Working with ...
5
votes
2answers
498 views

Draw a Golden Spiral!

Given a number n, you must output a golden spiral with the number of quarter turns being n. The spiral must be completely black and the background must be completely white. This must be output as a ...
8
votes
8answers
470 views

Verify Magic Square

A magic square is a square array of numbers with side n consisting of the distinct positive integers 1, 2, ..., n² arranged such that the sum of the n numbers in any horizontal, vertical, or main ...
23
votes
20answers
5k views

Pixel-art, episode 1: display Super Mario

it's a-me! Today's task is simple: write a program, or a function that displays the idle small Mario sprite, from Super Mario Bros, on NES, over a blue background. Any kind of entry is valid as long ...
9
votes
2answers
312 views

What are you waiting for? (A mahjong solver)

Idea thanks to @MartinBüttner from a discussion in chat Mahjong is a tile game that is immensely popular in Asia. It is typically played with four players, and the goal of the game is to be the first ...
6
votes
1answer
233 views

Solve a Tetris Puzzle (pack predefined shapes into optimal form)

The challenge is about finding an optimal solution on how to place a number of given shapes. It is oriented on the principle of Tetris, where it is optimal to pack the given pieces as tight as ...
6
votes
4answers
416 views

Hole 2 - Prime Quine

Find Hole 1 here. Make a quine that, when run, outputs its own source code block multiple times. In fact, it must output it n times, where n in the next prime number. I think an example shows it ...
7
votes
2answers
740 views

Emulate the Professor's typing

Emulate the Professor's typing Background Unfortunately, the Professor is not able to use his keyboard properly: whenever he is meant to use the Shift key, he presses Caps Lock once before typing, ...
56
votes
40answers
6k views

Cops and Robbers: Regex Golf

The Cops' Challenge You are to write a short, obfuscated regex, satisfying the following spec: You may choose any flavour that is freely testable online. There's a good list of online testers over ...
17
votes
7answers
2k views

Print all Country Codes

ISO 3166-1 is the standard that defines all the country codes. The well-known two-letter codes (US, GB, JP, etc.) are called Alpha-2 codes. With two letters, there are only 262 = 676 possible codes, ...
5
votes
6answers
525 views

I'm feeling lucky

Write the shortest function that returns the content of the first result of a google search ("I'm feeling lucky"). Exemple: lucky('cat'); returns something like: <!DOCTYPE html> ...
5
votes
1answer
294 views

Notes to Tablature

Challenge Given a list a notes, you must return the corresponding tablature. Notes The notes must be in the range of A to G inclusive and the octave range being 2 to 6 inclusive. The format is ...
58
votes
90answers
14k views

Sing Happy Birthday to your favourite programming language

Your favourite programming language has just had a birthday. Be nice and sing the Happy Birthday song to him (or her, if you will). Of course you should accomplish this by writing a program in that ...
11
votes
2answers
699 views

9 Holes of Code Golf - Kickoff

There has already been a 9 Hole Challenge (and another one here), but that was soooo last year. And besides, I have only been around for 2 months (although it seems like forever). And it is ...
7
votes
11answers
571 views

Bulgarian Solitaire

Bulgarian Solitaire is a single-player game made popular by Martin Gardner in his mathematical column in Scientific American. You have N identical cards, split into piles. You take a card from each ...
10
votes
9answers
1k views

Calculate the troll toll to safely pass

Inspired by http://puzzling.stackexchange.com/q/626 In your adventures you arrive at a series of 7 bridges you have to cross. Underneath each bridge lives a troll. In order to cross the bridge, you ...
3
votes
8answers
444 views

Golfing the Core

Note: although this is tagged as Python, other languages are permitted Challenge What you have to do is write the shortest functions to perform the same actions as the following Python 2 built in ...
-5
votes
2answers
154 views

Unique code generation [closed]

As input, you are given a positive integer n. Output a code in response. Each n should generate a unique code. There are some constraints on the code that it outputs: The code must be 7 or more ...
6
votes
3answers
504 views

Riemann Series Theorem

The Riemann series theorem states that the terms of a conditionally convergent series can be permutated such that the resulting series converges to an arbitrary value. The Challenge Write a program ...
6
votes
3answers
395 views

Anti-aliased ASCII Aureoles

Consider the following ASCII image of five concentric anti-aliased ASCII aureoles: ........ .@..............@. ..... ..... .@.. ...
12
votes
7answers
2k views

Print the Retro Rocket

(inspired by this SO question) You are given as input a single positive integer n. In as few characters as possible, output a rocket in ASCII art with a head, a tail, and a body composed of n ...
9
votes
1answer
229 views

Shubbles and Smoles - Part I

The Setup Consider an oddly-shaped box containing 29 numbered cells as shown in Fig. 1 below. Inside this 2D box are two species of square-shaped animals: shubbles and smoles. Fig. 1 (a) shows ...
-3
votes
9answers
287 views

Count multiples of 3

Given n numbers and he decides to count all the multiples of 3 from the n numbers. INPUT 1. The first line of input contains the integer n. 2. Then n lines follow, each containing a positive ...
11
votes
2answers
622 views

Ray-trace a shiny sphere

I downloaded POV-ray and rendered this shiny metal sphere 90s style: Your task is to do the same thing, but to do it by implementing the rendering engine yourself in as few bytes as possible. You ...
18
votes
3answers
687 views

2D Collision Detection

This challenge is based on actual collision detection I had to write for a simple game recently. Write a program or function which, given two objects, returns a truthy or falsy value depending on ...
37
votes
13answers
5k views

Periodic Table of Elements - Code Golf

Based on Practical Golf - US States Your task is to find the abbreviation (symbol) of an element given the element name, up to and including ununoctium (118). Use the periodic table on Wikipedia. ...
5
votes
1answer
496 views

Manhattan Police

Introduction You are the police chief of the NYPD and you have been tasked to position police officers so that all of the streets are patrolled. Your squad is short-staffed, however, meaning that you ...
20
votes
9answers
2k views

The Saltine Challenge

Here is an ASCII saltine cracker: _________________ | . . . | | . . | | . . . | | . . | | . . . | |_________________| Here are two crackers ...
10
votes
2answers
320 views

Tension on a Graph, Part II: A Rubber Band

This is the second of two challenges about "pulling functions taut". Here is the slightly simpler Part I. Let's drive m nails into a board at positions (x1, y1) to (xm, ym). Tie a rubber band to the ...
21
votes
5answers
1k views

Is the brick structure stable?

Let's represent a standard masonry brick as [__] (and ignore the fact that the top is open). When these bricks are stacked every other layer is offset by half a brick, as is usual in brick ...
3
votes
5answers
389 views

Find X in a partially sorted Array

Your job is to find the location (read index) of a given element X in an array gone through the following transformation process: Take a fully sorted integer array of size N (N is known implicitly) ...
15
votes
0answers
405 views

Stitch a picture

I have a large collection of fine art. My toddler is learning to use scissors and glue; lately she has started playing with my art collection. Fortunately she is really quite good with the scissors ...