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

0
votes
0answers
11 views

calculate the first n perfect numbers

Write a program that calculates the first n perfect numbers. A perfect number is one where the sum of the factors is the original number. For example, 6 is a perfect number because 1+2+3=6. No non ...
8
votes
3answers
152 views

Valid snakes on a plane

Inspired by one of Vi Hart's videos (which are a treasure trove full of potential challenge ideas) A snake is made up of segments of same length and the connection between each segment can be ...
3
votes
1answer
43 views

Shortest Identifying Substring

This challenge is inspired by dmenu, the program I use to launch other programs on my Linux box. To start, for example, GIMP, I simply hit the keyboard shortcut I have assigned to dmenu, type "gimp" ...
9
votes
2answers
119 views

Books on a Shelf

I have some books and a bookshelf. I would like to put as many books on the shelf as possible but I have a rule. All dimensions of the books (height, width and depth) should form a non-increasing ...
0
votes
1answer
52 views

Pythy Finite Ordinals [duplicate]

Write a program in any language that takes a single natural number n as input and generates a Pyth program that, in turn, produces, using nested lists, the nested set given by S(n), where: S(0) = ...
16
votes
2answers
279 views

Can you cast the spell?

In Magic: the Gathering, mages (known as "planeswalkers") battle each other by casting spells. Spells cost mana. Five colors of mana exist: White, Blue, Black, Red, and Green, represented as {W}, {U}, ...
53
votes
12answers
2k views

Do you want to code a snowman?

Here is a simple ASCII art snowman: _===_ (.,.) ( : ) ( : ) Let's make him some friends. This will be the general pattern for our ASCII art snowpeople: HHHHH HHHHH X(LNR)Y X(TTT)Y (BBB) The ...
9
votes
1answer
216 views

Concatenate lists of strings item-wise in Python

This is a tips question for golfing in python. Suppose you have two lists of strings, and you want to concatenate the corresponding entries from each list. E.g. with a=list("abcd") and ...
13
votes
0answers
113 views

Can you fold a hexomino into a cube?

One of my kid's favorite toys is a set like this. Actually its one of my favorite toys - I've been playing with it and its been giving me some PPCG challenge ideas. Here's one: Write a program or ...
7
votes
2answers
115 views

Digits Digging a Dungeon

Given a non-decreasing list of one-digit positive integers, you should determine how deep dungeon the digits will dig. ███ ███ A dungeon with 5 blocks removed and a depth of 3. ███ ███ ███ ████ ...
8
votes
2answers
236 views

You call it Centering, I call it Code Golf

"Let's face it, aligned images are like little gifts from Heaven. Welcome, but unexpected." - Geobits +10000 reputation to whoever wins this challenge. Rules: 1) You are to generate a program. 2) ...
33
votes
8answers
2k views

Not Your Routine Bean Machine

Consider this ASCII version of a mechanism similar to a bean machine or plinko/pachinko game: O ^ \ ^ ^ ^ \ \ ^ / ^ U U U U U 1 2 3 4 5 The O is a ball that falls down. When it ...
17
votes
7answers
832 views

Convert a fraction to a repeated decimal

Almost the polar opposite if this challenge, and I suspect it will be slightly easier. Your task is to take two integers in the format a/b (Forming a rational number) then output the number in ...
12
votes
3answers
841 views

Is that word Feminine or Masculine?

Write a program or function that takes in a single string containing only lowercase a-z, and prints or returns a truthy value if the word is the feminine version of the thing it represents and a falsy ...
23
votes
10answers
2k views

Where will your buddies sit?

You and some buddies are going bowling. There are a total of N bowlers. However, there are only N-1 chairs to sit in. The solution is simple: whoever's turn it currently is doesn't get a chair. Then ...
11
votes
1answer
253 views
+50

ASCII Art Generation

Task Write a program or function that takes an image of width w and height h, and two integers a <= w/2 and b <= h/2, and outputs an ascii art representation of the image, with the dimensions a ...
11
votes
3answers
303 views

Make an almost quine

I wanted to fool a friend by giving him a quine that almost worked, but became sloppier and sloppier. Create a program that, when run, will output the program, but one character off. Either one ...
41
votes
20answers
4k views

Golf Your Language's Identicon

Identicons are small images of geometric patterns that represent the hash value of a string. Stack Exchange uses the identicons from Gravatar as each user's default avatar image. In this challenge, ...
4
votes
0answers
232 views

Optimising Arithmetic Expressions [on hold]

Create a program or function that, given a postfix expression, converts it to the simplest equivalent expression. The expression may contain positive single-digit numbers, integer variables denoted a ...
15
votes
3answers
245 views

Race of the Digits

You should write a program or function which given a starting order of distinct one-digit positive integers and the length of the track as input outputs or returns the finish order of the numbers. ...
31
votes
7answers
1k views

Build a steady brick wall

A brick wall is a rectangle made of horizontal 1-by-n bricks stacked into rows. Here's a wall of height 4 and width 8, with brick sizes shown on the right. [______][______] 4 4 [__][____][__][] ...
5
votes
1answer
149 views

Finding Pairs for Letters

You should write a program or function which given a string as input outputs or returns a string or list of the lowercase letters in the order they find their uppercase pair. The input is a string ...
16
votes
7answers
576 views

Last Nonzero Digits of a Factorial in Base

You should write a program or function which given three positive integers n b k as input outputs or returns the last k digits before the trailing zeros in the base b representation of n!. Example ...
13
votes
33answers
3k views

Death By Shock Probe: That's a lot of dice

In the webcomic Darths & Droids, Pete, who plays R2-D2 in the fictional roleplaying campaign around which the comic is based, once claims (warning: potential spoilers in the linked comic) that, ...
16
votes
1answer
202 views

