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

6
votes
0answers
62 views

Draw a Random Walk with Slashes

Write a program or function that takes in a positive integer N (via stdin/command line/function arg) and prints or returns a string representation of a two dimensional random walk that is N steps ...
1
vote
0answers
59 views

DoIt Java Style

Given string X, convert it to Java Style string, as defined below: Strings may only contain numbers and letters(signs are not allowed) Strings must not start with numbers Strings must start with ...
15
votes
3answers
602 views

Infinite Labyrinths

Background You are the apprentice of a powerful wizard, and your master is currently developing a spell for creating an inter-dimensional labyrinth to trap his enemies in. He wants you to program his ...
8
votes
3answers
279 views

Calculate a check digit using the Damm algorithm

There are popular check digit algorithms such as Luhn and then there are good ones, for example the Damm algorithm. The only possible reason behind the popularity of algorithms such as Luhn is that ...
7
votes
0answers
128 views

Shortest Substring Index

I'm a lazy but efficient person, as many of you probably are as well. So, whenever I'm doing something I want to do it with minimal effort. Which is why I'm asking you to solve this problem for me. ...
15
votes
1answer
188 views

Remove an unobstructed rectangle

This image was made by overlaying 7 differently colored rectangles on top of each other: The black and maroon rectangles are unobstructed, that is, no other rectangles are above them. Write a ...
6
votes
1answer
284 views

Reverse every word in a line in vim

