# All Questions

10,644 questions
977 views

### Unique Sudoku Finder

Challenge: Given a Sudoku board on standard input, find the minimum number of numbers added to make the board unique. Specifics/Rules: The input is formatted as follows (all whitespace is ...
602 views

### Arithmetic Golf: Reach 2011

This is an ai-player challenge. Your goal is to reach the number 2011 as quickly as possible, or to get as close to it as you can. Rules: A "hole" consists of a rectangular grid of digits (0-9). ...
5k views

### Descending Sort using Standard Ascending Sort Function [closed]

Taking an array of records. For example ...
1k views

### Maximize order of operations

Here's a problem to which I don't know the answer. Suppose you have an ordered list of integers with an operator in between each consecutive pair. Let's restrict ourselves to three operations that are ...
2k views

### Detect loops in a linked list [closed]

This comes from one of my favorite interview questions, though apparently it is now a fairly well-known puzzle. I have no way of knowing, but if you have already heard the answer it would be polite to ...
7k views

### Count the number of times a function runs [closed]

This is a teaser a friend of mine sent. It seems straightforward, but I can't seem to get my head around it, probably due to my lack of sleep. You have 16 bits available. Compose a function, and ...
3k views

### Enumerate all palindromic numbers (in decimal) between 0 and n

Given a non-negative integer n, enumerate all palindromic numbers (in decimal) between 0 and n (inclusive range). A palindromic number remains the same when its digits are reversed. The first ...
992 views

### Knock down walls in a maze

Rules: In this game you start at the top of a rectangular grid of size N x M made up of walls and open spaces. The input is N lines of M characters, where a . ...
31k views

### Hard code golf: Regex for divisibility by 7

Matthias Goergens has a 25,604-character (down from the original 63,993-character) regex to match numbers divisible by 7, but that includes a lot of fluff: redundant parentheses, distribution (...
1k views

### What comes next?

Given a space-separated list of integers, your task is to find the next integer in the sequence. Each integer in the sequence is the result of applying a single mathematical operation(...
2k views

Choose Your Own Adventure books are a form of interactive literature where the reader must make decisions that affect the outcome of the story. At certain points in the story, the reader has multiple ...
1k views

### Program to Spoonerise words [duplicate]

A spoonerisation is swapping the first letter/pronounceable syllable of two or more words. Example: A lack of pies = A pack of lies. Bad salad = Sad ballad (ish) :) Challenge: Write a program to ...
1k views

### How to encode shortest brainf_ck strings

This is an interesting one. I have written a short program in objective-c to encode a string into a brainf_ck string, this is what it looks like: ...
705 views

### Tricky Median Question

Given n points, choose a point in the given list such that the sum of distances to this point is minimum ,compared to all others. Distance is measured in the following manner. For a point (x,y) all ...
14k views

### Shortest Game of Life

Conway's Game of Life is the classic example of cellular automation. The cells form a square grid and each has two states: alive or dead. On each turn, each cell simultaneously updates according to ...
2k views

### Lights Out - Find the solution

(This code golf task is related to Code-Golf: Lights Off!. The same puzzle is used, but the task is different.) Introduction "Lights Out" is a puzzle in which you should switch off all lights in a ...
1k views

### Enumerate all binary trees with n nodes

Given an integer n, enumerate all possible full binary trees with n internal nodes. (Full binary trees have exactly 2 children on every internal node). The tree structure should be output as a pre-...
927 views

### 400th Question Celebration/Challenge [closed]

I just looked and saw that there are 399 questions on this wondrous "Programming Puzzles & Code Golf" site!!! That means that...THIS IS THE 400th question!!! To celebrate this momentous occasion,...
17k views

### Program that determines whether an int is greater or lesser [closed]

Write a program which prompts a user to input two integers A and B, the program should determine whether A is greater than or lesser than B without the use of greater than [>] or less than [<] ...
2k views

### Generating BF-code with single purpose

I'd like to see you create code (in any programming language) that output working BF (Brain***k) code. Your program have a single character input on stdin. The input should be one digit ("0", "1", "2",...
3k views

### C: Output “tomorrow's date”

I'm a code golf novice, but I'm eager to give it a go. My challenge is: Write the shortest program in C which takes in a date D as input and outputs the date ...
2k views

### Wordsearch Solver

Given a list of words and a grid of letters, find all the words in the grid and remove any letters which are not part of any of the words. The words could be forwards, backwards, up, down or diagonal. ...
446 views

### Text Statistics: Return a list/array of the number of occurrences of each character used in a text file, including spaces, tabs, and new lines [closed]

Generic Lorem Ipsum: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris felis dolor, bibendum at tincidunt vel, imperdiet eget libero. Cras vel felis purus. Phasellus a vestibulum ...
376 views

### Session-Saving Quine

Inspired by this question. Create a program that prompts the user to store some data, and when the program is quitting, spit out the program itself, except the session data changed. The user then ...
6k 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 ...
9k views

### Compute the CRC32 table at compile-time [closed]

The reference implementation of CRC32 computes a lookup table at runtime: ...
843 views

### Multiples of 67 in a constructed array of arrays?

A triangle-shaped table is constructed such the first row is "1, 3, 5, 7, ..., 99" Each subsequent row has the following properties: One less element than the row above Each element is the sum of ...
1k views

### Creative Programming [closed]

Make a story out of your programming. Example in JavaScript: ...
306 views

### Generate a JavaDoc comment [closed]

I'm too lazy to write a JavaDoc comment myself, there's a lot of typing and it is mostly boilerplate. Write a program to generate a JavaDoc comment with \$ as a ...
1k views

### Musical Score Interpreter

Given an ascii musical score, you must be able to output the note and its corresponding length. The score will contain between 5 and 15 notes inclusive, and is transcribed on a stave. A stave is ...
2k views

### Chess endgame: White to Mate In One

Given an 8x8 grid of letters representing the current state of a game of chess, your program's task is to find a next move for white that results in checkmate (the answer will always be mate in one ...
2k views

### Solving triangles with trigonometry

Time to dig up your old trigonometry notes from high school! The challenge is to solve the unknown sides and angles of different triangles. And as is customary in code golf, the smallest working code ...
1k views

### Machine Epsilon

Machine epsilon is an important floating point number to know when doing numerical calculations. One way to understand it is when this relation ...
2k 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 length ...
4k views

### Write the fastest Fibonacci

This is yet another challenge about the Fibonacci numbers. The goal is to compute the 20'000'000th Fibonacii number as fast as possible. The decimal output is about 4 MiB large; it starts with: ...
6k views

### Solve the eight queens problem at compile-time [closed]

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 ...
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 ...
1k views

### Knuth's Power Tree

In The Art of Computer Programming, Knuth describes an algorithm to compute short addition chains. The algorithm works by computing a tree known as the Power Tree. The tree is rooted at 1, and each ...
207 views

### Proving the shortest quine in a particular language [duplicate]

Possible Duplicate: Golf you a quine for great good! People have proposed short quines in various languages. Puzzle: Find the shortest non-trivial quine in a language of your choice, and prove ...
840 views

### Unicode character classification [closed]

Real-world programs often use libraries like ICU to support Unicode. The puzzle is to create the smallest possible function that can determine whether a given Unicode character is lowercase, ...
3k views

### Magic square generator

Create the shortest function to print a magic square of given size. A magic square is a NxN matrix of distinct numbers and the sum of each row, column and diagonal is equal to a constant. A magic ...
2k views

### Undulant numbers

An undulant number is a number where its digits alternate between up and down like the following number: 461902 or 708143, or even 1010101, but not 123, because 2 < 3. Write a program or function ...
348 views

### Negative Regexp [closed]

Write the shortest function that takes one string, and returns a regular expression that matches anything EXCEPT the input string, in parenthesis. Escape necessary characters like Perl ...
769 views

### Soundex function

Write the shortest function to generate the American Soundex code for a surname only containing the uppercase letters A-Z. Your function must produce output consistent with all the linked page's ...
2k 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 ...
488 views

### using a Markov Chain, because this question itself as input text for example

Create a Markov Chain generator, which generates (and outputs) an Order 4 text chain. It must be able to support all plain text formatting used on this question, so be sure to check for punctuation (...
8k views

### Generate a mandelbrot fractal [closed]

Your task is to draw the mandelbrot set in ascii. It should look something like The complex number c lies in the mandelbrot set, when the sequence ...
715 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, ...