Questions tagged [math]
The challenge involves mathematics in some central way. Also consider using more specific tags, listed in the tag wiki info.
607
questions
21
votes
34
answers
3k
views
Calculate Standard Deviation
Challenge
Given a list of numbers, calculate the population standard deviation of the list.
Use the following equation to calculate population standard deviation:
Input
The input will a list of ...
21
votes
22
answers
2k
views
Sum the diagonals
Take a matrix of positive integers as input, and output the individual sums of the elements on the diagonal lines through the matrix.
You shall only count the lines that goes diagonally down and to ...
21
votes
9
answers
5k
views
Implement Rijndael's S-box
Rijndael's S-box is a frequently used operation in AES encryption and decryption. It is typically implemented as a 256-byte lookup table. That's fast, but means you need to enumerate a 256-byte ...
21
votes
12
answers
3k
views
Calculate Landau's function
Landau's function \$g(n)\$ (OEIS A000793) gives the maximum order of an element of the symmetric group \$S_n\$. Here, the order of a permutation \$\pi\$ is the smallest positive integer \$k\$ such ...
21
votes
16
answers
2k
views
Verify Eigenpairs
In this challenge, you will be given a square matrix A, a vector v, and a scalar λ. You will ...
21
votes
18
answers
5k
views
Convince me Gabriel's Horn is possible
From Wikipedia, Gabriel's Horn is a particular geometric figure that has infinite surface area but finite volume. I discovered this definition in this Vsauce's video (starting at 0:22) where I took ...
21
votes
5
answers
688
views
Thar she blows!
Arrr... Ahoy there, me maties! Unfurl tha' mainsail! Full to starboard! Ah, feel th' wind in yer hair!
Right, me hearties... I be needin' a bit of yer codin' skills! Me crew are a li'l more ...
20
votes
14
answers
1k
views
Output N in base -10
Challenge:
In the programming language of your choice, accept an integer as input in base 10, and output it in the negadecimal notation, which is also known as base -10
Example algorithm:
This is ...
20
votes
2
answers
816
views
Lean golf: Pascal vs. Fibonacci
The Pascal's triangle and the Fibonacci sequence have an interesting connection:
Source: Math is Fun - Pascal's triangle
Your job is to prove this property in Lean theorem prover (Lean 3 + mathlib). ...
20
votes
21
answers
3k
views
Implement the Torian
The Torian, \$x!x\$, of a non-negative integer \$x\$ can be recursively defined as
$$
x!0 = x \\
x!n = \prod^x_{i=1} i!(n-1) = 1!(n-1) \times 2!(n-1) \times \cdots \times x!(n-1)
$$
The Torian is then ...
20
votes
11
answers
2k
views
What's next, Achilles?
Powerful numbers are positive integers such that, when expressed as a prime factorisation:
$$a = p_1^{e_1} \times p_2^{e_2} \times p_3^{e_3} \cdots \times p_k^{e_k}$$
all exponents \$e_1, e_2, ...\$ ...
20
votes
4
answers
529
views
Locally invert a Polynomial
Challenge
Given a polynomial \$p\$ with real coefficients of order \$1\$ and degree \$n\$, find another polynomial \$q\$ of degree at most \$n\$ such that \$(p∘q)(X) = p(q(X)) \equiv X \mod X^{n+1}\$, ...
19
votes
26
answers
2k
views
Triangle Area Side Side Side [closed]
Given three sides of a triangle, print area of this triangle.
Test cases:
In: 2,3,4
Out: 2.90473750965556
In: ...
19
votes
16
answers
1k
views
(RGS 4/5) Inverting matrices modulo m
Task
Given an integer matrix M and a modulus m, find an inverse of M modulo ...
19
votes
39
answers
2k
views
Print the tetration
Tetration, represented as \${}^ba\$, is repeated exponentiation. For example, \${}^32\$ is \$2^{2^2}\$, which is \$16\$.
Given two numbers \$a\$ and \$b\$, print \${}^ba\$.
Test cases
...
19
votes
6
answers
995
views
Kolakoski-like self-referencing sequences
This is how the Kolakoski sequence (OEIS A000002) is defined:
The Kolakoski sequence is a sequence that contains 1 and 2, and ...
19
votes
18
answers
2k
views
Hypercube elements
Write a function or program that outputs the number of each type of element (vertex, edge, face, etc.) of an N-dimensional hypercube.
As an example, the 3 dimensional cube has 1 cell (i.e. 1 3-...
18
votes
4
answers
2k
views
Laver table computations and an algorithm that is not known to terminate in ZFC
The Laver tables provide examples of programs which have not been shown to terminate in the standard axiomatic system of mathematics ZFC but which do terminate when one assumes very large cardinal ...
18
votes
22
answers
1k
views
Output diagonal positions of me squared
Given a number n, Output an ordered list of 1-based indices falling on either of the diagonals of an n*n square matrix.
...
18
votes
11
answers
2k
views
Find numbers within the Copeland–Erdős constant
Background
The Copeland–Erdős constant is the concatenation of "0." with the base 10 representations of the prime numbers in order. Its value is
...
18
votes
8
answers
649
views
Convert between balanced bases!
Balanced bases:
Balanced bases are essentially the same as normal bases, except that digits can be positive or negative, while in normal bases digits can only be positive.
From here on, balanced ...
18
votes
9
answers
1k
views
How long does it take to paint a stick?
(Based on this Math.SE problem, which also provides some graphics)
I have a stick which looks kinda like this:
I want it to look kinda like this:
I'm not an expert painter, however, so before I ...
18
votes
5
answers
1k
views
Jordan Decomposition
Important note: Because this challenge only applies to square matrices, any time I use the term "matrix", it is assumed that I am referring to a square matrix. I am leaving off the "...
17
votes
27
answers
555
views
\$n\$-perfect numbers
A positive integer \$x\$ is an \$n\$-perfect number if \$\sigma(x) = nx\$, where \$\sigma(x)\$ is the divisor sum function. For example, \$120\$ is a \$3\$-perfect number because its divisors sum to \$...
17
votes
23
answers
2k
views
Enumerate Derangements
Given some positive integer \$n\$ generate all derangements of \$n\$ objects.
Details
A derangement is a permutation with no fixed point. (This means in every derangement number \$i\$ cannot be in ...
17
votes
12
answers
2k
views
Strict partitions of a positive integer
OEIS A000009 counts the number of strict partitions of the integers. A strict partition of a nonnegative integer n is a set of positive integers (so no repetition ...
17
votes
10
answers
538
views
Ascending matrix
The "ascending matrix" is an infinite matrix of whole numbers (0 included) in which any element is the smallest available element which has not been previously used on the respective row and column:
<...
16
votes
3
answers
375
views
Solving less-than inequalities with positive integers
Write a program or function that takes in a nonempty list of mathematical inequalities that use the less than operator (<). Each line in the list will have the ...
16
votes
6
answers
1k
views
Simulate any 1D cellular automaton
The Challenge
You are to write a complete program that takes seven numbers from STDIN, and prints the two dimensional history of the cellular automaton (CA) to STDOUT. This is code golf.
Input ...
16
votes
4
answers
1k
views
An optimization challenge with strange coins
You have n coins which each weigh either -1 or 1. Each is labelled from 0 to n-1 so you can ...
16
votes
16
answers
3k
views
Test if given number is a Keith number
Since Fibonacci numbers and sequences seems like a popular subject for code golf I thought that it might be a fun challenge to code golf with Keith numbers.
So I propose a challenge that is to create ...
16
votes
47
answers
2k
views
Alternating Sign Sequence
Introduction
The sign of a number is either a +, or a - for every non-zero integer. Zero itself is signless (...
15
votes
36
answers
4k
views
Generate Sexy Primes
Sexy Primes are pairs of numbers \$(n, n+6)\$ such as \$n\$ and \$n+6\$ are both prime
You need to create a function which will take an integer, check for sexy primes from 0 to that integer, and ...
15
votes
5
answers
568
views
Visualize a Difference Pyramid
A difference pyramid is a pyramid where each new diagonal is the absolute value of the differences between the elements of the last diagonal. For example, if we start with the array
...
15
votes
7
answers
3k
views
Draw the Sierpinski Arrowhead Curve
Introduction
The Sierpinski Arrowhead Curve is a curve that's limit is Sierpinski's Triangle.
It first starts like this:
_
/ \
Then, each line is replaced with a ...
15
votes
15
answers
1k
views
Fun With Permutations
Who doesn't absolutely love permutations, right? I know, they are amazing––so much fun!
Well, why not take this fun and make it funner?
Here's the challenge:
Given an input in the exact form: ...
15
votes
14
answers
3k
views
Compute the first N digits of e
Challenge
Write a program to compute the the first N (<= 10^3) digits of e.
Your program should take an integer N as input.
Input:
100
Output:
...
15
votes
4
answers
428
views
Counting Abelian groups of a given size
Background
Last time, we counted groups of a given size, which is a non-trivial problem.
This time, we'll only count Abelian groups, i.e., groups with a commutative operation. Formally, a group (G, ∗) ...
14
votes
15
answers
1k
views
Dihedral group D4 composition with custom labels
The dihedral group \$D_4\$ is the symmetry group of the square, that is the moves that transform a square to itself via rotations and reflections. It consists of 8 elements: rotations by 0, 90, 180, ...
14
votes
7
answers
950
views
Molar masses of compounds
Task
Write a program that takes in a compound made solely of elements with an atomic number less than or equal to 92 (Uranium), and outputs the molar mass of the compound in ...
14
votes
37
answers
3k
views
N numbers closest to zero staying balanced
Objective: Given a positive integer n:
If n is odd, output the list of n numbers closest to ...
14
votes
10
answers
2k
views
Find a fraction's position in the Stern-Brocot tree
The Stern-Brocot tree is a binary tree of fractions where each fraction is acquired by adding the numerators and denominators of the two fractions neighbouring it in the levels above.
It is generated ...
14
votes
12
answers
7k
views
3 and 5 Litre Jug Puzzle
You may have seen this one in Die Hard: With a Vengeance... This question is based on the famous 3 and 5 Litre Jug Puzzle, but with a slightly different slant.
Golf up some code that when given an ...
13
votes
6
answers
712
views
Ellipsoid surface area
Related: Ellipse circumference
Introduction
An ellipsoid (Wikipedia / MathWorld) is a 3D object analogous to an ellipse on 2D. Its shape is defined by three principal semi-axes \$a,b,c\$:
$$ \frac{x^2}...
13
votes
4
answers
1k
views
How NOT to reduce fractions
Reducing fractions the wrong way
In this code-golf challenge you have to find fractions that can be reduced the wrong way but still end up in the same number.
Note: reducing fractions the wrong way ...
13
votes
9
answers
2k
views
Calculate the Kronecker Product
Related, but very different.
In the examples below, \$A\$ and \$B\$ will be \$2\times2\$ matrices, and the matrices are one-indexed.
A Kronecker product has the following properties:
...
13
votes
3
answers
992
views
Implement a Graphing Calculator
There have been many questions involving calculators; however, it does not appear that any involve implementing a graphing calculator.
The Challenge
You are to write a complete program that takes ...
12
votes
18
answers
1k
views
Polynomial Laplace transform
This is a repost of this challenge, intended to revamp it for looser I/O formats and updated rules
You are to write a program which takes an integer polynomial in \$t\$ as input and outputs the ...
12
votes
7
answers
4k
views
Shortest Program to Solve a Quartic Equation
Write the shortest program to solve a quartic equation.
A quartic equation is a polynomial equation of the form:
\$ax^4 + bx^3 + cx^2 + dx + e=0\$
A solution for \$x\$ is a number such that the above ...
12
votes
6
answers
622
views
Implement Multiplicative Fuzzy Logic
Inspired by this excellent challenge (from which the bulk of this text is blatantly duct-taped) – and my highschool philosophy project...
I define the following operators:
Fuzzy Conjunction a ×F b is ...