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

5
votes
4answers
100 views

Remove single line and multiline comments from string

Goal Using the programming language of your choice, write the shortest program to eliminate comments from a string representing a C program. Input The string can be... given as a function ...
-5
votes
0answers
108 views

StackEgg “Automater” [on hold]

As you know, there is a game known as StackEgg on stack exchange. Since we are all busy people, we will write a script to play it for us. Specifically, write a script that does the following. The ...
2
votes
1answer
152 views

■ or ■+■ or ■+■+■ or ■+■+■+■ [duplicate]

Sum of squares Goal: Write a given natural number as sum of squares. Thanks to Lagrange, Fermat and Legendre we know that you can write any positive integer as sum of (one), two, three, or maximal ...
9
votes
1answer
337 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 ...
2
votes
2answers
231 views

DoIt Java Style [on hold]

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 ...
28
votes
4answers
3k 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 ...
11
votes
5answers
428 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 ...
9
votes
1answer
236 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. ...
17
votes
2answers
325 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
292 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
329 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
465 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 ...
18
votes
16answers
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
187 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
3answers
390 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
882 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
537 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
337 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
8answers
884 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 ...
6
votes
0answers
196 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
5answers
116 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
328 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
832 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
186 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
909 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
166 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
473 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
726 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
395 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
851 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
551 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
564 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
250 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
6answers
502 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
513 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 ...