Questions tagged [code-golf]

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, please state this explicitly in the challenge. If source code length is not the primary scoring criterion, consider using another tag instead.

Filter by
Sorted by
Tagged with
2
votes
20answers
526 views

Number in overlapping range

You are given two integers between lets say 1 and 12, one and two and a integer between lets say 0 and 4 which is called ...
10
votes
1answer
213 views

Interpreter for number theory, modulo n

A sentence of number theory (for our purposes) is a sequence of the following symbols: 0 and ' (successor) - successor means <...
27
votes
31answers
3k views

Output the list of musical notes

This task is simple: Write a program or function that outputs the list of all musical notes (using English note names) from A♭ to G♯. All notes without a name consisting of a single letter (i.e. ...
15
votes
16answers
4k views

Attacking the Hydra

Instead of being a skillful warrior capable of slaying Hydras (see here and here), this time you are a warrior that has no prior knowledge on how to kill one or which weapons to use against the ...
9
votes
7answers
1k views

An array battle with odd secret powers

Here is a relatively simple two dimensional array challenge. Imagine a battlefield of 625 foot soldiers. You command the odd troops, but unfortunately the strength of the even troops overwhelms you. ...
11
votes
34answers
1k views

Chunk + Enumerate a list of digits

I have a list of decimal digits: 4, 4, 4, 7, 7, 9, 9, 9, 9, 2, 2, 2, 4, 4 The list of decimal digits are known as items. We can form "chunks" from these items by ...
20
votes
12answers
2k views

Lípínguapua dopo Pêpê

Língua do Pê, or P Language, is a language game spoken in Brazil and Portugal with Portuguese. It is also known in other languages, such as Dutch and Afrikaans. (Wikipedia) There are some dialects in ...
33
votes
21answers
5k views

Telephone number in spoken words

Goal Write a program or function that translates a numerical telephone number into text that makes it easy to say. When digits are repeated, they should be read as "double n" or "triple n". ...
10
votes
7answers
242 views

Crossing sequences

Crossing Sequences Given a list of positive integers A, call it an increasing sequence if each element is greater than or equal to the previous one; and call it a ...
15
votes
18answers
2k views

Simplification of numbers

How, you can’t remember the 6 or 7-digit phone number that appeared on the TV screen for a second?! Using the special technique described below, you will turn into a walking phonebook! Obviously, the ...
32
votes
33answers
6k views

Is this n-speak?

Inspired by Is it double speak?, I devised a harder challenge. Given a string, determine if the string is n-speak, for any \$n\geq 2\$. N-speak is defined by repeating each letter \$n\$ times. With \$...
1
vote
5answers
208 views

Print an array as a table [closed]

Write a program that prints an associative array (key-value) to a table. Requirements Standard loopholes are forbidden Please include a link to an online interpreter and the byte count in the ...
30
votes
34answers
7k views

The cat ate your input again!

Create a cat program, a.k.a a program that takes an input and prints it. ...Except, the program will randomly take characters away from your input and print that instead. Each character in the input ...
0
votes
1answer
322 views

The Practice of Programming

At 1998, Brian Kernighan, while working on the book "The Practice of Programming", wanted to demonstrate realisation of regular expression engine. But struggled to find small engine, that cod could ...
18
votes
7answers
3k views

Y2K… in 2019?

It's August 10th, 2019, but your task still involves Y2K. Weird, right? Create a program that prints itself, with a two digit number appended to it. The first time you run it, it should append 00 to ...
5
votes
7answers
303 views

Bucket interpreter

Create a program that interprets the programming language Bucket. Bucket works on two buckets: the first can hold A and the second can hold B units of liquid. The things you can do with these buckets ...
20
votes
25answers
3k views

Write an interpreter for *

The task is simple. Write an interpreter for the language *. Here's a bigger link to the wiki. There are only three valid * programs: * Prints "Hello World" <...
5
votes
7answers
196 views

Dropsort with a Twist

This is my first attempt at a Code Golf question. If it needs obvious edits, please feel free to make them. Below is a description of the basic Dropsort algorithm. Dropsort is run on a list of ...
42
votes
15answers
4k views

Does this Foo machine halt?

Determining whether a Turing machine halts is well known to be undecidable, but that's not necessarily true for simpler machines. A Foo machine is a machine with a finite tape, where each cell on the ...
1
vote
0answers
159 views

Self-Contained Generator Function (JavaScript) [closed]

Create a function that takes in a generator function as its only parameter, and returns an object that can be used as both as a generator and a generator function for said generator. The idea is to be ...
7
votes
6answers
234 views

Help me sub-divide a time signature

This challenge is based on a video in which Andrew Huang discusses unusual time signatures... https://www.youtube.com/watch?v=JQk-1IXRfew In it, he advises that you can understand time signatures by ...
21
votes
14answers
6k views

Look mom! I made my own (Base 10) numeral system! [closed]

We've all done it, well, maybe not, but making your own alien language and numbering system is a staple of especially fantasy writing, but is mostly just a fun activity. The task is simple, take two ...
2
votes
1answer
161 views

Black and white shirt 2

This is a more complicated version of this puzzle. The premise is the same but a few rules differ in a few key places, making for a more complex problem. Assume I have some number of black shirts and ...
1
vote
7answers
382 views

Black and white shirts

This puzzle is based on this Math.SE post. A more complex version of this problem can be found over here. Assume I have some number of black shirts and some number of white shirts, both at least 1. ...
8
votes
1answer
231 views

Radioactive Bit Checking

Note: This is the radiation-hardening version of my previous challenge Pristine Bit Checking. This should be much more difficult than that one. Write a program/function that takes two integers in the ...
15
votes
18answers
2k views

Decode a variable-length quantity

A variable-length quantity (also referred to as VLQ or uintvar) is a way to encode up to a 28 bit integer value using only as many bytes as necessary. This was used ...
7
votes
6answers
890 views

Determine Beckett Grading Service (BGS) Final Grade

Introduction: Beckett Grading Service (aka BGS), is a company which encapusulates and grades Trading Card Game (TCG) cards (i.e. sport cards, Magic The Gathering, Pokémon, Yu-Gi-Oh, etc. etc.). The ...
45
votes
71answers
9k views

Is it double speak?

In an earlier challenge I asked code golfers to produce strings which copy each character in a string. For example: TThhiiss iiss ddoouubbllee ssppeeaakk!! ...
15
votes
14answers
2k views

Generate a random point outside a given rectangle within a map

Introduction Given this visualization of a playing field: ...
11
votes
2answers
740 views

Tile the chessboard with four-colored triominoes

Task: Consider the problem: "given a chessboard with one square missing, cut it into 21 L-triominoes". There is a well-known constructive proof that this can be done for any square chessboard size ...
16
votes
10answers
4k views

Write The Shortest Program To Check If A Binary Tree Is Balanced

For each node in a balanced binary tree, the maximum difference in the heights of the left child subtree and the right child subtree are at most 1. The height of a binary tree is the distance from ...
34
votes
35answers
5k views

Repeated! Factorials!

Not to be confused with Find the factorial! Introduction The factorial of an integer n can be calculated by $$n!=n\times(n-1)\times(n-2)\times(...)\times2\times1$$...
18
votes
19answers
6k views

Write The Shortest Program to Calculate Height of a Binary Tree

The height of a binary tree is the distance from the root node to the node child that is farthest from the root. Below is an example: ...
18
votes
1answer
290 views

Complete the grid-filling meander

A grid-filling meander is a closed path that visits every cell of a square \$N \times N\$ grid at least once, never crossing any edge between adjacent cells more than once and never crossing itself. ...
4
votes
2answers
240 views

Regex golf and ccTLDs, hooray!

Write a regex that only matches valid country code top level domains (ccTLDs). Your regex must match both the domains with the dot and without the dot (it must match tv and .tv). Any domain that is ...
-3
votes
10answers
439 views

Decode an URL string

Challenge I think everyone of us heard of URL encoding mechanism - it's basically everywhere. Given an URLEncoded string on stdin, decode it, and output the decoded form to stdout. The encoding is ...
7
votes
2answers
368 views

Formula One Strategist

Introduction Formula One is a complex sport and as with complex sports, strategy is very important.Some teams will manage better strategy than others and those teams will often win the races. After ...
57
votes
118answers
11k views

“DDoouubbllee ssppeeaakk!!”

Super simple challenge today, or is it? I feel like we've heard a fair bit about double speak recently, well let's define it in a codable way... Double speak is when each and every character in a ...
28
votes
4answers
2k views

Move arrows along a contour

Sandboxed Given a set of closed non-overlapping 2d contours (separated by at least one space even on diagonals) with arrows oriented consistently in the same clockwise or counter-clockwise direction (...
-4
votes
5answers
338 views

Shortest way to get a TypeError

It's simple, simply write the shortest code to raise a TypeError. In Python you can do: raise TypeError However it should be ...
11
votes
5answers
788 views

Does this addition pyramid puzzle have a unique solution?

Given an addition pyramid \$P\$, determine whether it can be solved. An addition pyramid consists of layers, each having one number less than the one below it. Layer \$i\$ is symbolized as \$P_i\$. \$...
11
votes
6answers
512 views

Virus vs Antidotes code golf [closed]

There is a rectangular 2D array containing viruses denoted by 'v', antidote1 denoted by 'a', and antidote2 denoted by 'b' (there are no values other than 'v', 'a' and 'b'). Antidote1 can kill ...
18
votes
12answers
2k views

Composing fill in the blanks

Let us say that we have a particular set of functions on strings. These functions are kind of like fill in the blanks or madlibs, except that they only take one input and use that to fill in all of ...
29
votes
16answers
6k views

To find islands of 1 and 0 in matrix

Given a two dimensional matrix of 0 and 1s. Find the number of island for 1s and 0s where neighbours are only in the horizontal and vertical. ...
5
votes
19answers
502 views

Get delta of days by current hour and added delta of days

Inputs: current hour: from 0 to 23 (inclusive) delta of hours: [current hour] + ...
23
votes
22answers
2k views

Invert Some Switches on a Switchboard

Inspired by this challenge. Goal: Given a pre-configured switchboard and a list of indexes, invert the switches at the given indexes. A switchboard is made up of some number of switches (...
22
votes
43answers
4k views

Character Frequency in a String [duplicate]

Given a string of printable ASCII, output the frequency of each character in that string. The Challenge Input is given as a string of printable ASCII characters (decimal ...
27
votes
29answers
4k views

Inverse Colombian Function

Let's define a sequence: The n digit summing sequence (n-DSS) is a sequence that starts with n. If the last number was k, then the next number is k + digit-sum(k). Here are the first few n-DSS: ...
2
votes
0answers
214 views

What are some of the most character-efficient programming languages? [closed]

Like Brainfuck or JSFuck would be efficient in terms of number of characters needed, but what languages would have the highest amount of information per character? I was thinking of APL and J but ...
32
votes
23answers
4k views

Brute-force the switchboard

The other day, our team went to an escape room. One of the puzzles involved a board of six mechanical switches where you had to find the correct combination of on and off in order to unlock a box, ...