Questions tagged [math]
The challenge involves mathematics in some central way. Also consider using more specific tags, listed in the tag wiki info.
1,823
questions
12
votes
9
answers
1k
views
How many ways can you make change?
The "third type of Euler Transform" takes an integer sequence that gives the number of objects of a given weight and outputs a sequences that gives the number of multisets of objects that ...
14
votes
13
answers
1k
views
Calculate the sum of numbers in a rectangle
Aim
Consider this infinite array of numbers:
...
14
votes
5
answers
595
views
Sum-of-four-squares grid
Output a grid of characters visualizing the decomposition of a number into a sum of four perfect squares.
Challenge
Given a nonnegative integer \$0 \le n \le 2^{30}\$, output a \$2^k \times 2^k\$ ...
17
votes
18
answers
2k
views
Shift right by half a trit
Shift right by half a trit
This is inspired by Shift right by half a bit, but it's a little different.
Motivation
I was wondering if there is a function f that maps ...
28
votes
47
answers
2k
views
Cubic Concatenation
Challenge
Given three non-negative integers \$a, b\$ and \$c\$, decide if the sum of their cubes is equal to the concatenation of those numbers, aka:
$$
a^{3}+b^{3}+c^{3} = a^\frown b ^\frown c
$$
...
6
votes
1
answer
246
views
Counterexample to Shapiro inequality
Input: A positive integer n such that n is even and greater than 12 or n is odd and greater than 23.
Output: A list of non-negative integers that violates Shapiro inequality.
More precisely, Let s be ...
14
votes
16
answers
565
views
Rabinowitz-Wagon \$\pi\$ formula
In 1995, Stanley Rabinowitz and Stan Wagon found an interesting algorithm to generate the digits of \$\pi\$ one by one without storing the previous results. The algorithm is called the spigot ...
10
votes
10
answers
748
views
Factoriadic Fraction Addition
Objective
Given two rational numbers represented in fractional factoriadic as defined below, add them, and output the result in fractional factoriadic.
Fractional factoriadic
Fractional factoriadic is ...
14
votes
16
answers
2k
views
Reduce a string up to idempotency [closed]
Objective
Given a string consisting of printable ASCII characters (!0x21 ― ~0x7E), treat it as an element in the free idempotent ...
7
votes
6
answers
626
views
Compute Dickman
Input
A floating point number \$x\$ between 1 and 8 inclusive.
Output
The Dickman function of \$x\$.
The Dickman–de Bruijn function \$\rho(u)\$ is a continuous function that satisfies the delay ...
9
votes
12
answers
717
views
Minimum number of select-all/copy/paste steps for a string containing n copies of the original
This challenge is based on this Mathematics answer.
Write the shortest program or function that, when given some natural number \$n\$, outputs \$S(n)\$, which is the minimum number of steps for ...
16
votes
3
answers
2k
views
Find 10 float64s that give the least accurate sum
Input
Integer \$n > 1\$
Output
Ten 64 bit floating point numbers between \$-n\$ and \$n\$, inclusive, whose sum is the least accurate.
Details and examples.
These examples are not claimed to be ...
13
votes
9
answers
1k
views
Sum of square roots (as an algebraic number)
An algebraic number is a number that is a root of a non-zero polynomial with integer coefficients. It is well-known that the sum of two algebraic numbers is algebraic. In particular, the sum of a list ...
3
votes
7
answers
351
views
Find the most isolated point
Given two non-empty sets of points \$P,T = \{(x,y)\ |\ x,y \in \mathbb{Z} \}\$, find the point \$p \in P\$ such that it is the "most isolated" from all points in \$T\$. The "most ...
13
votes
13
answers
2k
views
Compute the degree of a string
The input is a string made of the letters a,b,c only. The output is an integer representing the degree of the sequence. The degree of a sequence is computed as follows:
Assume that each of the ...
8
votes
4
answers
485
views
How far are you?
Write a program that gets coordinates of two objects on Earth, and calculates how far they are from each other directly in space (a straight line through Earth) and on the surface (through the ...
13
votes
11
answers
804
views
*Trivial* near-repdigit perfect powers
Task
Output the sequence that precisely consists of the following integers in increasing order:
the 2nd and higher powers of 10 (\$10^i\$ where \$i \ge 2\$),
the squares of powers of 10 times 2 or 3 (...
17
votes
21
answers
1k
views
Infer pluses and minuses
The problem
Consider an equation such as "3 ± 2 ± 4 ± 1 = 4" and determine if there exists a sequence of pluses and minuses that makes it arithmetically correct. If it exists, ...
26
votes
15
answers
2k
views
Is it a cartesian product?
The cartesian product of two multisets \$A\$ and \$B\$ is the multiset of all ordered pairs consisting of an element of \$A\$ and an element of \$B\$. For example, the cartesian product of \$\{1, 2, 7,...
5
votes
1
answer
311
views
Dishonest dungeon staff
This is a joint post with https://puzzling.stackexchange.com/questions/126255/dishonest-dungeon-staff
You are faced with the difficult task to set up a dungeon for adventurers. However you made a deal ...
10
votes
4
answers
2k
views
Output a 1-2-3-5-7... sequence
Follow-up of my previous challenge, inspired by @emanresu A's question, and proven possible by @att (Mathematica solution linked)
For the purposes of this challenge, a 1-2-3-5-7... sequence is an ...
21
votes
15
answers
2k
views
Output a 1-2-3 sequence
For the purposes of this challenge, a 1-2-3 sequence is an infinite sequence of increasing positive integers such that for any positive integer \$n\$, exactly one of \$n, 2n,\$ and \$3n\$ appears in ...
19
votes
5
answers
3k
views
Draw a Fibonacci Swoosh
Title courtesy of Greg Martin
For this challenge, I'll define an arc of size \$k\$ as a single piece of a sine wave with a length of \$k\$ units and an height of \$\frac{k}{4}\$ units:
And I'll ...
6
votes
12
answers
957
views
Argument of a complex number (Robbers)
V1.1: Added criterion to help with tiebreakers, a bit overkill but still.V1.2: It's April 15th!
Task: Crack the scrambled code for calculating the argument of a complex number \$z=x+iy\$ given two ...
11
votes
23
answers
2k
views
Argument of a complex number (Cops)
This is the cop's thread, where one should post the scrambled code. Here is the robbers' thread where the cracked source should be posted and linked to the cop's answer.
NB: I am currently writing up ...
14
votes
7
answers
2k
views
How quickly can you type this unary string?
If I want to type the string aaa, the least keystrokes I can type it in is 3: a a a. But if I want to type the string ...
7
votes
2
answers
270
views
Convert maximum values to bit widths
Background
The newest version of the C standard, C23, adds preprocessor macros like INT_WIDTH, ULONG_WIDTH, and ...
12
votes
14
answers
1k
views
Lattice points visible from the origin
Challenge
Create a program that outputs a square grid showing visible and non-visible points \$(x, y)\$ from the origin based on their greatest common divisor (GCD).
A point \$(x, y)\$ is considered ...
18
votes
26
answers
2k
views
Is it a tetrate of two?
The tetration operation consists of repeated exponentiation, and it is written ↑↑. For instance,
3↑↑3 =3 ^(3^3) = 3^27 = 7,625,597,484,987
A tetrate of two is an ...
12
votes
6
answers
1k
views
Contract a tensor
Introduction
Tensor contraction is an operation that can be performed on a tensor. It is a generalization of the idea of the trace of a matrix. For example, if we have a rank-2 tensor (a matrix) and ...
11
votes
10
answers
1k
views
Egyptian fraction representations of 1 without prime denominators
Background
As noted in this question, for all positive integers \$n>2\$ there exists at least one Egyptian fraction representation (EFR) of \$n\$ distinct positive integers \$a_{1} < a_{2} < \...
15
votes
12
answers
828
views
Sum up snail number neighbours
Input: You are given two numbers n and m.
Create the snail: Given an n >= 3, fill an <...
14
votes
13
answers
1k
views
Counting rankings
There is a competition with \$n\$ participants in total. Alice is one of the participants. The outcome of the competition is given as a ranking per participant with a possibility of ties; e.g. there ...
3
votes
4
answers
686
views
Fastest count of certain hypercubes with labeled vertices
CHALLENGE
This is a fastest-code challenge.
Count how many n-dimensional hypercubes with n=1,2,3,4 exist, with vertices labeled with either 1 or 0, such that there does not exist any rectangle formed ...
4
votes
5
answers
414
views
Generate a sequence of \$n\$ consecutive composite numbers
Definitions
The common methods to generate consecutive composites are
$$\overbrace{(n+1)! + 2, \ (n+1)! + 3, \ \ldots, \ (n+1)! + (n+1)}^{\text{n composites}}$$
$$\overbrace{n!+2,n!+3,...,n!+n}^{\text{...
1
vote
8
answers
304
views
Alternating Random Series Sum To \$N\$ [closed]
Challenge
Given a positive integer \$N \ge 3\$, generate an alternating series of \$N\$ random numbers within the range \$[1, N]\$, such that their sum equals \$N\$. Expressed mathematically as
$$N = ...
-3
votes
8
answers
1k
views
Number of cigarettes that can be made from a given number of butts
Assumption
A cigarette can be made by combining four cigarette butts. Cigarette butts last infinitely until smoked.
Explanation
Say you have 31 butts. That means, you can make 7 cigarettes from 28 ...
13
votes
20
answers
1k
views
Modular Equivalence
Given two numbers \$x,y > 2, x≠y \$ output all integers \$m\$ such that
$$
x + y \equiv x \cdot y \pmod m
$$
$$
x \cdot y > m > 2
$$
Input
Two integers
Output
A list of integers
Test cases
<...
13
votes
19
answers
1k
views
The TAK function (easy mode)
The TAK function is defined as follows for integers \$x\$, \$y\$, \$z\$:
$$
t(x, y, z) = \begin{cases}
y, & \text{if $x \le y$} \\
t(t(x-1,y,z), t(y-1,z,x), t(z-1,x,y)), & \text{otherwise}
\...
18
votes
7
answers
1k
views
The TAK function
The TAK function is defined as follows for integers \$x\$, \$y\$, \$z\$:
$$
t(x, y, z) = \begin{cases}
y, & \text{if $x \le y$} \\
t(t(x-1,y,z), t(y-1,z,x), t(z-1,x,y)), & \text{otherwise}
\...
13
votes
20
answers
2k
views
Complete a Mystery Sequence
Given a sequence of three integers, determine if the sequence is arithmetic (of the form [a, a+d, a+2*d]) or geometric (of the form ...
7
votes
10
answers
974
views
Make 1's and 2's composite
Input
An integer k composed of 1 and 2, with at least 3 digits and at most 200 digits.
...
3
votes
28
answers
2k
views
Consecutive Composite Numbers
Challenge
Generate \$n-1\$ consecutive composite numbers using this prime gap formula
$$n!+2,n!+3,...,n!+n$$
Input
An integer \$n\$ such that \$3 \leq n \leq 50 \$.
Output
Sequence of \$n-1\$ ...
17
votes
19
answers
1k
views
Ellipse Lattice Point Counter
Challenge
Determine how many integer lattice points there are in an ellipse
$$\frac{x^2}{a^2} + \frac{y^2}{b^2} \leq 1$$
centered at the origin with width \$2a\$ and height \$2b\$ where integers \$a, ...
-6
votes
1
answer
187
views
Where to stand to throw circles over sticks
Consider a horizontal line with vertical lines centered on the x-axis and placed at gaps of \$\sqrt{2}/2\$. For a positive integer \$n \geq 3\$, the first half of the lines have lengths \$0, \sqrt{2},...
17
votes
22
answers
2k
views
Divmod continuously until the remainder is 1 or 0, then get the remainder
The task is simple, divide, get the quotient and the remainder, and if the remainder isn't 1 or 0, do the same thing (quotient divmod remainder) until the remainder is 1 or 0, then get the remainder. ...
10
votes
12
answers
1k
views
Counting Collinear Points
Given two points \$(x_1, y_1)\$ and \$(x_2, y_2)\$ with integer coordinates, calculate the number of integer points (excluding the given points) that lie on the straight line segment joining these two ...
1
vote
1
answer
562
views
Where to put a circle?
Consider an \$n \times n\$ grid of integers which is part of an infinite grid. The top left coordinate of the \$n \times n\$ grid of integers is \$(0, 0)\$.
The task is to find a circle which when ...
12
votes
20
answers
5k
views
Calculate 500 digits of e [duplicate]
Write a program to calculate the first 500 digits of the mathematical constant e, meeting the rules below:
It cannot include "e", "math.e" or similar e constants, nor may it call ...
9
votes
3
answers
480
views
Coin sequence probability
Given two strings containing only 0 and 1, decide the probability that first appears earlier as a consecutive substring in an ...