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

4
votes
5answers
126 views

Combinatorial products of unique primes

Statement of problem Given a set of unique, consecutive primes (not necessarily including 2), generate the products of all combinations of first powers of these primes — e.g., no repeats — and also ...
5
votes
6answers
264 views

Output all numbers below certain number containing certain digits

Output all numbers in certain range containing certain digits Task Take an input of digits through console, prompt, or a file (in the decimal number system). These digits should be separated by ...
5
votes
11answers
524 views

Increment every number in a string

Given a string containing decimal numbers: teststring134this 123test string54 100 increment every number in this string by one to give the new string teststring135this 124test string55 101. The ...
5
votes
0answers
88 views

Its time to do the Math

This is one of my favorite Math puzzles. Given a digit (say 3) and the number of times to use that digit (say 5), generate 10 expressions which result to 1, 2, 3, 4, 5, 6, 7, 8, 9 and 10 using just ...
4
votes
2answers
160 views

The color spelling game

In the color spelling game, you are shown a list of color names, but rather than reading the words that are written, you have to say the name of the color of the letters. The game is over as soon as ...
7
votes
4answers
577 views

Anagramming Code

Let's try this again. The object of this contest is to make two pieces of code that are anagrams of each other (the two must contain the same bytes in a different order), and they will do the ...
5
votes
3answers
173 views

Print all domino tilings of 4x6 rectangle

This is an extension of Fibonacci Domino Tiling. Your goal is to print all 281 ways to tile a 4x6 rectangle with 1x2 and 2x1 dominoes. Fewest bytes wins. Use the vertical bar | to indicate a space ...
7
votes
4answers
341 views

Moore Iteration

Info The numbers 1 to 9 each represent a cell in the Moore's Neighbourhood, with 5 being the central cell. So: 123 456 789 1={-1,-1} 2={-1, 0} 3={-1, 1} 4={ 0,-1} 5={ 0, 0} 6={ 0, 1} 7={ 1,-1} 8={ ...
2
votes
0answers
165 views

Generating a Student Timetable

Introduction You are the computer science teacher in a large high school and have been tasked to create a system to generate the student timetables. You must, given a JSON dictionary of student names ...
3
votes
5answers
240 views

Find all strings at distance k

The edit (or Levenshtein) distance between two strings is the minimal number of single character insertions, deletions and substitutions needed to transform one string into the other. The challenge ...
7
votes
1answer
99 views

Rosetta Stone Challenge: Run-Length Encoding v2.0

The goal of a Rosetta Stone Challenge is to write solutions in as many languages as possible. Show off your programming multilingualism! The Challenge We've done run-length encoding before but only ...
2
votes
2answers
311 views

Shortest parser for a left-recursive grammar

Write the shortest parser for the grammar: M -> M + n | n Output must be some representation of a structured value representing the concrete syntax tree produced by the input n+n+n. The code to ...
8
votes
1answer
228 views

Graph Google Search Results

