Questions tagged [math]

The challenge involves mathematics. Also consider using more specific tags: [number] [number-theory] [arithmetic] [combinatorics] [graph-theory] [geometry] [abstract-algebra].

Filter by
Sorted by
Tagged with
19
votes
24answers
1k views

Perfect radicals

Given a positive integer number \$n\$ output its perfect radical. Definition A perfect radical \$r\$ of a positive integer \$n\$ is the lowest integer root of \$n\$ of any index \$i\$: $$r = \sqrt[i]{...
28
votes
49answers
3k views

Infinitely many ℕ

Background: A sequence of infinite naturals is a sequence that contains every natural number infinitely many times. To clarify, every number must be printed multiple times! The Challenge: Output a ...
16
votes
20answers
2k views

Find distance between the closest 3D points

Your task is to take \$n \ge 2\$ points in 3D space, represented as 3 floating point values, and output the Euclidean distance between the two closest points. For example $$A = (0, 0, 0) \\ B = (1, 1, ...
16
votes
13answers
1k views

All-inclusive semi-primes

\$723 = 3 \times 241\$ is a semi-prime (the product of two primes) whose prime factors include all digits from \$1\$ to \$n\$, where \$n\$ is the total number of digits between them. Another way to ...
2
votes
0answers
99 views

Dobble Double Challenge [closed]

I have a problem, which I haven't found a solution for. Solutions to the first part are well documented, but I have yet to find anyone who has solved the second part. I call this the "Dobble"...
8
votes
7answers
2k views

Fastest square root of an arbitrary size

We do seem to have a fastest square root challenge, but it's very restrictive. In this challenge, your program (or function) will be given an arbitrarily sized nonnegative integer, which is the square ...
33
votes
22answers
3k views

Narcissistic loop lengths

A narcissistic number is a natural number which is equal to the sum of its digits when each digit is taken to the power of the number digits. For example \$8208 = 8^4 + 2^4 + 0^4 + 8^4\$, so is ...
23
votes
36answers
1k views

Display the exponent from a binary floating point number as a decimal value

Had my software final exams recently, one of the last questions had me thinking for a while after the exam had finished. Background IEEE754 numbers are according to the below layout The exponent is ...
10
votes
1answer
321 views

Total resistance from unit resistors

This problem is based on, A337517, the most recent OEIS sequence with the keyword "nice". \$a(n)\$ is the number of distinct resistances that can be produced from a circuit with exactly \$n\...
14
votes
14answers
451 views

Repetend length in 1/n

This problem is based on non-terminating, repeating decimal points. Let \$n\$ be any positive integer \$(n > 1 \text{ and } n < 10000)\$, say \$7\$. Then, \$1/n = 1/7 = 0.142857142857142857...\$ ...
8
votes
14answers
357 views

Golf a bijection \$\mathbb{N}^n\to\mathbb{N}\$

Your task is to write a program which implements a bijection \$\mathbb{N}^n\to\mathbb{N}\$ for \$n \ge 1\$. Your program should take \$n\$ natural numbers as input, in any acceptable method (including ...
23
votes
9answers
3k views

The square root of the square root of the square root of the…

This code-golf challenge will give you an integer n, and ask you to count the number of positive integer sequences \$S = (a_1, a_2, \dots, a_t)\$ such that \$a_1 + ...
18
votes
16answers
2k views

A Portuguese sequence of integers

Context Consider the following sequence of integers: $$2, 10, 12, 16, 17, 18, 19, ...$$ Can you guess the next term? Well, it is \$200\$. What about the next? It is \$201\$... In case it hasn't become ...
18
votes
13answers
1k views

Find all integer pairs that produce a given Loeschian number

Inspired by and drawns from Is this number Loeschian? A positive integer \$k\$ is a Loeschian number if \$k\$ can be expressed as \$i^2 + j^2 + i\times j\$ for \$i\$, \$j\$ integers. For example, ...
37
votes
17answers
2k views

Three other numbers

Given three distinct numbers from \$1\$ to \$7\$, output three other distinct numbers from \$1\$ to \$7\$, that is having no numbers in common with the original numbers. Your code must produce a ...
20
votes
37answers
4k views

Is that number a Two Bit Number™️?

Let's start by defining a Two Bit Number™️: It is a positive integer When expressed as a binary string it has exactly 2 true bits OR When expressed as a decimal number, it has exactly 2 of the ...
29
votes
24answers
3k views

Circumference of an ellipse

Challenge Unlike the circumference of a circle (which is as simple as \$2\pi r\$), the circumference of an ellipse is hard. Given the semi-major axis \$a\$ and semi-minor axis \$b\$ of an ellipse (see ...
13
votes
17answers
1k views

Plot a centered circle

Intro Given radius \$r\$, draw a circle in the center of the screen. Sandbox. The Challenge Here is a simple challenge. Plot a circle using the formula \$x^2+y^2=r^2\$, or any other formula that will ...
21
votes
16answers
2k views

Delicate primes

Inspired by Find the largest fragile prime. By removing at least 1 digit from a positive integer, we can get a different non-negative integer. Note that this is different to the ...
0
votes
1answer
127 views

The Perfect Polynomial [closed]

The coefficients of a perfect square polynomial can be calculated by the formula \$(ax)^2 + 2abx + b^2\$, where both a and b are integers. The objective of this challenge is to create a program that ...
15
votes
26answers
436 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 \$...
30
votes
5answers
2k views

Avoid walking into a rectangle

Given a rectangle, a start point, and an end point, find any path from start to finish that avoids the rectangle. Example Suppose you were at \$(1.5, -1.5)\$ and you needed to get to \$(2, 4)\$. ...
12
votes
13answers
1k views

Diophantine Approximation: find lowest possible denominator to approximate within given precision

Challenge Given a number x and a precision e, find the lowest positive integer q such that <...
16
votes
12answers
2k views

Implement the Polygamma function

The Polygamma function of order \$m\$, \$\psi^{(m)}(z)\$, is the \$(m + 1)\$th derivative of the logarithm of the gamma function, which is also the \$m\$th derivative of the digamma function. Your ...
30
votes
76answers
5k views

The vanilla factorial challenge

Note: We already have the old factorial challenge, but it has some restrictions on the domain, performance, and banning built-ins. As the consensus here was to create a separate challenge without ...
30
votes
17answers
2k views

Substandard deviation

The mean of a population \$(x_1,\dots,x_n)\$ is defined as \$\bar x=\frac1n\sum_{i=1}^n x_i\$. The (uncorrected) standard deviation of the population is defined as \$\sqrt{\frac1n\sum (x_i-\bar x)^2}\$...
16
votes
13answers
2k views

Is it in the polygon?

The challenge Given point and a path of points, say whether or not the point is in the polygon that is created by the path. Also return true if the point is on an ...
17
votes
7answers
647 views

Combinatorial Decomposition

In the body of this challenge, \$\begin{pmatrix}n\\k\end{pmatrix}\$ is used to represent the number of combinations of \$k\$ elements of \$n\$, also written as \$\frac{n!}{k!(n-k)!}\$ or \$n\mathrm{C}...
18
votes
10answers
624 views

Prime Modified Z-Factorials

Let me explain one by one the above terms... We will call \$\text{Z-Factorial}(n)\$ of a positive integer \$n\$, \$n!\$ (i.e. \$n\$ factorial) without any trailing zeros. So, \$\text{Z-Factorial}(30)\$...
14
votes
4answers
541 views

Find the maximum flow

Given a directed network, with a single source and a single sink, it is possible to find the maximum flow through this network, from source to sink. For example, take the below network, \$G\$: Here, ...
0
votes
15answers
470 views

Find your dog's age

Task Take the (integer) number of human years that the dog has lived, \$n\$, as input and return its age in dog years, \$d\$, to two decimal places. The number of human years, \$n\$, will be between \$...
3
votes
0answers
148 views

Sums of permutations of vectors [closed]

I am looking for a more efficient way of computing the following. Let A and B be two vectors of non-negative integers of length <...
13
votes
13answers
1k views

Help me accelerate linear recurrence relation!

Background A linear recurrence relation is a description of a sequence, defined as one or more initial terms and a linear formula on last \$k\$ terms to calculate the next term. (For the sake of ...
11
votes
0answers
231 views

Checkerboard the Matrix

Task Given a matrix, your program/function should output a row-equivalent matrix in checkerboard form ( \$A_{ij}=0\$ if and only if \$i+j\$ is odd). Two matrices are defined to be row-equivalent if ...
14
votes
5answers
541 views

Cantor Function, Cruel

A ripoff of this challenge. Go upvote it! Objective Given a rational number amongst \$[0,1]\$, apply the Cantor function to it and output the rational number that's produced. The Cantor function The ...
22
votes
14answers
2k views

The Cantor Function

The Cantor function is continuous everywhere and constant almost everywhere, but has an average slope of 1: The function can be found recursively: \$f_0(x)=x\$ \$f_{n+1}(x)=\left\{\begin{matrix}\frac{...
24
votes
16answers
2k views

Cleaning up decimal numbers

Background Sometimes in calculus you're expected to calculate the sum of an infinite series. Sometimes these series are very friendly, like a geometric series, but add anything else onto it and it can ...
18
votes
10answers
2k views

Complete the Magic Square

Background A magic square is an n×n matrix consisting of one of each of the integers from \$1\$ to \$n^2\$ where every row, column, and diagonal sum to the same ...
11
votes
4answers
211 views

Is it a uniform polyhedron?

Objective Given a vertex figure consisting of regular convex polygons, determine whether it represents a convex uniform polyhedron. What is a uniform polyhedron? A uniform polyhedron is a polyhedron ...
9
votes
3answers
420 views

Count The Genus

Objective Given a matrix of connected box drawing characters, count its genus, the number of plane sections it encloses. Valid input The box drawing characters are ...
-5
votes
2answers
175 views

Solve the dress problem [closed]

Background Peter's Father, the Teacher of a dance-club, asks Peter a question: Given are two natural numbers (\$\mathbb{N}\$ \$x\$ and \$y\$). \$x\$ is the number of the garment types (e.g. shorts, ...
-1
votes
8answers
1k views

Make a Ramanujan magic square

Background As you maybe know Ramanujan made this magic square by \$4x4\$ Matrix: This works like all magic squares. But the special thing in this square is that his birthdate is hidden in the first ...
14
votes
5answers
952 views

What is the Subspace Dimension?

Challenge Given the Cartesian coordinates of two or more distinct points in Euclidean n-space (\$\mathbb{R}^n\$), output the minimum dimension of a flat (affine) subspace that contains those points, ...
24
votes
16answers
2k views

Laguerre Polynomials

Laguerre polynomials are solutions to Laguerre's equation, a second-order linear differential equation: \$xy''+(1-x)y'+ny=0\$. For a given value of n, the solution, y, is named \$L_n(x)\$. The ...
7
votes
7answers
2k views

Music with pi and e

Because I forgot to celebrate the pi-day(14.3) lets celebrate with \$\pi\$, \$e\$ (Euler's number) and music! Challenge No, we don't have time to eat a pi-pizza, lets make a program. What you need is ...
18
votes
29answers
2k views

Find the perfect square!

Your task is to turn a square root like this: √12 into a form like this: 2√3 For our purpose, we only need to output the left ...
16
votes
19answers
2k views

Are they collinear?

Task Write a program/function that when given three 2d points in cartesian coordinates as input outputs a truthy value if they are collinear otherwise a falsey value Three points are said to be ...
5
votes
8answers
248 views

Is it a geometric sequence or not? [closed]

Well, last time I asked for an arithmetic sequence, now comes the geometric sequence Challenge In this challenge, the input will be an unordered set of numbers and the program should be able to tell ...
-7
votes
4answers
211 views

Is it an Arithmetic Sequence or not? [closed]

Challenge In this challenge, the input will be an ordered set of numbers and the program should be able to tell if the set of numbers is an Arithmetic Sequence. Input The input will be a list ...
19
votes
16answers
2k views

Find the discrete logarithm

Task Write a program/function that when given 3 positive integers \$a, b\$ and \$m\$ as input outputs a positive integer \$x\$ such that \$a^x\equiv b\ (\text{mod}\ m)\$ or that no such \$x\$ exists. ...

1
2 3 4 5
30