Code-golf is a competition to solve a particular problem in the fewest characters or bytes of source code. If source code length is not the primary scoring criterion, consider using another tag instead.

learn more… | top users | synonyms

5
votes
5answers
296 views

Output nth term in Catalan type sequence

Given a number, starting with 1, create new numbers (children) by taking the last digit, n, and concatenating 1 through n+1. This seems to be a much better explanation of the sequence A071159. ...
5
votes
1answer
264 views

Crosswalk Efficiency

A standard road intersection contains 4 sidewalk corners and four crosswalks connecting them. It could also have 2 diagonal walks. sRRRRs iOOOOi dAAAAd eDDDDe side0----1walk ROAD|\ ...
8
votes
2answers
708 views

Compact coding of integer into bitstring

I want to compactly code positive integers x into bits, in a manner allowing decoding back into the original integers for a stateless decoder knowing the maximum value m of each x; it shall be ...
10
votes
2answers
438 views

Introspective Programming: Code that analyzes its source and its output

Write a program that outputs the total number of characters and the frequency of each character in its source and its output. You must follow the format illustrated in the example. Example If your ...
3
votes
4answers
224 views

Difference of expressions when evaluated in different orders

We all know the standard order of operations for math functions (PEMDAS), but what if we instead evaluated expressions left-to-right? The Challenge Given a string through standard input or through ...
6
votes
5answers
382 views

Spiral in the grid

Write a program which enumerates points on a regular grid in the form of a spiral. The output should be the indices of the points (row-major) and the spiral should start at 0 and proceed ...
7
votes
0answers
63 views

Checking periodic table words [duplicate]

Given a sequence of letters, write a program to construct it using symbols on the periodic table. For example, given the input bacon, the program should output: BaCoN BAcON BaCON Note that ...
36
votes
73answers
5k 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 ...
5
votes
2answers
362 views

Basic Algebraic Expansion

Problem I've got a GREAT new program that will change the way we think about math in computing, taking in strings of algebraic functions and doing AMAZING things with them! The only problem, is that ...
72
votes
14answers
8k views

Has my milk expired?

Aww, man, this expiry date doesn't write the months with letters! I can't tell if it's expiring on March 10th or October 3rd... Wait, no, never mind, the year says 2012. (alley-oops half-used brick of ...
11
votes
2answers
519 views

Three-letter cube sculptures (episode 1)

This question is inspired by the cover of the book "Godel, Escher, Bach": The challenge here is to write a function that tells if three given letters can produce a 3D sculpture that can be read ...
11
votes
8answers
1k views

Write a brainfuck translator

In any programming or scripting language x, write a program that takes a valid brainfuck sourcecode from stdin and output, to stdout, the sourcecode of a program, written in language x, that would ...
1
vote
1answer
856 views

A Most Excellent Code Golf Adventure

You dudes, the Most Excellent Adventure is a home brew roleplaying game system based on the Bill & Ted Films, plays gnarly air guitar riff. In this game system, when you draw from your dice pool ...
15
votes
12answers
3k views

Simulate Rule 110

Rule 110 is a cellular automaton with some interesting properties. Your goal is to simulate a rule 110 in as few characters as possible. For those who don't know, rule 110 is simulated line by line. ...
17
votes
0answers
501 views

Print the lyrics to “Twinkle Twinkle Little Star”

Your goal is to print the lyrics to the song "Twinkle Twinke Little Star" as each note is played. The computer's microphone will hear notes. If the pitch (but not necessarily the length) of the note ...
7
votes
0answers
234 views

ASCII Waterworks

Intro Consider a grid of the characters f A\/ such as f f f A A / \ \ / A A \/ / \/ where: f represents a faucet that pours a stream of water downward ...
1
vote
0answers
84 views

Recover a bzip2 file

The popular .bz2 compression format is used to store all sorts of things. One of the more interesting features is that it consists of several independently decompressible blocks, allowing recovery of ...
12
votes
11answers
2k views

Implement a Brute Force Sudoku Solver

Implement the shortest Sudoku solver using guessing. Since I have received a few request I have added this as an alternative question for those wishing to implement a brute force sudoku solver. ...
24
votes
20answers
3k views

Golfing ASCII-art

Let's try to golf this piece of ascii-art representing a golfing man: '\ . . |>18>> \ . ' . | ...
37
votes
91answers
7k views

Shortest code to produce infinite output

Write the shortest code you can that produces an infinite output. That's all. You code will only be disqualified if it stops producing output at some point. As always in code golf, the shortest code ...
18
votes
7answers
1k views

Pokeball Simulator

In the Pokemon video games, the player is sent out into the world to force wild animals into tiny balls and train them to fight. Of course, everyone knows that no one plays Pokemon for the battling. ...
0
votes
2answers
224 views

Shortest conditional to run a specific statement: C code golf

Currently I have the code (expanded for your benefit): <number> != <number> ? printf("|\\"); : <number>; The idea here, is to do this condition in the least number of characters. ...
28
votes
17answers
3k views

Check if point lies inside triangle

Your goal is to determine whether a given 2D point X lies within the area of the triangle with given vertices A,B,C. Write a function that takes in the coordinates of the test point X and the three ...
13
votes
6answers
743 views

PI window encryption

This is a simple encryption method that uses PI digits to encode a message, the method is simple: The key is just a positive integer that indicates where the window starts then: Given a string to ...
7
votes
9answers
952 views

Make a finky syntax checker

You are to make a program that can check the syntax of programs of its same language. For example, if you do it in python, it checks python syntax. Your program will receive a program on standard ...
4
votes
3answers
715 views

Brainfuck Sorting

Write a program in brainfuck that accepts input of 4 ASCII characters as numbers (from 32 to 126) and outputs the numbers or ASCII equivalent sorted in ascending order. Requirements: Your program ...
-2
votes
0answers
105 views