Your task is to build a vim script or provide a sequence of keystrokes that will operate on a single line of text with up to 140 printable ASCII characters (anywhere in a file, with the cursor ...
12
votes
1answer
313 views

How do I get more Klotski in my life?

I really love sliding tile puzzles, but recently, I haven't had time for them. Hence, I need a program to give me my fix of sliding-tile puzzles, specifically Klotski puzzles. Your input will be in ...
4
votes
7answers
424 views

N-gram histogram

Given a text and a number N, output, in a human readable format, the set of the character N-grams with their respective percentages. The smallprint The text can be read from a file, stdin, passed ...
17
votes
15answers
4k views

Shortest Sorted Hello World

Write a program that takes no input and prints Hello, World! to stdout or your language's closest alternative. The catch is that each line in your program must only contain printable ASCII characters ...
10
votes
2answers
185 views

Computing truncated digits sums of powers of pi

Given a positive integer n output the sum of the first n decimal digits of the fractional part of πn. Example input and outputs: 1 → 1 2 → 14 3 → ...
-1
votes
0answers
62 views

Self compressing code [duplicate]

Create a program in any language, that could be used for loss-less compression (see below) of a source code in that language. By loss-less compression I mean any transformation of a source code, that ...
6
votes
2answers
335 views
+150

IPV4 subnet list cleaner (in CIDR notation)

We have a lot of IPV4 address, to group into subnets, so we need a tool for doing this: Our list is very ugly, not ordered and sometime in subnet notation, sometime in simple address. Sample: ...
10
votes
9answers
871 views

Generate The SUDSI Sequence

The SUDSI sequence (sum, difference, swap, increment) is a curious integer sequence that appears to exhibit rather chaotic behavior. It can be generated as follows: Let S be an infinite list of the ...
5
votes
11answers
530 views

Decode a Rövarspråket string

This question is the inverse of this one by James Williams. Rövarspråket Rövarspråket is a word game played by Swedish children, from the books about Kalle Blomkvist by Astrid Lindgren. The basic ...
10
votes
6answers
333 views

Implement a Variable Length Hash

My friend and I have this game that we play with words. It is a fun pastime and it involves "canceling out" letters in a word until there is nothing left. I am really tired of him being so much faster ...
12
votes
20answers
2k views

Convert a string to its Rövarspråket equivalent

Rövarspråket Rövarspråket is a word game played by Swedish children, from the books about Kalle Blomkvist by Astrid Lindgren. The basic rules are as follows (from Wikipedia): Every consonant ...
0
votes
0answers
62 views

Random arithmetic quiz [duplicate]

Given a and b as two random numbers from 0 to 10 and op as a random symbol of arithmetic operations, you should display 10 questions in the format: a op b = to the user, after each question if the ...
23
votes
21answers
3k views

Very Simple Triangles

Write a program or function that takes in a positive integer (via stdin, command line, or function arg) and prints or returns a string of that many of these small triangles tiled together, alternating ...
26
votes
6answers
651 views

ASCII topology pt 1: Can I count on you?

I have a serious problem. I have some text files where I keep my very important numbers -- all of the important ones! And twos, and threes.. These numbers were so important that I couldn't entrust ...
5
votes
0answers
191 views

Implement multiplication by a constant with addition and bit shifts

While looking at the ARM instruction set, you notice that the ADD instruction has the so-called "Flexible second operand", which can be abused for quick multiplication. For example, the following ...
-4
votes
0answers
104 views

Create a Blue Screen (aka BSOD) [closed]

Create a minimum program (size counted in chars) that causes a BSOD. This should not damage anything. No linking to exe's such as this. I chose characters as the measure because I am sure it is ...
-4
votes
5answers
115 views

Generate a random floating point number between 2 limits [closed]

This challenge is to generate a random floating-point number between 2 limits. You may use any language so long as it can be called from the command line, and runs on linux. It must also be able to ...
17
votes
6answers
2k views

Chinese Remainder Theorem

The Chinese Remainder Theorem tells us that we can always find a number that produces any required remainders under different prime moduli. Your goal is to write code to output such a number in ...
7
votes
1answer
322 views

Decrypting a block of AES

Today your goal is to decrypt a secret message using AES. Given a ciphertext and key you will decrypt and print the message. Your program may be in any language. It will be run with input on ...
21
votes
3answers
826 views

How do I craft that?

There are 21 items in Minecraft that you can craft using only wood and items crafted from wood: axe boat bowl button chest crafting table door fence gate hoe ladder pickaxe ...
14
votes
0answers
184 views

Prime polynomials

Given a polynomial, determine whether it's prime. A polynomial is ax^n + bx^(n-1) + ... + dx^3 + ex^2 + fx + g, where each term is a constant number (the coefficient) multiplied by a nonnegative ...
0
votes
0answers
32 views

Floating Point Numbers as Minimal Ratio [duplicate]

Input a floating point number a. Calculate two integers b and c, so that b/c=a is correct to as many decimal places as given by a. b needs to be minimal (so there exists no smaller possible b) ...
14
votes
8answers
1k views

Discrete Baker's Map

Introduction The Baker's map is an important dynamical system that exhibits chaotic behavior. It is a function from the unit square to itself defined intuitively as follows. Cut the square ...
27
votes
6answers
898 views

Grid Based Digital Logic (Duodyadic Tiles)

Duodyadic tiles are kinds of square function blocks that take two inputs, one from their top side and one from their left side, and have two outputs, one on their right side and one on their bottom ...
26
votes
19answers
3k views

Vampire Compatibility

A little known fact about vampires is that they must drink the blood of victim that has a compatible donor blood type. The compatibility matrix for vampires is the same as the regular red blood cell ...
-3
votes
5answers
154 views

42 in Rod Logic

Write the shortest possible program which takes a numeric input and outputs the result of adding 42 to the input. f(x) -> x + 42 There's only one restriction. Your program can only be composed ...
36
votes
10answers
4k views

The Urinal Protocol

Background The so-called "Urinal Protocol", describing the order in which individual urinals are picked in a men's bathroom, has been discussed in multiple places. One version is given in this xkcd ...
12
votes
1answer
164 views

Finding Symmetries in Squares

Write a program or function that takes in a list of positive integers. Each of these integers represents the side length of a square on a 2D plane. Each square can be moved to any integer coordinates ...
15
votes
6answers
472 views

Sorted Lexical Partition of a Number

The challenge is really simple: given a number, you split its digits into an array of smaller numbers such that the resulting numbers are non-decreasing. The catch is that you have to split it such ...
14
votes
5answers
676 views
+150

Generate a Rectangle from a Specification

Introduction This challenge is inspired by Grime, my 2D pattern matching language. Basically, you are given a "grammar" that describes two-dimensional grids of characters, and your job is to generate ...
13
votes
5answers
1k views

Calculate π with quadratic convergence

Write a function or complete program that takes a positive number n and performs n steps of an iterative algorithm for calculating π that has quadratic convergence (i.e. it approximately doubles the ...
8
votes
33answers
3k views

Count the number of ones in unsigned 16 bit integer

Write some statement(s) which will count the number of ones in an unsigned sixteen bit integer. For example, if a variable s = 1337, then set ones to 6 because 1337 as a sixteen bit binary number is ...
23
votes
9answers
2k views

Two-way Palindromic Closure Generator

Introduction A palindromic closure of an input string is the shortest palindrome that can be constructed out of the input string where the final palindrome starts with the input string. For this ...
3
votes
4answers
264 views

Words of centuries

I'd like to get a list of words that are strongly connected with a particular time epoch, for example, 19th century, 20th century and 21st century. I suspect that nobody used a word like "smartphone" ...
1
vote
11answers
392 views

Palindromic palindrome generator

Create a program, that converts input string to a palindrome starting with the input string. The program itself must be a palindrome. For example input: neverod, print neveroddoreven. You should ...
10
votes
5answers
849 views

Transmit Pi… precisely

Following on from Monte Carlo estimator of Pi this challenge is to produce the shortest code for the constant Pi. Except here your code must output consecutive digits of pi forever. This is code ...
8
votes
2answers
549 views

Write a GIF encoder

Yes, the good old GIF. Loved for its versatility, hated for its patents and partly obsoleted due to its limitations (and patents), GIF consists, at the core, of a color palette and a palette-indexed ...
16
votes
5answers
563 views

A Basic Pyth-like Syntax Checker

Pyth is a golfing language based on Python. It uses prefix notation, with each command having a different arity (number of arguments it accepts). Your task is to write a syntax checker for a ...
6
votes
3answers
247 views

Latin Word Judgment

Because I can't concentrate on any task for more than about 5 seconds, I often find myself breaking up words into a sub-strings, each of which is a different length and doesn't contain any repeated ...
12
votes
4answers
412 views

Tracing the Hues of an Image

Load an image into this stack snippet and move your mouse over it. A black curve that follows the hue angle, starting at your cursor point, will be drawn: <script ...
6
votes
6answers
511 views

Sort all the pixels of an image by the number of occurrences

Input The name of a file in the raster graphics format of your choice. The chosen format must support at least 8 bits per channel and 3 channels. Output A file in the same format, with the same ...
12
votes
21answers
2k views

Monte Carlo estimator of Pi

Happy Pi Day everyone! For no reason at all, I'm trying to construct a Monte Carlo estimator of Pi that is as short as possible. Can we construct one that can fit in a tweet? To clarify, what I have ...
9
votes
2answers
228 views

Summing colored graphs

In some cases, often in physics, you have to sum graphs. Your challenge is to write, in a language of your choice, a program or function that takes multiple graphs as images, calculates all possible ...
18
votes
4answers
828 views

Calculate the size of the moon

The size of the moon mystery I am sure you have heard that the moon changes its size. When you're in love and you're lucky, the moon is almost twice in size compared to normal situations. Some people ...