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
1answer
61 views

WTF.js Obfuscator

Background One of the commonly meme'd aspects of javascript is its incredibly loose type coercion that allows for +!![]+[+[]] == '10' this technique can also be ...
19
votes
26answers
1k views

Shift right by half a bit

The challenge is to implement a program or function (subsequently referred to as "program") that takes a nonnegative integer \$n\$ as input and returns \$n\over\sqrt{2}\$ (the input divided by the ...
3
votes
1answer
192 views

How predictable is popular music?

The McGill Billboard Project annotates various audio features of songs from a random sample of the Billboard charts. I scraped this data to produce the following file of chord progressions: ...
15
votes
13answers
661 views

Bucket and Minimize

The challenge - given a numeric list L and an integer N as inputs, write a function that: finds the bucket sizes for L such that it is split into N whole buckets of equal or near-equal size, and ...
22
votes
44answers
5k views

Internal Truth Machine

It's a normal truth machine but instead of taking input, it uses the first character of the program. Thus, internal. The 0 and 1 are plain characters, i.e. ASCII code 0x30 and 0x31 respectively. ...
1
vote
0answers
59 views

Selfish Programs [duplicate]

The Challenge Write two programs P and Q such that: P and ...
0
votes
0answers
52 views

What is the shortest brainfuck quine? [duplicate]

(Apart from the empty program of course) The shortest I could find was this 410 byte beauty: ...
23
votes
21answers
7k views

What's my telephone number?

Introduction The telephone numbers or involution numbers are a sequence of integers that count the ways \$n\$ telephone lines can be connected to each other, where each line can be connected to at ...
-7
votes
0answers
128 views

Bootstrap your language [closed]

Interpret language X in language X with as little code as possible. Your implementation of language X must be able to interpret on your implementation of language X, and your implementation of ...
3
votes
1answer
225 views

Cutting Sequence for N dimensions

Inputs: The program or function should take 2 vector-like (e.g. a list of numbers) O and V of the same number of dimensions, and a number T (all floating-point numbers or similar) Constraints: T >=...
26
votes
27answers
3k views

Smallest number such that concatenation is a square

Challenge Write a program or function that takes a number \$n\$ and returns the smallest \$k\$ such that concatenation \$n'k\$ is a square. This sequence is described by A071176 on the OEIS. I/O ...
15
votes
12answers
1k views

Are the beams above or below the notes?

In musical notation, groups of notes shorter than one beat are joined together by a line at the bottom called a beam. Here are a few bars of music with the beams highlighted: (Taken from Second Suite ...
2
votes
14answers
2k views

Move my liquid to make me equal

You are given 4 positive integers: volume of the first container (v1), volume of the second container (v2), volume of the liquid ...
14
votes
10answers
705 views

Spotify Shuffle (music playlist shuffle algorithm)

Background Perfect shuffle algorithms like Fisher-Yates shuffle don't produce great results when it comes to music playlist shuffling, because it often produces clusters of songs from the same album. ...
10
votes
4answers
498 views

Keta Bracket Autocompletion

Special thanks to Bubbler and AdmBorkBork for supplying feedback about this challenge Keta (Keyboard tacit — clever naming, I know!) is a golfing language I’ve been working on recently. One of it’s ...
22
votes
18answers
7k views

99 ways to say “I love you”

Inspired by this blog post. Write a program that outputs 99 distinct programs (in the same language) that output the string I love you. How the programs are ...
16
votes
10answers
367 views

Decomposition of a matrix in \$ SL_2(\mathbb{Z}) \$

Background The special linear group \$ SL_2(\mathbb{Z}) \$ is a multiplicative group of \$ 2 \times 2 \$ matrices whose elements are integers and determinant is 1. It is known that every member of \$...
6
votes
14answers
2k views

Print out execution time of program [closed]

Challenge Write a complete program that prints out the time it took to execute a certain part of itself. That part must include a process whose total number of operations (and therefore execution ...
1
vote
0answers
48 views

Compositional inverse of a power series [duplicate]

If \$f(x) = x + \sum_{i>1} a_ix^i\$ and \$g(x)=x+\sum_{i>1}b_ix^i\$ then there is a composite power series \$f(g(x))\$ also of this form. Given a power series \$f\$ the goal is to find a ...
17
votes
20answers
5k views

Largest monetary amount impossible to make with two types of coin

Suppose we have two different types of coin which are worth relatively prime positive integer amounts. In this case, it is possible to make change for all but finitely many quantities. Your job is to ...
19
votes
15answers
822 views

Cartesian LCM of two arrays

Given two nonempty arrays of natural numbers \$a\$ and \$b\$, return the shortest nonempty array of pairs of natural numbers \$q\$ such that the sequence of first elements of \$q\$ consists of a whole ...
26
votes
40answers
4k views

Convert a 32 bit binary IPv4 address to its quad-dotted notation

Challenge Write a program or function that converts a 32 bit binary number to its quad-dotted decimal notation (often used for representing IPv4) Quad-dotted decimal A quad-dotted decimal is formed ...
5
votes
3answers
175 views

Recreate a simplified version of the card game L.L.A.M.A

In LLAMA, you want to dump cards from your hand as quickly as you can, but you might not be able to play what you want. Each player starts a round with six cards in hand; the deck consists of llama ...
9
votes
17answers
3k views

How many ACUs do I have?

Posted from sandbox The Intro What is an ACU? This challenge is based on the concept of money and since this is an international community, we all use different currencies, so in keeping with our ...
-6
votes
13answers
338 views

Dissect a word and arrange all its letters in alphabetical order

Question Write a program to accept one string on the console only and print back its letters arranged in alphabetical order. The string must only have the following characters: ...
-4
votes
5answers
238 views

Signpost reading [closed]

Challenge source: My: https://testovac.ksp.sk/tasks/ls18-signpost/download/ dated 11. 7. 2016 SPOJ: https://www.spoj.com/problems/SIGNPOST/ dated 2018-03-22 Challenge definition == Example input/...
15
votes
6answers
3k views

What's the Mayan date?

Just over seven years ago, everybody suddenly stopped talking about the Maya people. It is time to rectify that! For clarification, I am talking about the Mesoamerican Long Count Calendar. Your ...
12
votes
7answers
451 views

Make a random drum loop

Do randomly generated drum loops sound good? A drum loop is a \$5\times 32\$ matrix \$A\$ of \$1\$s and \$0\$s such that \$A_{1,1}=A_{1,17}=A_{2,9}=A_{2,25}=1\$, for each \$i\$, the \$i\$th row has ...
14
votes
15answers
4k views

Drum fill generator

Create a program that generates a drum fill. Your program will output a pattern of L (left hand hits), 'R' (right hand hits), and ...
4
votes
2answers
1k views

Shortest Solution in Python 3 for Caught Speeding - CodingBat

I am trying to find the shortest code in python 3, to solve this problem: You are driving a little too fast, and a police officer stops you. Write code to take two integer inputs, first one ...
15
votes
8answers
1k views

Is this quadrilateral tangential?

Related: Is this quadrilateral cyclic? Background A tangential quadrilateral is a quadrilateral which has an incircle: Examples include any square, rhombus, or a kite-like shape. Rectangles or ...
27
votes
10answers
6k views

Write a program that sees the New Year in itself

Write the smallest program that maps strings injectively to outputs and maps itself to 2020. To be clear, your program \$p\$ must have the following properties: every possible input string \$s\$ has ...
9
votes
4answers
480 views

When is Hannukah?

Input The input will be a year between 1583 and 2239. We just want to know when Hannukah was or will be in that year. This is information used by millions of people every year and put in calendars ...
30
votes
22answers
3k views

Generate a Nine-Ball Pool rack

Introduction Nine-Ball is a popular pool game played casually and as a competitive sport. There is one of each numbered ball, with the numbers 1 to 9. The game starts with all 9 of the balls in a ...
2
votes
3answers
182 views

Partial tq interpreter

In this task you are expected to provide a list output given an input tq program. The tq programs will not contain whitespace inside them. What is tq, in the first place? tq is a lazy-evaluated ...
14
votes
9answers
398 views

Partitioning Digits into Distinct Integers

Given a sequence of base-10 digits, output the longest list of integers that contains all the digits exactly once, in the order in which they appeared in the input, without repeating any integers. ...
9
votes
10answers
372 views

Integer Keys and Duplicates

Given a non-empty list/vector of positive integers, write a function to check the following conditions in as few bytes as possible. Take the first integer (the key, or k1) and check that the next k1 ...
-2
votes
2answers
228 views

Shorten String as Much as Possible [closed]

Introduction In a list of strings, there is a certain length you can shorten strings to before they become indistinguishable. This is a pretty bad explanation, so here is an example. ...
11
votes
9answers
673 views

Random spanning tree of a rectangular grid

Significantly harder version of Spanning tree of a rectangular grid. Background A spanning tree (Wikipedia) of an undirected graph is a subgraph that is a tree which includes all of the vertices of ...
23
votes
11answers
1k views

Random triple with uniform marginals

Output a random triple \$(x,y,z)\$ of real numbers such that \$x+y+z=\frac{3}{2}\$ Each of \$x,y,z\$, taken alone, is uniformly distributed from \$0\$ to \$1\$. Please explain in your answer what ...
0
votes
1answer
179 views

Determine if a number is less than another [closed]

Introduction Your job is to write a function or program that detects if a number a is less than a number b. But... You are not ...
5
votes
3answers
332 views

Swaps to Sort an Array

You are given an array \$A\$, which may contain duplicate elements. In each swap, you may swap the value of any two indices \$i, j\$ (i.e. switch the values of \$A_i\$ and \$A_j\$). What is the least ...
3
votes
1answer
188 views

How Shuffled is this Sequence?

Given a sequence \$S\$ with length \$n\$ of exactly one each of whole numbers from \$1\$ to \$n\$, your task is to return a number \$\sigma\$ indicating how shuffled it is. Definition of shuffledness ...
27
votes
37answers
2k views

CahartcreS awppnig (Character Swapping)

Intro/Background I was looking at "You Had One Job" pictures lately, and noticed an old favourite of mine: And I said to myself: "I need a program that can generate text like that". So I devised a ...
9
votes
1answer
244 views

Maximal 2-distance Sets

In the plane (\$\mathbb R^2\$) we can have at most five distinct points such that the distances from each point to every other point (except itself) can assume at most two distinct values. An example ...
28
votes
15answers
4k views

.-…--..---.-…--… the red-nosed reindeer

Can you recover a sequence of letters from a sequence of dots and dashes? In Morse code, x is represented by -..-, but without ...
13
votes
0answers
377 views

Is this ordinal prime?

You are given an countable ordinal \$1 < r < \varepsilon_0\$. Determine whether or not it is prime. If not, provide exactly two ordinals \$r_0, r_1 < r\$ such that \$r_0r_1 = r\$, following ...
4
votes
2answers
294 views

Minified Intcode Computer

As the trip through the solar system on your way to rescue Santa gets a little droll, so perhaps some optimizations to your Intcode Computer are in order. Namely, making it as small as possible ...
4
votes
11answers
717 views

Reversing and Shifting

Sandbox Adapted from exercise 8 of 100 little Keg exercises String manipulation is a very important part of any programming language. Consequently, that is what this challenge is about. The ...
8
votes
11answers
494 views

Convert Character Substrings to Numeric

I often have to take character data and categorize it numerically at work. A common thing I do is to take character type variables and convert them to numeric type characters, keeping same categories ...