Questions tagged [math]
The challenge involves mathematics in some central way. Also consider using more specific tags, listed in the tag wiki info.
1,876 questions
12
votes
10
answers
688
views
Polynomial Basis Conversion
The most common way to represent a polynomial is writing it as a linear combination of monomials, i.e., powers of the variable. For example, the polynomial \$p(x) = x^3 + 2x^2 + x + 1\$ is a linear ...
18
votes
3
answers
966
views
Cancel and minimize game
Here is a game: Start with the set {1,2,3,...,n} of natural numbers. At any turn of the game, you may pick two numbers from this set, a and b, then replace them with their product a*b. Since it is a ...
9
votes
3
answers
309
views
Divide 1 by a sum/difference of square roots
Divide 1 by a sum/difference of square roots
Input: An expression that is a sum/difference of square roots of positive integers. You can assme it will not equal 0.
The general form is \$\pm\sqrt{a_1}\...
13
votes
16
answers
1k
views
Compute the NFL passer rating
Each quarterback in the NFL is given a passer rating at the end of the game, which measures how good their forward passes were. It is not strictly a basic arithmetic formula, and is calculated as ...
12
votes
12
answers
734
views
Recursive cumulative sum [duplicate]
Challenge:
Given inputs \$i\$ and \$n\$, calculate \$R_i(n)\$ where:
$$R_0(n)=n \\
R_i(n)=\sum_{j=0}^nR_{i-1}(j)$$
Note that \$R_1\$ is triangular function, and \$R_2\$ is tetrahedral function.
This ...
5
votes
1
answer
333
views
Implement 2ˣ using the polynomial system
Your job is to implement \$2^x\$ using polynomials, such that in a way that for all integers \$x\$ and \$y\$,
$$\exists(v_0,v_1,\dots)[P_1(x,y,v_0,v_1,v_2,\cdots) = 0 \land P_2(x,y,v_0,v_1,v_2,\cdots)=...
17
votes
6
answers
875
views
Decompose a palindromic polynomial
A palindromic polynomial is a polynomial whose list of coefficients is a palindrome. For example, the polynomial \$p(x) = x^4 + 2x^3 + 3x^2 + 2x + 1\$ is palindromic because its coefficients are \$[1, ...
13
votes
8
answers
1k
views
Float vs Decimal
You will be given a decimal number n in the form of a string. You must determine if that number, when stored in standard number type ...
16
votes
7
answers
1k
views
Solve the crossed ladders problem
I'm surprised we don't have the crossed ladders problem as a task here yet.
Two ladders of lengths a and b lie oppositely across an alley, as shown in the figure. The ladders cross at a height of h ...
15
votes
17
answers
2k
views
IMO 2025: Divisor sums that go forever
Problem 4 of the 2025 International Mathematical Olympiad asked (paraphrased):
Let \$f(n)\$ be the sum of the largest three proper divisors of \$n\$,
that is divisors excluding \$n\$ itself. For ...
14
votes
7
answers
1k
views
Squaring the roots of a polynomial
In this challenge, you are given a polynomial \$p(x)\$, and you need to find a polynomial \$q(x)\$ whose roots are exactly the squares of the roots of \$p(x)\$ (counted with multiplicity). In other ...
1
vote
1
answer
301
views
The Parable of the Dagger Prelude
Taken from lesswrong.com
Once upon a time, there was a court jester who dabbled in logic.
The jester presented the king with two boxes. Upon the first box was
inscribed:
"Either this box ...
24
votes
6
answers
3k
views
Computing Pi with iF*ck
Objective
Compute \$\pi\$ using nothing but \$i\$ (\$\sqrt{-1}\$).
Guidelines
ONLY exponentiation and multiplication may be used (i.e. \$i^i\$ or \$ii\$)
No additional symbols may be used (so no ...
5
votes
10
answers
1k
views
Genshin Elemental Aura Decay
There is this game Genshin Impact, when an element is applied to an enemy i.e. Electro it remains for some time causing decay to the enemy health. For this challenge, we'll simplify this to a single ...
10
votes
2
answers
702
views
Intersection check in the fewest operations
Challenge
Given two line segments, your goal is to write a function which determines if they intersect using only the operations given below:
Multiplication: x*y
...
6
votes
17
answers
1k
views
555 Timer Calculator
The Challenge
In honour of getting 555 Rep, here's a little challenge to work out the frequency of a 555 Timer. The frequency can be worked out using
$$ f=\frac{1.44}{(R_1+2R_2)C_1} $$
Implement this ...
-4
votes
12
answers
355
views
Power Grid Management
You are writing the management software for one "node" of a power grid. A node has a layout like this
+
|
+---N---+
|
+
Each + is a ...
4
votes
8
answers
932
views
How many distinct characters can be used to implement Boolean Algebra in your programming language [closed]
I am interested in the following problem:
What is the minimum number of distinct characters used in any programming language that can implement Boolean Algebra?
In particular, what is the set that ...
9
votes
4
answers
507
views
Ultra-modular representative of rational numbers
Objective
Given a reduced fraction \$p/q\$ where \$q > 0\$, output the (unique) reduced fraction \$p'/q'\$ such that:
\$p'\$ is nonnegative and less than \$q'\$, and
\$q'\$ is a positive odd ...
-10
votes
2
answers
289
views
Fizz-Buzz-Bazz-Pazz
Fizz-Buzz-Bazz-Pazz
Problem Summary
Write a program that prints numbers from 1 to 100 with replacements based on the following ...
-3
votes
5
answers
306
views
Shortest Inverse Square Root [duplicate]
Alex ([email protected]) So... uh, thanks for covering me last time. Look, we've had a pretty odd order from a client, but they're willing to pay a TON to ...
11
votes
5
answers
849
views
Show order equivalence between the rationals and the binary fractions
Write a function \$f\$ which takes rational numbers and gives binary fractions (rational numbers whose denominator is a power of two) which is bijective and preserves order.
That means:
Different ...
16
votes
17
answers
3k
views
Noise Cancelling Headphones
Alex ([email protected]) Hey champ, we've just had a huge order for those new noise-cancelling headphones we're meant to be making. Unfooooorrttunately... ...
9
votes
1
answer
371
views
Ruler-and-compass constructions
In this code-golf challenge, you will work with a construction that was used by the ancient Greeks: the straightedge-and-compass construction. In particular, you will count how many different ...
3
votes
1
answer
302
views
Count number of families of sets satisfying a list of criteria
CHALLENGE
This problem has a math background.
For n=1,2,3,4 we want to count the number of families of sets with maximum n elements that satisfy many criteria of the form:
$$\bigoplus_{k\in A,A\in \...
9
votes
4
answers
257
views
Inequality region vertices with 4 equations
Given the following inequalities:
$$
\begin{align}
ax+by&\leq c\\
dx+ey&\leq f\\
gx+hy&\leq i\\
jx+ky&\leq l
\end{align}
$$
These inequalities enclose a region in the shape of a convex ...
-6
votes
4
answers
385
views
Find the argmin of the cusum
Input
You will be given an array arr of length 10 of float64s. They will all be between -1 and 1.
Output
You must give the index in the array of the minimum value ...
16
votes
17
answers
1k
views
Counting Gessel walks
OEIS A135404 gives the number of Gessel walks \$g(n)\$ of length \$2n\$. A Gessel walk is
a walk on the square lattice starting and ending at the origin
with possible steps (1,0), (-1,0), (1,1), (-1,-...
14
votes
19
answers
3k
views
Antiparallel 12-hour Clock Hands
Output (or print) each of the 11 times, one per line, in the POSIX %I:%M:%S format, at which the hour and minute hands of a 12-hour clock are antiparallel. Here <...
7
votes
18
answers
2k
views
Compute the infinite Pochhammer symbol
I saw the following problem on MathsSE:
You try to do something and your probability of success is \$p\$. If you fail, you try again, but the probability of success falls down to \$p^2\$. If you fail ...
6
votes
1
answer
587
views
Can you beat numpy convolve?
The task is to compute the convolution of an array with itself as quickly as possible. The array will contain 80-bit extended precision long doubles and I will specify how the array is to be created. ...
12
votes
14
answers
1k
views
Decide Equality of Closed Surfaces
Objective
Given two closed surfaces (a.k.a. closed 2-manifolds), decide whether they're homeomorphic.
Introduction
In lay terms, a closed surface is a finite-sized shape that resembles a flat plane ...
8
votes
18
answers
4k
views
Is this number Ugly?
Related, but not dupe (Asking about the n-th k-smooth number whereas I'm only asking if a certain number is 5-smooth.)Source: Partially inspired by Leetcode's 5-smooth Number problem, but partially ...
9
votes
7
answers
499
views
Malfatti circle radii
Consider a triangle \$ABC\$ whose sides \$BC,CA,AB\$ have lengths \$a,b,c\$ respectively. In this triangle we can construct circles \$G_A,G_B,G_C\$ such that
\$G_A\$ is tangent to \$CA,AB,G_B,G_C\$
\$...
-5
votes
4
answers
204
views
Determine if a rational number is an integer, without division [closed]
Determine if a rational number is also an integer, without any form of dividing. The input should be any pair of numerator and denominator. Don't forget to consider negative numbers, and division by ...
9
votes
9
answers
563
views
Convert to Pascal-ary
Your program must take integers \$S \geq 0\$ and \$n \geq 1\$ as input and output a list of \$n\$ integers \$(a_i)_{i=1}^{i=n}\$ such that \$-1 \leq a_1 \leq a_2 \leq \dotsb \leq a_n\$ and
\$S = \sum_{...
9
votes
15
answers
950
views
Is it in the sequence? (sum of the first n cubes) [duplicate]
According to Nicomachus' Theorem, the sum of the first n cubes is equal to the square of the nth triangular number. See this question for a visualisation.
Your task is to take an integer and determine ...
6
votes
3
answers
648
views
Implement any rotation-invariant function on colored dodecahedrons
Each of a regular dodecahedron's 12 faces can be painted either red or blue. Your task is to implement a function \$f\$ that takes a painted dodecahedron (as 12 booleans, in whatever order and format ...
3
votes
13
answers
1k
views
The "Graphing" Calculator 2... A Higher Power
A sequel to my earlier post, when working with quadratic graphs, you can use Y=MX²+NX+C to calculate the shapes of a quadratic curve... but can you ...
2
votes
11
answers
823
views
Climbing through the mountains on all paths
Narrative
We are standing at the foot of a mountain. To find the best route when climbing the mountain, let's consider all possible routes.
On our route, there is no point lower than our starting ...
11
votes
6
answers
1k
views
Tracing light through a house of mirrors
Suppose you find yourself in a house of mirrors! You stand in the corner, and you trace how your image reflects off of mirror A, followed by mirror B, followed by mirror C, followed by mirror A.
But ...
15
votes
10
answers
2k
views
Walks in Nice (Nizza)
Narrative
Recently, I visited Nice (a French city on the Mediterranean coast) and saw a curious tourist wandering through the city. His walk started at the center of the 'Promenade des Anglais'. He ...
12
votes
6
answers
2k
views
Frogs on lily pads want to make a party
Consider binary strings (reading from left to right) starting with a '1' as ponds of lily pads. A '1' signifies a frog sitting on the lily pad, and a '0' represents an empty lily pad.
Here, we see a ...
7
votes
6
answers
404
views
Walks on a circle
A walk on a circle is a sequence of oriented arcs of equal length on a circle starting and ending at the same point. The endpoint of an arc is always the starting point of the next arc of the walk. ...
12
votes
10
answers
2k
views
Girls and boys parades
Donald Knuth describes the setup:
"There are \$n\$ girls \${g_1, ..., g_n}\$ and \$k\$ boys \${b_1, ..., b_k}\$,
where \$g_i\$ is younger than \$g_{i+1}\$ and \$b_j\$ is younger than
\$b_{j+1}\$, ...
17
votes
10
answers
2k
views
The smallest number with a given water capacity
This is the outline of this challenge: Every number greater than or equal to two has a prime factorization. A prime factorization can be represented as a bar graph. Every bar graph has a water ...
11
votes
7
answers
2k
views
Perfect ruler search
Definitions:
A sparse ruler, or simply a ruler, is a strict increasing finite sequence of nonnegative integers starting from 0, called marks.
A ruler is complete if the set of all distances it can ...
4
votes
4
answers
639
views
Fill in matrices for matrix bit flipping as quickly as possible
Consider an n by n binary matrix. If it has rank r <= n, then we want to compute the largest number bits flips necessary to reduce its rank to a specific value. All computations should be done ...
14
votes
7
answers
937
views
Implement any 10-ary truth function with cyclic symmetry
Implement a function \$f\$ that takes 10 boolean inputs and returns a boolean.
The only requirement on \$f\$ is that it satisfies the identity
$$
f(x_1,x_2,x_3,x_4,x_5,x_6,x_7,x_8,x_9,x_{10})=f(x_2,...
7
votes
8
answers
425
views
Padé approximant of \$\exp(x)\$
In mathematics, a Padé approximant (Wikipedia, MathWorld) is the "best" approximation of a function by a rational function. For a function \$f(x)\$, the Padé approximant of order \$[m/n]\$ ...