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
0answers
154 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 >=...
24
votes
26answers
2k 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 ...
14
votes
10answers
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 ...
0
votes
12answers
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 ...
13
votes
10answers
611 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. ...
9
votes
3answers
437 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 ...
20
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
354 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
1k 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
46 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 ...
16
votes
18answers
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
808 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 ...
25
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
170 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
16answers
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
327 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
447 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 ...
14
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
477 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
180 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
396 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
369 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
225 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
672 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 ...
22
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
174 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
330 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
367 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
285 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
700 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
478 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 ...
18
votes
9answers
1k views

Proportion of self-avoiding walks on a square lattice

The challenge Given a positive integer N, compute the proportion of N-step walks on a plane that don't intersect themselves. ...
2
votes
1answer
122 views

From text to ascii art from CodinGame practice puzzle

On CodingGame, there is a Puzzle that ask to write words with ascii art. I solve the puzzle then tried to golf it. What improvement can I do on it? ...
12
votes
13answers
2k views

Probabilistically fair prize splitting for two-player coin toss

Introduction Adam (A) and Bubbler (B) are playing coin toss, where the one who wins 5 times first would win the prize of $32. If the game is aborted when the scores are ...
7
votes
4answers
363 views

Dirichlet Convolution Inverse

If \$f,g\colon \mathbb{Z}_{\geq 1} \to \mathbb{R}\$, the Dirichlet convolution of \$f\$ and \$g\$ is defined by \$ \qquad\qquad\qquad \displaystyle (f*g)(n) = \sum_{d|n}f(d)g(n/d).\$ This ...
4
votes
1answer
105 views

Is there a shorter way to express this haskell idiom?

Every so often I have a function of type a -> b and a function of type b -> b -> c and I would like a function of type <...
3
votes
11answers
792 views

Even-Odd chunks

(Inspired by the Keg utility of this challenge) Given a non-empty input string, e.g. s c 1= e(a"E"), split the input into even-odd chunks. Example (Feel free to ...
11
votes
5answers
595 views

Define the finite field GF(9)

\$GF(9)\$ or \$GF(3^2)\$ is the smallest finite field whose order isn't a prime or a power of two. Finite fields of prime order aren't particurlarly interesting and there are already challenges for \$...
1
vote
1answer
88 views

2D Path Drawing [duplicate]

(This is not a duplicate of Follow the path, as this challenge have invalid path detection and use ><^v in the output.) Task So your task is to take in the ...
15
votes
22answers
2k views

Integer Interpretator

The Challenge Given a finite list of integers, split it into the fewest partitions possible such that no partition contains a number more than once. Rules Input can be in any format and any order. ...