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

14
votes
11answers
416 views

I'm not the language you're looking for!

Isn't it annoying when you find a piece of code and you don't know what language it was written in? This challenge attempts to somewhat solve this. Challenge You will have to write a program that ...
2
votes
3answers
118 views

Output optimal trill fingerings

Note: all array references in this post are zero-indexed. When playing the piano, two notes on the same key must be pressed with two different fingers. You could use the same finger, but it doesn't ...
7
votes
1answer
72 views

Text Processing #1: Hyphenation

Background This is the first part of a 3-hole golf course on text processing. The over-arching idea is that if you take an input text and pipe it through the solutions to all three challenges (with a ...
0
votes
0answers
32 views

UDP client server programming related question [on hold]

Write an algorithm each for UDP client and UDP server with the following specifications:  Client should prompt a user to enter two numbers  Client program will send these numbers to the server.  ...
7
votes
7answers
1k views

Have you mooed today?

The Debian Linux distribution (and Debian-based distros, like Ubuntu, Kali and others) uses a package-manager called APT. To install program foo you would type into a terminal sudo apt-get install ...
4
votes
1answer
276 views

What is the shortest infinite loop statement?

I'm working on a golf for Java and I need an infinite loop. Obviously, I don't want to spend any more bytes than I have to, especially in such an expressive language. Assuming I have some code I want ...
10
votes
35answers
893 views

Find the occurrences of a character in an input string

Challenge Write a program that, given a string x which is 10 characters long and a character y, outputs the number of times character y occurs in string x. The shortest program in bytes to do so ...
28
votes
9answers
2k views

Print This Question ↓

The basic idea of a kolmogorov-complexity challenge is to print a set output in the shortest code (though that meaning has changed now). We have had many of them, from Borromean Rings to The ...
4
votes
0answers
130 views

The spoak laugh generator [on hold]

The spoak laugh For those who don't know, in Brazil some people laugh on chats like this: aposkpaoskaposkaposkpaokspaoskpaoksa. So here is the challenge: To make a program that generate this laugh ...
8
votes
1answer
157 views

Plot a hyperbolic plane tessellation

Make a plot (Poincare disk) of a tessellation on a hyperbolic plane, such as: The program takes four inputs: 1) How many edges/polygon (three in this example). 2) How many intersect at each ...
11
votes
3answers
365 views

How bold is this post?

Preamble In Stack Exchange markdown, we use ** to bold out text. For example, this markdown: The **quick brown fox jumps over the lazy** dog. Renders as: The quick brown fox jumps over the ...
36
votes
7answers
4k views

It's super effective!

In Pokémon there are 18 types: Normal Fighting Flying Poison Ground Rock Bug Ghost Steel Fire Water Grass Electric Psychic Ice Dragon Dark Fairy A Pokémon can ...
11
votes
1answer
173 views

Count the trees

A tree is a connected, undirected graph with no cycles. Your task is to count how many distinct trees there are with a given number of vertices. Two trees are considered distinct if they are not ...
12
votes
1answer
202 views

Recursive ASCII Spirals

In the great tradition of ASCII Art Challenges on this site, here's another one. Given an input, draw a spiral. &>----v ||>--v| |||>v|| |||@||| ||^-<|| |^---<| ^-----< Simple, ...
15
votes
4answers
536 views

What's the voltage over each component?

The picture below shows a RLC circuit. A RLC circuit is an electrical circuit consisting of a resistor (R), an inductor (L), and a capacitor (C), connected in series or in parallel. (1) In order to ...
15
votes
16answers
1k views

A calculator as a list of numbers and operators

Your task is to take a list of arguments that are either integers or operators, and parse them like so: There is a current operator, which starts as +. Each time an operator is found, the current ...
29
votes
12answers
3k views

Visually Explain the Pythagorean Theorem