When you search for something on Google, it conveniently gives a message near the top of the page saying something like About 53,000,000 results (0.22 seconds). (The numbers change depending on what ...
22
votes
9answers
1k views

Word Search Puzzle

Given a rectangular text as a word search puzzle and a search string, determine if the text contains the search string. The search string may appear: horizontally, vertically or diagonally forwards ...
1
vote
5answers
384 views

Find the next number in the pattern

Write a program, that takes 5 numbers as input and outputs the next number in the pattern. Heres a text file with 1835 test patterns, containing 6 numbers separated by commas each line. Using the ...
11
votes
8answers
726 views

Draw a range of mountain ranges

Inspired by Fibonacci domino tiling, this problem is about generating ASCII art representing another famous combinatorial sequence. A n-step mountain diagram is a drawing of a mountain range, using ...
4
votes
3answers
244 views

String Bit Manipulation- There and Back Again

Your job is to encrypt a string using a number key. Your program will receive 2 strings: one containing a sequence of characters to encrypt, and another one containing an even amount of digits (1-9, ...
7
votes
6answers
472 views

Mixed Base Conversion

Background Most people on here should be familiar with several base systems: decimal, binary, hexadecimal, octal. E.g. in the hexadecimal system, the number 1234516 would represent 1*16^4 + 2*16^3 + ...
-6
votes
0answers
71 views

Code that returns a set of decimal degrees gps coordinates [on hold]

I came across this riddle in a java programming forum, i figure that other languages can be more creative and ingenious. The code will not be used outside of self educational purposes. The resulting ...
13
votes
1answer
314 views

Minimal Boggle-like Arrangements

Consider how a word could be arranged on an arbitrarily large Boggle grid if the rule about not using the same letter cube more than once is ignored. Also assume that you have an unlimited number of ...
14
votes
7answers
1k views

Countdown and recycle

Countdown Your goal for this code-golf challenge is to count down and meanwhile recycle numbers. Let me explain. First your application reads a number, either as program argument or using stdin. ...
8
votes
9answers
998 views

Fibonacci domino tiling

There's classic combinatorial result that the number of ways to tile a 2*n strip by 1*2 dominoes is the nth Fibonacci number. You goal is to print all the tilings for a given n, drawn with dashes and ...
5
votes
3answers
587 views

Make a WaterOverflow

You and a friend are playing a game - who can overflow the most containers? There are n containers numbered 1 to n. Each container has a certain maximum capacity of water, in litres. You take turns ...
22
votes
1answer
433 views

Standardise a Phinary Number

Background Most people on here should be familiar with a few integer base systems: decimal, binary, hexadecimal, octal. E.g. in the hexadecimal system, a number abc.de16 would represent a*16^2 + ...
10
votes
1answer
473 views

Programmer's Garden

Programmer's Garden Being a professional software developer, you cannot risk exposing yourself to the harsh non-artificial light of the sun, but you also have a soft spot for flowers, and want to ...
29
votes
14answers
2k views

String.prototype.isRepeated

UPDATE : isaacg's Pyth submission is the winner! Many of you must have heard that there is a cooler version of JavaScript in town (read ES6) which has a method String.prototype.repeat so that you ...
5
votes
0answers
167 views

Which positive integer is equal to it's own Scrabble score when spelt out in full? [closed]

The Challenge: Make the shortest program to confirm that 12 is the answer. (The puzzle is from Ian Stewart's "Cabinet of Mathematical Curiosities". This is my first code golf question. I hope this ...
9
votes
4answers
389 views

How NOT to reduce fractions

Reducing fractions the wrong way In this code-golf challenge you have to find fractions that can be reduced the wrong way but still end up in the same number. Note: reducing fractions the worng way ...
22
votes
20answers
5k views

Crack the code to the combination lock

Given a standard combination lock like the one in the picture. The way to unlock it is to align the 4 numbers in the code on the combination line. After years of loyal service you have been fired from ...
4
votes
1answer
254 views

Unnecessary Text Abbreviations

Introduction I can't stand text abbreviations, mainly because for the most part I have no idea what most of them mean. Of course, cut backs need to be made, so if they are necessary to fit the text ...
10
votes
1answer
367 views

Reorganize By Arrows

Lets say I was writing something, and I accidentally wrote it in the wrong box: +-------+--------+ | Verbs | Nouns | +-------+--------+ | Truck | | | eat | Banana | | | Car | ...
7
votes
6answers
668 views

Curve Stitching

Curve stitching is the process of "stitching" together multiple straight lines in order to create a curve, like so: For an explanation of curve stitching, visit this website. We will be drawing ...
11
votes
4answers
477 views

Find the Chromatic Number

Surprisingly, we haven't had any challenges on graph colouring yet! Given an undirected graph, we can give each vertex a colour such that no two adjacent vertices share the same colour. The smallest ...
7
votes
4answers
334 views

Generate Eban Numbers

(Continuing on the number sequences code-golf, here is an interesting sequence) Eban Numbers (A006933) are the sequence of numbers whose names (in English) do not contain the letter "e" (i.e., "e" is ...
5
votes
12answers
470 views

Check the jumbled words [duplicate]

This is an easy one. Anagrams are words which have the same characters but in different order. All you have to do is to figure out if two strings are anagram or not. Rules: Take two strings as a ...
10
votes
2answers
346 views

Write a Clem interpreter

Clem is a minimal stack-based programming language featuring first-class functions. Your objective is to write an interpreter for the Clem language. It should properly execute all examples included in ...
8
votes
3answers
354 views

Pigpen Cipher Encryption

Pigpen Cipher Encryption Your mission is simple: to write a program which receives text as input and outputs an ASCII representation of it in the Pigpen Cipher. Input ASCII-only (no Unicode) ...
12
votes
6answers
633 views

Electron Configurations

Electron Configurations Your mission is to accept an element's atomic number as input, and output its electron configuration (e.g. 2,8,8,2 for calcium). Input An atomic number from 1 to 118. You ...
18
votes
30answers
3k views

Generating a single string with an Oxford comma from a list

What are some clever (brief and idiomatic) approaches to taking a list of strings and returning a single properly punctuated string built from the list, with each element quoted. This came up for me ...
6
votes
5answers
413 views

Tips for golfing in Applescript

What tips do you have for golfing in Applescript? I'm looking for ideas that can be applied to code golf problems in general that are at least somewhat specific to Applescript (e.g. "remove comments" ...
7
votes
15answers
840 views

Generate Recamán's sequence

Recamán's sequence (A005132) is a mathematical sequence, defined as such: A(0) = 0 A(n) = A(n-1) - n if A(n-1) - n > 0 and is new, else A(n) = A(n-1) + n A pretty LaTex version of the above ...
4
votes
1answer
150 views

Arranging Fenceposts

If you want to build a fence and have different length boards available, there are many different ways to set up your posts. So, given a minimum and maximum board length, a number of boards, and the ...
6
votes
3answers
290 views

Catenary Between Two Points (Hanging Chain)

This is one of several challenges left for the community by Calvin's Hobbies. The curve that an idealised hanging rope or chain makes is a catenary. Image by Bin im Garten, via Wikimedia Commons. ...
-6
votes
2answers
185 views

Challenge: Crack the code [on hold]

I have created a simple encryption algorithm. Your challenge, if you choose to accept it, is to re-produce the algorithm that encodes one string into it's encoded counterpart and then back again by ...
2
votes
0answers
85 views

Tips for golfing in OCaml

Inspired from the assortment of other 'Tips for golfing in language xyz'. As usual, please only suggest tips that are specific to OCaml and not programming in general. One tip per answer please.
28
votes
19answers
4k views

Easily Typeable Words

This competition is over. The winner is CJam with 22 characters, beating TwiNight's answer by one character. Congratulations Dennis! An honorable mention goes to Falko, who went totally crazy with ...
12
votes
6answers
926 views

Integer Emotions

Write a program or function that "reacts" to a given integer n (input via function parameter/args/stdin) The program doesn't care about negative numbers, likes even, dislikes odd numbers and ...
10
votes
13answers
2k views

Pick the longest stick

You are a young programming geek living with your 2 other best friends. Every week, one of you has to do all the chores of the house and you decide whose turn it is by picking a stick. The one who ...
20
votes
4answers
1k views

Laser Mirror Portal Party

A 2D board will contain the following objects: ^,>,v, or <: A laser emitter facing up, right, down, or left respectively. There may be more than one. Lasers will travel in a straight line in ...
10
votes
1answer
205 views

Code-Golf Ascii Art Mini-Golf

Intro Let's play some mini-golf! The golf ball is represented by a . and the hole by a O. You want to get a hole in one on every hole, but you are not good at putting. In fact, you refuse to attempt ...