Tallest tower from a set of digits

Given a set of 1-digit numbers, you should determine how tall a tower they can construct. The digits live on a horizontal plane with a ground level where they can stand. No digit wants to be confused ...
9
votes
4answers
567 views

Theseus' New Ship

The Ship of Theseus is an old question that goes something like: If a ship has had all of its original parts replaced, is it still the same ship? For this golf, we're going to slowly replace ...
14
votes
5answers
490 views

Real-time string matching

Task The task is to golf a real-time exact string matching algorithm of your choice. Input Two lines of text supplied on standard input, separated by a new line. The first line contains the ...
18
votes
13answers
2k views

Random Golf of the Day #4: The Bertrand Paradox

About the Series First off, you may treat this like any other code golf challenge, and answer it without worrying about the series at all. However, there is a leaderboard across all challenges. You ...
-2
votes
0answers
47 views

Evaluate simple mathematical expressions [duplicate]

Given a simple mathematical expression (examples are listed below), return the answer, without using eval, exec, or arithmetic expansion. Expression may be decimals, returned with precision to the ...
14
votes
1answer
246 views

Find Patterns in Strings

In this challence, your task is to locate substrings with a given structure. Input Your input shall be two non-empty alphanumeric strings, a pattern p and a text t. The idea is that each character ...
29
votes
7answers
2k views

Area of an ASCII polygon

You should write a program or function which receives a string representing an ascii-art polygon as input and outputs ot returns the area of the polygon. The input is a string consisting of the ...
19
votes
12answers
469 views

Road-Length Encoding

In the United States, the two opposing directions of traffic on a road are separated by a dashed yellow line if passing is allowed and two solid yellow lines if passing is not allowed. (Just one ...
21
votes
15answers
1k views

Evaluating Dotty Strings

Write a program that takes in an odd length string containing only the characters . and :. With the aid of an initially empty stack, generate a number from this string as follows: For every character ...
8
votes
3answers
187 views

Generating Euclidean rhythms

Did you know that the Euclidean algorithm is capable of generating traditional musical rhythms? We'll see how this works by describing a similar, but slightly different algorithm to that in the paper. ...
17
votes
11answers
1k views

Counting in pyramids

You should write a program or function which receives a list of distinct integers as input and outputs or returns the number of occurrences of the input numbers in the following upside-down number ...
15
votes
4answers
707 views

Shifty XORyption

Write a program or function (or set of programs/functions) to encrypt and decrypt data given the following specification: Encryption Calculate an XOR hash of the input by XOR-ing every byte with ...
11
votes
2answers
176 views

Y-Wing Strategy for Sudoku

I recently got a new Sudoku app that produces really hard Sudoku's, which can't be solved using the standard strategies. So I had to learn a few new ones. One of these strategies is the Y-Wing ...
7
votes
2answers
249 views

Randomized Brainfuck Compiler

Joe is your average BF developer. He is about to check in his code changes to their repository when he gets a call from his boss. "Joe! The new client's machine is broken! The brainfuck interpreter ...
19
votes
4answers
966 views

(Somewhat) Pedantic Birthday Paradox

Background The birthday paradox is a popular problem in probability theory which defies (most people's) mathematical intuition. The problem statement is: Given N people, what is the probability ...
28
votes
4answers
3k views

Quick! Escape the black hole!

It is the year 87,539,319 and solitary space-walking is now commonplace, many people travel into space by themselves, propelled by nothing but a jetpack on their backs, programming their course with a ...
15
votes
7answers
829 views

Binary Images of Triangle Counts

My challenges tend to be a little bit hard and unattractive. So here something easy and fun. Alcuin's sequence Alcuin's sequence A(n) is defined by counting triangles. A(n) is the number of ...
6
votes
3answers
427 views

Leibniz golf in C#

I'm starting with golf code. But im only do C# so I know wont be a breaking record, but I want give it a try. Leibniz Challenge is here The first line contains the number of test cases (N) which is ...
12
votes
0answers
230 views

Determining the rotation of square given a list of points

In this challenge, you will be given a list of points. These points will lie on the perimeter of an imaginary square. Your goal is to: If possible, print out the rotation of the square, which will ...
4
votes
1answer
207 views

Word fractal plotter

Iterated Function Systems An Iterated Function System (IFS) is a method of constructing self-similar fractals. Each fractal is defined recursively as the union of several copies of itself, with each ...
11
votes
2answers
540 views

Smoothing out a list

You should write a program or function which takes a non-negative integer k and a sorted integer list Las input and outputs or returns a smoothed list M. M is created from the ascending list L by ...
15
votes
9answers
1k views

Compute the Hausdorff Distance

Introduction The Hausdorff distance measures the difference between two subsets of a metric space. Intuitively, a metric space is just some set with a built-in distance function; in this challenge, ...
18
votes
3answers
554 views

Stringing a Pearl Necklace

Overview Pearls (or Masyu) is a logic game played on a grid. There are black and white pearls placed on the grid. The object is to form a single, closed loop that travels through each pearl using ...
13
votes
6answers
438 views

Tiling a 2^N by 2^N Grid with L-Shaped Trominoes

When students are first taught about the proof technique of mathematical induction, a common example is the problem of tiling a 2N×2N grid with L-shaped trominoes, leaving one predetermined grid ...
47
votes
32answers
4k views

Telescopic Parentheses

Consider a non-empty string of correctly balanced parentheses: (()(()())()((())))(()) We can imagine that each pair of parentheses represents a ring in a collapsed telescopic construction. So let's ...
18
votes
9answers
2k views

Who wins a Spades trick

Write code to determine who wins a four-card trick in a game of Spades. Fewest bytes wins. The input is a string that lists the four cards played in sequence like TH QC JH 2H (Ten of Hearts, Queen of ...