A common visual explanation of the Pythagorean theorem is as such: The squares are meant to represent the side length's squared, and the areas of a + b = c, just like the Pythagorean theorem says. ...
1
vote
0answers
183 views

Back to the future: Post-quantum cryptography [on hold]

If you know your programming history, you may know that one of the earliest code golf challenges was to implement RSA encryption. Now, I'm challenging you to code golf an encryption system that is ...
-3
votes
0answers
94 views

Sing the Australian National Anthem - joyfully! [on hold]

We Australians have a pretty awful national anthem. Here it is in all its glory: To the tune of Advance Australia Fair Australians all let us rejoice, For we are young and free; We've golden ...
19
votes
43answers
2k views

Comparing two numbers

Challenge Given two integers A and B as input, you must write a program which outputs if A>B, A==B or A<B. The integers will be in any reasonable range supported by your language which ...
11
votes
3answers
277 views

Possible Tetris sequences

Write code to figure out whether a run of Tetris pieces could be generated by the official Tetris algorithm. Fewest bytes wins. Official Tetris games generate the sequence of falling pieces in a ...
24
votes
6answers
3k views

Is the pizza fair?

This question is inspired by, and is the inverse of this one. Dennis (E), Doorknob (D), Martin (M) and Chris (C) have ordered a pizza. The rectangular pizza is divided into square pieces, each marked ...
19
votes
10answers
2k views

Dead code elimination

Dead code sits there doing nothing, staring at us knowing it will never be executed... but today we can take revenge. Specification The input will be a multiline string. Each line may either be an ...
3
votes
2answers
155 views

Interpreted Interpreter [duplicate]

Duplicate? I knew somebody must've done this before. Programming a programming language in itself is something that has interested me since I knew what a programming language was. So I thought I'd ...
34
votes
7answers
880 views

Zigzagify a String

Write a program (or function) that takes in a non-empty string of any printable ASCII characters. Print (or return) a zigzagging chain of the characters in the string with every neighboring pair of ...
36
votes
7answers
1k views

Dennis, Doorknob, Martin Büttner, Chris Jester-Young - Pizzeria!

Programming Puzzles & Code Golf is about to get a new moderator, Dennis! This challenge is a tribute to him and our other active (or recently active) moderators: Doorknob, Martin Büttner, and ...
86
votes
204answers
10k views
+100

“Hello, World!”

So... uh... this is a bit embarrassing. But we don't have a plain "Hello, World!" challenge yet (despite having 35 variants tagged with hello-world, and counting). While this is not the most ...
25
votes
9answers
1k views

Fond Memories of Past Primes

Consider a prime number p, written in base 10. The memory of p is defined as the number of distinct primes strictly less than p that are contained as substrings of p. Challenge Given a non-negative ...
18
votes
1answer
313 views

Who is the rightful ruler?

Who will rule the realm? You are given a family tree which contains: name, sex, date of birth, date of death and a list of heirs, for each family member. You may use any convenient (nested) list ...
17
votes
1answer
223 views

Convert Brainfuck to MarioLANG

MarioLANG is a two-dimensional programming language where the source code resembles a Super Mario Bros. level. Furthermore, its instruction set is very similar to Brainfuck's. This means that ...
33
votes
4answers
2k views

Enumerate valid Brainf**k programs

Golunar/Unary is a way to encode all valid Brainfuck programs, but it is not an enumeration, since most natural numbers do not correspond to a valid program. For the purpose of this challenge, assume ...
10
votes
4answers
232 views

A backwards relationship

Write a program or function that, given two ASCII strings A and B, will produce strings A' and B' where the common substrings are reversed in their place. The process for finding A' is as follows: ...
20
votes
15answers
1k views

Let's see some action!

Who doesn't love action movies with fast noisy cars, especially those with a lot of crashes? Who doesn't love action shots in ascii art? The scene is: Two cars are starting at opposite sides of a ...
9
votes
1answer
323 views

Solve a game of Accordion