Implement the Sieve of Eratosthenes [duplicate]

The task is simple. Create a program or function that will generate, and print, primes using the Sieve of Eratosthenes. The Sieve of Eratosthenes is known to be the most efficient way to find ...
7
votes
7answers
329 views

List the combinations of elements in a set [duplicate]

Given a set of n elements, the challenge is to write a function who lists all the combinations of k elements of in this set. Example Set: [1, 7, 4] Input: 2 Output: [1,7], [1,4], [7,4] Example ...
17
votes
15answers
2k views

My Word can beat up your Word

PROBLEM Given two words, find the winner in a digital root battle. Define the digital root of a word this way: Each letter of the alphabet is assigned a number: A = 1, B = 2, C = 3, ..., Z = 26 ...
5
votes
5answers
411 views

Operations on Sets

Write a program that computes operations on sets. You may take input either from standard input or from command line arguments. Your program must be able to compute unions, intersections, relative ...
10
votes
12answers
1k views

Langton's ant ASCII art.

Draw the path of Langton's ant. Description Squares on a plane are colored variously either black or white. We arbitrarily identify one square as the "ant". The ant can travel in any of the four ...
180
votes
7answers
15k views

Draw with your CPU

I have come across an article where students used network traffic to draw their university on the country's IPv6 graph. [image] Your goal is simple to tell, but hard to implement. Draw the text MAIL ...
0
votes
2answers
239 views

Solve this math problem in smallest amount of code [on hold]

Here I found a cool math problem. I thought you could write some golfed code to compute all answers between x and x.(there is an infinite amount). Problem: Once upon a time, and old lady went to sell ...
7
votes
0answers
334 views

Build a MU puzzle solver

The MU puzzle is a puzzle in which you find out whether you can turn MI into MU given the following operations: If your string ends in I, you may add a U to the end. (e.g. MI -> MIU) If your ...
15
votes
34answers
2k views

Domino function

Using as few amount of Unicode characters as possible, create a function that receives three integers: Total amount of dominos nth affected domino Knock over direction (0=left, 1=right, or use ...
35
votes
13answers
4k views

Write a Rectangular Program that Outputs the Number of Times it was Rotated

The title says it all. Your goal is to write a program that forms a w×h rectangle of characters that can be rotated and re-run to output the number of 90° Counter-Clockwise (CCW) rotations that have ...
18
votes
3answers
2k views

Implement a Non-Guessing Sudoku Solver

Implement the shortest Sudoku solver. Sudoku Puzzle: | 1 2 3 | 4 5 6 | 7 8 9 -+----------------------- A| 3 | 1 | B| 6 | | 5 C| 5 | | 9 8 3 -+----------------------- ...
364
votes
134answers
141k views

Produce the number 2014 without any numbers in your source code

So, now that it's 2014, it's time for a code question involving the number 2014. Your task is to make a program that prints the number 2014, without using any of the characters 0123456789 in your ...
22
votes
28answers
3k views

Print the alphabet four times

The program must print the alphabet four times: first in the normal alphabetical order, second in the order of a qwerty keyboard, third in the order of a dvorak keyboard, and lastly in reverse ...
9
votes
5answers
475 views

Reduce html to n characters while keeping the formatting

Almost every language has a built-in function that can split a string at a given position. However, as soon as you have html tags in the string, the built-in function will not work properly. Your ...
36
votes
35answers
5k views

ETAOIN SHRDLU golf

Short and sweet description of the challenge: Based off ETAOIN SHRDLU, your challenge is to write the shortest program or function in any language that outputs the 26 letters of the English alphabet ...
-3
votes
2answers
166 views

Find the unique number [closed]

I have read a question similar to this. I found it interesting, And difficlut so I rephrased the question as a code golf. (that question is closed ) In 1 million and 1 numbers, all the numbers having ...
1
vote
9answers
1k views

Show the input RGB color

Write a program that takes R, G, and B values as command arguments and then displays that color some way. It doesn't matter how, as long as at least 100 pixels have the color. Shortest code wins.
4
votes
4answers
336 views

Determine number of unconnected components

You are given a graph represented through an adjacency list. For example, the input 1-2 2-3 3-4 4-1 would correspond to the graph with nodes 1, 2, 3 and 4, where 1 is connected to 2, 2 is connected ...
17
votes
13answers
3k views

One Bad Ternary Operator Deserves Another

Today's Daily WTF quotes the following line of code... FailSafe==0?'No technical ...
12
votes
30answers
1k views

Randomly pick one number that is different than two other random numbers

Two random numbers A and B have been generated to be either 1, 2, or 3 your job is to randomly pick a third number C that can also be 1,2 or 3. But, C cannot equal A or B. And Yes, A can equal B. ...
7
votes
3answers
1k views

Solve the 14-Pegs puzzle

Introduction A common puzzle involves a triangular board with 15 holes for tees/pegs as shown in the image below: Starting with all the pegs in the board except for a hole at the top, the point of ...
4
votes
12answers
520 views

Another amicable number problem

Two numbers are said to be 'amicable' or 'friends' if the sum of the proper divisors of the first is equal to the second, and viceversa. For example, the proper divisors of 220 are: 1, 2, 4, 5, 10, ...
6
votes
6answers
457 views

Find a binary tree's deepest node

Write a program that takes a binary tree as input, and outputs the deepest node and its depth. If there is a tie, print all involved nodes as well as their depths. Each node is represented as: T(x,x) ...
4
votes
0answers
177 views

Probability to win a hand of poker (Texas hold 'em)

Challenge: In the last stage of a two players Texas hold 'em, given a two-card hand and five cards on table, determine your probability to win versus an opponent by the standard ranking of poker ...