Questions tagged [math]
The challenge involves mathematics in some central way. Also consider using more specific tags, listed in the tag wiki info.
1,755
questions
5
votes
1
answer
489
views
Generate all possible equations with 10 characters
Nerdle is a Wordle variant, in which instead of words, the answers are equations. Each equation entered in the game must be a valid one.
Examples: 13³-1=2196, ...
5
votes
2
answers
241
views
Canonical form of a cubic Bézier curve
On Pomax's Primer on Bézier Curves this "fairly funky image" appears:
This is related to the fact that every cubic Bézier curve can be put in a "canonical form" by an affine ...
4
votes
1
answer
187
views
4D rotation matrix to quaternions
It is well-known that a 3D rotation can always be represented by a quaternion. It is less well-known that a 4D rotation can always be represented by two quaternions, sending a point \$p=(a,b,c,d)^T\$ ...
12
votes
6
answers
608
views
Number Clusters
Your task is to create a program or function, that when given an input list of nonnegative integers of length \$l \ge 2\$ and a nonnegative integer \$c\$ where \$2 \le c \le l\$, group the list into \$...
9
votes
5
answers
452
views
3D rotation matrix to quaternion
There are multiple ways to represent a 3D rotation. The most intuitive way is the rotation matrix –
$$A=\begin{bmatrix}A_{11}&A_{12}&A_{13}\\A_{21}&A_{22}&A_{23}\\A_{31}&A_{32}&...
20
votes
9
answers
1k
views
Split some points
proposed by @Adám in chat
Given an even number of finite points return a line \$y=mx+b\$ that evenly splits the points on both sides.
Specs
Take a list of distinct points \$(x,y)\$ (or a list of x-...
5
votes
2
answers
868
views
How spherical is my ellipsoid?
Define the (unnormalised) Willmore energy of a surface as the integral of squared mean curvature over it:
$$W=\int_SH^2\,dA$$
For surfaces topologically equivalent to a sphere \$W\ge4\pi\$, and \$W=4\...
15
votes
9
answers
1k
views
Ptolemy's table of chords
Ptolemy's Almagest contains a table of chords that effectively served as the world's only comprehensive trigonometric table for over a millennium. In modern form it looks like this:
\begin{array}{|l|...
8
votes
14
answers
693
views
Time to shortest permutation
Yesterday, as part of a IQ-style test, I got this interesting question:
The time on a 24-hour clock is 11:43. What is the least number of minutes I should wait before the same digits are on the ...
22
votes
27
answers
3k
views
Sum of Consecutive Squares
Your task
Given a integer input, \$ n \$ (such that \$ n > 1 \$), decide whether it can be written as the sum of (at least 2) consecutive square numbers.
Test cases
Truthy:
...
8
votes
17
answers
2k
views
Capture the Flag... with a twist
Inspired by a challenge from the OUCC 2022 Seniors competition.
Background
Two teams are playing "capture the flag". They take turns invading each other's base and capturing their opposing ...
18
votes
4
answers
657
views
Intersection area of two rotated rectangles
Given two rectangles, which are possibly not in the orthogonal direction, find the area of their intersection.
Input
You may take the rectangles as input in one of the following ways:
The ...
13
votes
10
answers
2k
views
Round to nicer numbers
The standard way to round numbers is to choose the nearest whole value, if the initial value is exactly halfway between two values, i.e. there is a tie, then you choose the larger one.
However where I ...
12
votes
10
answers
893
views
Maximum of outer product of integer vectors (in linear time)
Introduction
Our goal is to efficiently find the maximum of a large amount of (redundant) data.
We define the outer product of vectors \$A\$ and \$B\$ as a matrix containing the products of all ...
9
votes
4
answers
582
views
RADD decomposition of an integer
Introduction
The \$RADD(n)\$ operation is defined as the sum of \$n + [\$ the number whose decimal representation are the decimal digits of \$n\$ in reverse order \$]\$, see A004086. After reversal, ...
5
votes
7
answers
1k
views
Implement the Riemann R function
The Riemann R function is as follows:
$$R (x)=\sum _{n=1}^{\infty } \frac{\mu (n) \text{li}\left(x^{1/n}\right)}{n}.$$
This uses the Möbius function as well as the logarithmic integral.
From Wikipedia,...
11
votes
17
answers
429
views
Normal Subgroups of \$S_4\$
Objective
Given a permutation of 4 distinct items, classify the permutation by the normal subgroup(s) it belongs.
Input/Output Format
You gotta choose the followings as the hyperparameters for your ...
13
votes
8
answers
1k
views
Calculate my income tax
Background
Here in the UK1, these are the income tax rules:
You get a personal allowance (untaxed) of up to £12,570:
If you earn less than £100,000, you get the full £12,570 as personal allowance
...
34
votes
57
answers
4k
views
Sum every second digit in a number
I have a number like this:
n = 548915381
The output should be the sum of every second digit of that number. In this case 26:
...
20
votes
4
answers
2k
views
Write a number as a sum of Fibonacci numbers
In 2009, Hannah Alpert described the "far-difference" representation, a novel way of representing integers as sums and differences of Fibonacci numbers according to the following rules:
...
13
votes
25
answers
2k
views
Output the length of (the length plus a message) [duplicate]
The task is simple. You're given an arbitrary string message. Return that message prefixed with a number, such that the length of that number plus the message equals the number. In other words, the ...
10
votes
10
answers
454
views
CGAC2022 Day 3: \$n\$-dimensional Chocolate Pyramid
Part of Code Golf Advent Calendar 2022 event. See the linked meta post for details.
I've got an infinite supply of \$n\$-dimensional chocolate for some positive integer \$n\$. The shape of the ...
23
votes
19
answers
2k
views
CGAC2022 Day 1: Let's build a chocolate pyramid!
Following last year's event, we're doing Code Golf Advent Calendar 2022!
On each day from today (Dec 1) until Christmas (Dec 25), a Christmas-themed challenge will be posted, just like an Advent ...
5
votes
2
answers
209
views
Transform a lattice polygon to minimum diameter by shearing
Given is a grid polygon by the list of its integer vertex coordinates arranged along the perimeter, in the form
\$(x_1,y_1), (x_2,y_2), \cdots , (x_n,y_n)\$ with \$n \ge 3\$.
The polygon is completed ...
16
votes
5
answers
497
views
Perfect Nontransitive Sets
Background
For the purposes of this challenge, we'll define a "perfect nontransitive set" to be a set \$A\$ with some irreflexive, antisymmetric relation \$<\$, such that for all \$a \in ...
25
votes
48
answers
2k
views
Maximum average ord
Your task
Take a list of strings as the input, and output the maximum average ord.
Example
Given the list ...
20
votes
10
answers
892
views
Counting Stripey Bracelets
A bracelet consists of a number, \$\mathit{N}\$, of beads connected in a loop. Each bead may be any of \$\mathit{C}\$ colours. Bracelets are invariant under rotation (shifting beads around the loop) ...
23
votes
29
answers
2k
views
Power sequence differences
Your task
Given two positive integers \$x\$ and \$d\$ (such that \$d<x\$), output the 5th term of the \$d\$th difference of the sequence \$n^x\$
Example
Let's say we are given the inputs \$x=4\$ ...
19
votes
29
answers
2k
views
Length of Binary as Base 10 [OEIS A242347]
Computers like binary. Humans like base 10. Assuming users are humans, why not find the best of both worlds?
Your task is to find the first n terms in the sequence ...
16
votes
15
answers
2k
views
Generate the n'th Fermi-Dirac Prime
A Fermi-Dirac Prime is a prime power of the form \$p^{2^k}\$, where \$p\$ is prime and \$k \geq 0\$, or in other words, a prime to the power of an integer power of two. They are listed as integer ...
15
votes
16
answers
1k
views
Minimum rotation to get the maximum value
I recently solved a coding challenge in one of the challenge papers that my IT teacher gave to us. It was a seemingly simple, but fun challenge, so I thought it will make fun golfing.
The task
Given ...
16
votes
12
answers
1k
views
Triangular honeycomb numbers
From the infinite triangular array of positive integers, suppose we repeatedly select all numbers at Euclidean distance of \$\sqrt{3}\$, starting from 1:
$$
\underline{1} \\
\;2\; \quad \;3\; \\
\;4\; ...
24
votes
22
answers
2k
views
Triangular polkadot numbers
From the infinite triangular array of positive integers, suppose we select every 2nd numbers on every 2nd row as shown below:
$$
\underline{1} \\
\;2\; \quad \;3\; \\
\;\underline{4}\; \quad \;5\; \...
18
votes
16
answers
1k
views
Multiplicity of a root of a polynomial
Let \$p(x)\$ be a polynomial. We say \$a\$ is a root of multiplicity \$k\$ of \$p(x)\$, if there is another polynomial \$s(x)\$ such that \$p(x)=s(x)(x-a)^k\$ and \$s(a)\ne0\$.
For example, the ...
12
votes
20
answers
2k
views
Prime number checksum
Given a message, append checksum digits using prime numbers as weights.
A checksum digit is used as an error-detection method.
Take, for instance, the error-detection method of the EAN-13 code:
The ...
6
votes
2
answers
373
views
Partial Fractions
Given an input of a string, output the partial fraction in string form.
The partial fraction decomposition of a rational fraction of the form \$\frac{f(x)}{g(x)}\$, where \$f\$ and \$g\$ are ...
17
votes
15
answers
2k
views
A decimal-based unit of time
Background
In 1960, the 11th General Conference on Weights and Measures defined the Système International d'Unités (SI) Units which scientists still use today.
The metre and the kilogram became ...
5
votes
12
answers
597
views
It's Just Rocket Science, Part 2 - Centrifuge
You've gotten out of Earth's gravity well - good for you! However, you're feeling a bit uncomfortable in zero-gravity, and you want to replicate 1 \$g\$ of force in a centrifuge. Use the equation for ...
15
votes
10
answers
1k
views
Count Futoshiki row solutions
Futoshiki is a logic puzzle where an \$n×n\$ Latin square must be completed based on given numbers and inequalities between adjacent cells. Each row and column must contain exactly one of each number ...
12
votes
12
answers
2k
views
Find The Real Solutions of a Cubic
Description
All cubic equations can be solved, and every cubic has at least one solution. The goal of this challenge is to find the real solutions to a given cubic using inputs, and (obviously) the ...
15
votes
20
answers
3k
views
It's Just Rocket Science
Write a program/function that finds the amount of fuel needed to escape Earth's gravity well given the exhaust velocity of the fuel and the amount of mass to transport using the Tsiolkovsky rocket ...
16
votes
11
answers
1k
views
Carryless factors
Carryless multiplication is an operation similar to binary long multiplication, but with XOR instead of addition:
...
12
votes
18
answers
584
views
Count the number of compositions of \$n\$ in which the greatest part is odd
A composition of an integer \$n\$ is a representation of \$n\$ as a sum of positive integers. For example the eight compositions of 4 are as follows:
...
24
votes
16
answers
2k
views
Reconstruct Matrix from its diagonals
Given the diagonals of a matrix, reconstruct the original matrix.
The diagonals parallel to the major diagonal (the main diagonals) will be given.
Diagonals: ...
10
votes
4
answers
759
views
Compute the Fabius Function
The Fabius function is an example of a function that is infinitely differentiable everywhere, yet nowhere analytic.
One way to define the function is in terms of an infinite number of random variables....
21
votes
17
answers
2k
views
Calculate Pi unto a point using the Nilakantha series
Your task: given a nonzero positive number i, calculate pi using the Nilakantha series unto i terms.
The Nilakantha series is as ...
15
votes
5
answers
939
views
Detect round trips on a dodecahedron
An ant starts on an edge of a dodecahedron, facing parallel to it. At each step, it walks forward to the next vertex and turns either left or right to continue onto one of the other two edges that ...
21
votes
22
answers
2k
views
The second even sublime number
easy mode of my previous challenge
A perfect number is a positive integer whose sum of divisors (except itself) is equal to itself. E.g. 6 (1 + 2 + 3 = 6) and 28 (1 + 2 + 4 + 7 + 14 = 28) are perfect.
...
17
votes
8
answers
3k
views
An algorithm to find even sublime numbers
A perfect number is a positive integer whose sum of divisors (except itself) is equal to itself. E.g. 6 (1 + 2 + 3 = 6) and 28 (1 + 2 + 4 + 7 + 14 = 28) are perfect.
A sublime number (OEIS A081357) is ...
5
votes
2
answers
257
views
Generate a Kirkman triple system
Given a universe of \$v\$ elements, a Kirkman triple system is a set of \$(v-1)/2\$ classes each having \$v/3\$ blocks each having three elements, so that
every pair of elements appears in exactly ...