People who code: we want your input. Take the Survey

Questions tagged [code-golf]

Code-golf is a competition to solve a particular problem in the fewest bytes of source code.

Filter by
Sorted by
Tagged with
5
votes
16answers
2k views

Hexadecimal To Decimal [closed]

Read input of up to 8 characters presented as hexadecimal number and print this number as decimal number. In case that input can not be presented as hexadecimal input it has to print 0 Rules: It is ...
3
votes
5answers
2k views

Solve the knapsack problem

Knapsack Problem (Actually, this is a subset of real knapsack problem.... - there's nothing to optimize!) The knapsack problem is: Given positive integers , and an integer S, find non-negative ...
5
votes
2answers
1k views

Determining the winner of a Chess game

Challenge Being someone who plays far too much chess in his spare time, I thought I'd set a code golf challenge inspired by the game of chess (with a software flavour), for those interested. The ...
11
votes
2answers
987 views

Blockbox that Hex?

Write a program or a function in any programming language that takes a 6 digit hexadecimal input/argument. The input/argument can be 6 values or a 6 character string. Your program should output an ...
26
votes
31answers
4k views

There Was an Old Lady

Your goal is to write a program that prints the following poem exactly as it appears here: ...
6
votes
3answers
354 views

Shana tova umetuka! (Happy Jewish New Year!)

Write the shortest program, in the language of your choice, that takes as input a year on the Hebrew calendar, and outputs the corresponding Gregorian date for Rosh Hashana, in YYYY-MM-DD format. <...
9
votes
1answer
939 views

Optimize matrix chain multiplication

This challenge is to compute the most efficient multiplication order for a product of several matrices. The size of the matrices is specified on a single line of standard input. You should print to ...
11
votes
8answers
1k views

codegolf.com: Saving Time

From codegolf.com (not loading as of Sept 15, 2011) was one that was driving me crazy. Print to STDOUT a clock of an exacting form, reading time from STDIN and marking an ...
5
votes
3answers
413 views

Organize a tournament

Here is a real question somebody asked me. Suppose you have n teams, one terrain. Each team must play each other team exactly once. The number of times a team ...
6
votes
1answer
548 views

Set the chessboard

Objective Given an arbitrary chessboard as standard input (in which each piece is on a square), produce as standard output a list of moves needed to regularize, or set up, the chessboard. The moves ...
12
votes
9answers
2k views

Flag Semaphore Encoder

Your goal is to write a flag semaphore encoder, which will convert a given sentence into the corresponding flag semaphore characters, according to the semaphore system described on Wikipedia. Assume ...
20
votes
10answers
2k views

Exploit “free whitespace”

Suppose a codegolf challenge doesn't count whitespace in the length of your program. Cheat this system by encoding your script into whitespace, and golf a script which decodes and executes embedded ...
15
votes
30answers
7k views

Jolly Jumper Sequence

A sequence of n > 0 integers is called a jolly jumper if the absolute values of the difference between successive elements take on all the values 1 through n-1. So the sequence [4,1,2,4] has absolute ...
6
votes
1answer
603 views

Optimal Othello/Reversi Move

This is a code-golf challenge: Given a specific board in the game of Othello (Reversi), find a move for Black that will capture the maximum number of White pieces. (Obviously, this may not be the ...
13
votes
4answers
683 views

A Mere Bagatelle

The challenge Given a bagatelle board like the one below: ...
19
votes
1answer
1k 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 ...
13
votes
47answers
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 ...
11
votes
4answers
1k 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 . ...
77
votes
6answers
36k 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 (...
15
votes
7answers
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(...
18
votes
9answers
2k views

Choose Your Own Adventure

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 ...
9
votes
7answers
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 ...
70
votes
38answers
19k 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 ...
7
votes
3answers
3k 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 ...
10
votes
6answers
2k 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-...
9
votes
7answers
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",...
4
votes
5answers
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 ...
17
votes
4answers
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. ...
-4
votes
11answers
453 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 ...
12
votes
3answers
420 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 ...
55
votes
71answers
7k 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 ...
4
votes
12answers
852 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 ...
5
votes
4answers
309 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 ...
11
votes
5answers
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 ...
19
votes
1answer
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 ...
12
votes
3answers
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 ...
8
votes
25answers
2k 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 ...
23
votes
10answers
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 ...
32
votes
7answers
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 ...
5
votes
2answers
2k 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 ...
7
votes
4answers
879 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, ...
8
votes
3answers
4k 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 ...
16
votes
40answers
2k views

Undulant numbers [duplicate]

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 ...
5
votes
3answers
380 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 ...
13
votes
9answers
816 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 ...
43
votes
2answers
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 ...
7
votes
1answer
503 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 (...
52
votes
31answers
10k 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 ...
7
votes
14answers
767 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, ...
9
votes
5answers
1k views

Paint that fence

You are Tom Sawyer and you have to paint a fence of 102400 m long. Luckily, your friends decided to help you in exchange of various things. Each friend will paint L meters, starting from S with ...

1
201 202
203
204 205
209