Accordion is a solitaire card game I recently came across where nearly every layout is solvable, but incredibly hard. You can play it here. Rules 52 face cards are placed face-up in a random order. ...
21
votes
19answers
4k views

Stop, stand there where you are!

Challenge Write a function which takes one parameter: an integer t. Your function has to stop your program for t seconds before continuing, similar to time.sleep(t) in Python and WAIT t in BBC BASIC. ...
18
votes
1answer
242 views

Shapeshifting boxes

I define four box styles: +-----+ ooooooo ^^^^^ ******* | 1 | o 2 o < 3 > * 4 * | | o o < > * * +-----+ ooooooo vvvvv ******* Write a ...
37
votes
12answers
4k views

A naturally occurring prime generator

There are quite a large number of prime generating functions. Pretty much all of them are constructed and are based on the sieve of Eratosthenes, the Möbius function or the Wilson's theorem and are ...
11
votes
4answers
331 views

Approximate Square Formation

Background I have a bunch of square-shaped boxes of equal size, and since I'm a neat person, I want to arrange them all into a square formation. However, their number is not necessarily a perfect ...
8
votes
4answers
303 views

Number of domino tilings

Write a program or function that given positive n and m calculates the number of valid distinct domino tilings you can fit in a n by m rectangle. This is sequence A099390 in the Online Encyclopedia of ...
5
votes
0answers
326 views

Up 12 at 4 it's

Introduction On BBC Radio 2, on Saturdays there's a show hosted by Tony Blackburn called Pick of the Pops. Here, Tony selects a random week from a random year (in the range 1960-1989), and plays the ...
58
votes
14answers
2k views

Vertically collapse text

Say I have text like this (each word on one line, with no spaces) Programming Puzzles & Code Golf That makes no sense! It totally defies the laws of physics. Your challenge is to remedy this ...
7
votes
0answers
160 views

Can I make that shape with blocks, slabs, and stairs?

Consider a rectangular two-dimensional grid where each cell can either be empty (.) or full (0). e.g. ..00.... 0000.... .00000.. 000...00 ..000000 000.00.. The grid is considered infinite, all ...
14
votes
5answers
789 views

Fibonacci in +!()[]script

Write a piece of JavaScript code that calls alert with an array containing the first 50 Fibonacci numbers in order. You may only use the following characters: +!()[]. As a reference, your code must ...
9
votes
11answers
613 views
+50

Distributing Numbers

In this challenge you'll be using be distributing a product over sums and differences of numbers, as explained here. Examples Input | Output -------------|------------- 23(12+42) | ...
6
votes
1answer
214 views

Computing the geometric median

Given a list of integer points in an n-dimensional space, output the geometric median. Note that the output is not necessarily integer. Your answer must be precise to at least two digits after the ...
4
votes
0answers
174 views

Check all the keys of a keyboard [closed]

Write the shortest program that waits for every key of a Standard 101 key US Keyboard to be pressed at least once in any order and then exits writing OK! Every time a key is pressed the program ...
10
votes
0answers
254 views

Magic: the Gathering Combat Golf

Magic: the Gathering is a trading card game where, among other things, players play cards representing creatures, which can then attack the other player, or defend against the other player's attacks ...
-7
votes
7answers
187 views

Puzzle: Factor these 256-bit semiprimes [closed]

Challenge Write a program to factor this set of 10 numbers: 15683499351193564659087946928346254200387478295674004601169717908835380854917 ...
8
votes
3answers
265 views

Zig-zag strings

Zig-zag strings Given a string and a positive integer, output the string in a zig-zag wave pattern with a peak amplitude and character spacing equal to the integer. This is similar to this question ...
-1
votes
0answers
54 views

Simultaneous Equation Solver [duplicate]

Solve linear simultaneous equations with up to 26 variables (a-z). Edit: This question is similar but different to the one posed here. This question is designed to take in more natural inputs, as ...