Questions tagged [code-golf]
Code-golf is a competition to solve a particular problem in the fewest bytes of source code.
11,757
questions
7
votes
5
answers
477
views
Multiply multivariate polynomials
We already have a challenge about multiplying multiply single-variable polynomials. This challenge is about multiply two polynomials with multiple variables
Your task is given two multi-variable ...
11
votes
10
answers
401
views
Stevin's Notation
Stevin's Notation is a way to represent decimals in a non-fractional way.
The Flemish mathematician and engineer Simon Stevin is
remembered for his study of decimal fractions. Although he was not the
...
1
vote
0
answers
58
views
How Many Staircases [duplicate]
Problem
You're a staircase engineer on a house and realize you only have n rectangles to create a staircase. So you are tasked with finding the number of ways to ...
10
votes
5
answers
1k
views
Decode Chess Move
As the title says, given a valid chess move in algebraic notation, produce the string describing the move.
Example:
...
11
votes
16
answers
1k
views
The rectangle spanned by two numbers
One way to generalize the concept of a range from the integers to the Gaussian integers (complex numbers with integer real and imaginary part) is taking all numbers contained in the rectangle enclosed ...
9
votes
11
answers
721
views
Otteretto Classic game scoring method
Brief description of the game
In the game Otteretto Classic (which you can test directly in your browser; try it!) the player has to form palindromic sequences using adjacent cells on a square grid. ...
8
votes
18
answers
1k
views
Piecing Paired Primes
Problem
You've stumbled upon a paradoxical mathematical phenomenon related to prime numbers. Consider the following scenario:
You have an infinite list of prime numbers: $$2, 3, 5, 7, 11, 13, 17, 19, ....
6
votes
4
answers
487
views
Walk by walls in a room
Challenge
You just entered a room. Here's how it looks (you are the X):
|\ /|
| \/ |
| X |
| |
|----|
You challenge yourself to see if you can reach where you ...
15
votes
18
answers
2k
views
First odd then even indices
Your task is to find out how often you need to "shuffle" a given list with the following operation until you get back the original list.
...
13
votes
9
answers
3k
views
Give the fool's Fibonacci sequence
Recently I asked for tips on improving some code-golf of mine. The code was supposed to output every third value of the Fibonacci sequence starting with 2:
...
14
votes
10
answers
3k
views
When in {country}, do as the {countrians} do
(or: Output the plural demonym.)
When in Rome, do as the Romans do. This is a well-known English phrase meaning that it’s best to follow what others are doing around you — to go with the flow. Today, ...
12
votes
18
answers
1k
views
Print a meter of numbers to a specified limit
Given a positive integer n, output a number meter formatted like this:
...
1
vote
1
answer
162
views
Shorten this recursive even fibonacci implementation [closed]
I have the following Haskell code to generate the the values of the Fibonacci sequence which are even as an infinite list:
...
15
votes
16
answers
831
views
Output the smallest increasing sequence where each term is coprime to preceding 3 terms
This sequence is defined as
Starts with 1, 2, 3
The next element of the sequence is the first number greater than the previous three that is co-prime with each of the previous 3 elements in the ...
11
votes
4
answers
1k
views
Optimal Duck Game Moves
How to play the duck game
This is a 2-player game.
First, we start with a line of blue rubber ducks (represented here as circles):
🔵🔵🔵🔵🔵🔵🔵
Now, in each ...
6
votes
8
answers
846
views
Iterate over strings II
This is a successor to a previous challenge.
Input
An integer \$1 \leq n \leq 5\$.
Task
Your code should produce all strings that satisfy the following properties:
Your string should contain exactly ...
16
votes
17
answers
1k
views
Count N-Rich Permutations of an Integer Sequence
Given a sequence of integers with length \$L\$ and an integer \$1 \le N \le L\$, an "\$N\$-rich" permutation is one whose the longest strictly increasing contiguous subsequence has length ...
8
votes
3
answers
625
views
Compressed UTF-8
In the UTF-8 encoding bytes of the Form 10****** can only appear within multi-byte sequences, with the length of the sequence already being determined by the first ...
16
votes
11
answers
1k
views
Iterate over all non-equivalent strings
Input
A single positive integer \$ 10 \geq n \geq 2\$
Output
A list of strings, each of length \$2n\$, satisfying the following properties.
Each string will contain each of the first \$n\$ lowercase ...
14
votes
12
answers
1k
views
Shift Braille down
Braille Patterns in Unicode contains 8 dots(⣿) and occupy area U+2800-U+28FF. Given a Braille Pattern character, where the bottom two dots are not used(aka. U+2800-...
20
votes
9
answers
2k
views
Cutting a Circular Pizza Vertically
Most people would cut circular pizzas into circular sectors to divide them up evenly, but it's also possible to divide them evenly by cutting them vertically like so, where each piece has the same ...
11
votes
34
answers
2k
views
Convert binary to unary
The title says it all; Given a number in the binary (base-2) number system, output the same number expressed in unary (base-1).
You should take the binary number as a string (optionally with a ...
16
votes
15
answers
1k
views
Find separating sets
Two points pand q in a topological space can be separated if there are open sets U and ...
20
votes
16
answers
1k
views
Evenly spread values
Given a sorted list of unique positive floats (none of which are integers) such as:
[0.1, 0.2, 1.4, 2.3, 2.4, 2.5, 3.2]
Evenly spread out the values that fall ...
11
votes
4
answers
350
views
Generate the vertices of a geodesic sphere
As in this challenge, the task is to generate the vertices of a polyhedron. The polyhedron here is the one obtained by dividing a regular icosahedron's triangular faces into smaller triangles so that ...
8
votes
11
answers
2k
views
Reverse engineer colors for a layout
This challenge was originally posted on codidact.
At my job we have to sometimes lay out materials. Materials come in large long rolls and are cut into smaller pieces when being laid out.
When we ...
19
votes
14
answers
2k
views
Rook Polynomials
In combinatorics, the rook polynomial \$R_{m,n}(x)\$ of a \$m \times n\$ chessboard is the generating function for the numbers of arrangements of non-attacking rooks. To be precise:
$$R_{m,n}(x) = \...
16
votes
6
answers
3k
views
Is it a valid Go type?
Write the shortest program or function that will determine if an input is a valid Go type.
Spec
This challenge will use the following simplified subset of Go types. For more information, see the ...
8
votes
11
answers
679
views
Buzzing Bill's Newspaper: Four Letter Splits
"Buzzing" Bill is a well respected beaver. He is the hardest working in his home dam. He was a strong beaver and was able to lift more logs than anyone at the dam. Unfortunately Buzzing Bill'...
14
votes
11
answers
2k
views
Round up to a smoother number
Input
Two positive integers a > b
Output
The smallest integer c >= a so that c can be ...
8
votes
14
answers
1k
views
Calculate the aspect ratio of the Nepal flag
Above is the picture of the flag of the country Nepal. Pretty cool.
What's cooler, is the aspect ratio, which is defined under the constitution as:
That formula in copyable form:
$$ 1 : \frac{...
8
votes
8
answers
388
views
Near miss prime multiples
This challenge was originally posted on codidact.
Given a number \$n \geq 3\$ as input output the smallest number \$k\$ such that the modular residues of \$k\$ by the first \$n\$ primes is exactly \$\...
19
votes
17
answers
1k
views
Compute the convolution of two strings
While implementing polynomial multiplication in Itr I found the following interesting operation on strings
To compute the convolution of two strings (for instance ...
17
votes
13
answers
1k
views
Efficient censorship
This challenge was originally posted on codidact.
You are a low-level censor working for the Ministry of Media Accuracy. Part of your job is to make sure that certain words don't appear in ...
11
votes
12
answers
1k
views
The all-high powerful numbers
We've had powerful numbers, yes, but what about highly powerful numbers?
Highly powerful numbers
Let \$n\$ be a positive integer in the form
$$n = p_1^{e_{p_1}(n)}p_2^{e_{p_2}(n)}\cdots p_k^{e_{p_k}(n)...
26
votes
17
answers
4k
views
s-n-a-k-e-a-r-o-u-n-d--->
This code-golf challenge is about walking around a string like a snake.
s-n-a-k
.---. e
d <-' a
n-u-o-r
You will be given a string \$ S \$ of length \$ l \$ and ...
20
votes
5
answers
1k
views
Repeating occupied pattern in Hilbert's hotel
Imagine a countable infinite amount of empty rooms. When an infinite amount of guests come, they occupy the 1st, 3rd, 5th...(all odd) empty rooms. Therefore there's always an infinite amount of empty ...
21
votes
18
answers
2k
views
Is this set laminar?
A family of sets is called laminar if for any two sets \$A\$ and \$B\$ in the family one of the following is true:
\$ A \subseteq B \$
\$ A \supseteq B \$
\$ A \cap B = \emptyset \$
Or less ...
15
votes
14
answers
2k
views
How many trailing zeros in the hyperfactorial?
We have a challenge to calculate the hyperfactorial and one to count the trailing zeros of the factorial, so it seems logical to put them together and count the trailing zeros in the hyperfactorial.
...
19
votes
13
answers
1k
views
Calculating Transitive Closure
First attempt at a question.
Calculating Transitive Closure
According to Wikipedia, "the transitive closure \$R^*\$ of a homogeneous binary relation \$R\$ on a set \$X\$ is the smallest ...
7
votes
19
answers
2k
views
Number of bits needed to represent the product of the first primes
Input
An integer \$n\$ greater than or equal to 1.
Output
The number of bits in the binary representation of the integer that is the product of the first \$n\$ primes.
Example
The product of the first ...
9
votes
5
answers
779
views
Compute the logarithm of a matrix
There have already been challenges about computing the exponential of a matrix , as well as computing the natural logarithm
of a number. This challenge is about finding the (natural) logarithm of ...
13
votes
15
answers
2k
views
Can you perform swaps?
Today's problem is easy. You're given two strings A and B of equal length consisting of only the characters ( and ). Check ...
7
votes
6
answers
540
views
Print Bing's sentience
Generative AI is here! It's great for certain things, but it has a few problems. Not only has it broken our Stack Exchange community, it also makes mistakes. For example, when you ask Bing AI if it is ...
15
votes
7
answers
1k
views
Solve quadratic equations when 1+1=0
There already have been multiple challenges about carryless
multiplication, this challenge will work with the same calculation rules.
You task is given a quadratic polynomial ...
17
votes
25
answers
3k
views
Is this a powerful number?
A powerful number is a positive integer \$n\$ such that for every prime \$p\$ that divides \$n\$, \$p^2\$ also divides \$n\$. Or equivalently, \$n\$ is powerful if and only if it can be written in the ...
20
votes
13
answers
3k
views
Chinese color mixing
Objective
Given two Chinese ideographs meaning basic colors, output the ideograph that means the color resulting from mixing them.
Basic colors
The basic colors are:
靑(U+9751; blue)
赤(U+8D64; red)
黃(...
17
votes
22
answers
2k
views
Compute this fractal matrix
The unique-disjointness matrix ( UDISJ(n) ) is a matrix on all pairs of subsets of {1...,n} with entries $$ U_{(A,B)}=\begin{cases}
0, ~ if ~ |A\cap B|=1\\
1, ~ ...
32
votes
34
answers
2k
views
Make a k-skip-j range
On the Mathematica Stack Exchange, 100xln2 asks:
I need a list of integers […] The list contains integers and is characterized by [three] parameters, lets call them k and j [and listmax], which ...
17
votes
23
answers
3k
views
Meta-cat program
Write a program or function that takes input and outputs/returns a full program (in the same language) that outputs said input.
Note that the input may contain any printable ASCII character or newline ...