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

2
votes
0answers
37 views

Maximum Circle Radius

You have a rectangle, 300 pixels wide by 300 pixels tall. You also have 5 circles. Your task is to write a program that will find the largest possible radius and optimal position of these circles so ...
0
votes
0answers
169 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 ...
10
votes
17answers
2k 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
7answers
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
135 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: ...
11
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
74 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 ...
38
votes
7answers
6k 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 ...
11
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
99 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
411 views

Give me a haircut!

This is my head: \ /-- -| / -\ | | | \ \ \ \ | --\ | \ | | / |--| / / | /|- //--| / | | | || //\ | | \ /| // \ | It consists of exactly eight hairs. My hair ...
6
votes
1answer
354 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, ...
12
votes
5answers
902 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
112 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
488 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
464 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
307 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
229 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
408 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
733 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
1k 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
522 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
288 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 ...
10
votes
2answers
679 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
568 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
443 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
153 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
500 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
228 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
617 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
682 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
493 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
319 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
387 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
402 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 ...
8
votes
6answers
296 views

Sort by custom alphabet

The challenge is to make a program that sorts a list of words, only that the words need to be in the order of a random alphabet. Your program will accept a string of comma-seperated words and a new ...
14
votes
10answers
910 views

Sierpinski Layers

Starting with /\ you can create a Sierpinski triangle like pattern by adding a line beneath such that... Any loose branch / or \ splits again into two branches: /\. Any collision of branches \/ dies ...
7
votes
0answers
108 views

Factor a polynomial over a finite field or the integers

Without using any built-in factoring/polynomial functions, factor a polynomial completely into irreducibles over the integers or a finite field. Input Your program/function will receive some prime ...
3
votes
1answer
187 views

GPS: Golfed Positioning System

Your mission, should you choose to accept it, is to write code for a GPS receiver. Input The current time, as nanoseconds from the Unix epoch. [EDIT: This is optional, please state whether you ...