Questions tagged [math]

The challenge involves mathematics in some central way. Also consider using more specific tags, listed in the tag wiki info.

Filter by
Sorted by
Tagged with
22 votes
36 answers
2k 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 ...
user avatar
16 votes
1 answer
484 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\...
user avatar
  • 8,117
16 votes
15 answers
591 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...\$ ...
user avatar
  • 2,860
10 votes
14 answers
499 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 ...
user avatar
26 votes
10 answers
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 + ...
user avatar
  • 8,117
23 votes
17 answers
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 ...
user avatar
  • 13.8k
20 votes
14 answers
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, ...
user avatar
  • 511
41 votes
21 answers
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 ...
user avatar
  • 138k
28 votes
48 answers
5k 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 numeral ...
user avatar
  • 11.3k
30 votes
24 answers
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 ...
user avatar
  • 64.8k
16 votes
32 answers
2k 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 ...
user avatar
  • 25.2k
23 votes
16 answers
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 ...
user avatar
-2 votes
1 answer
140 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 ...
user avatar
  • 417
17 votes
27 answers
540 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 \$...
user avatar
30 votes
5 answers
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)\$. ...
user avatar
  • 12.3k
13 votes
13 answers
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 <...
user avatar
  • 519
17 votes
12 answers
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 ...
user avatar
46 votes
118 answers
7k views

The vanilla factorial challenge

Task Given a non-negative integer \$n\$, evaluate the factorial \$n!\$. The factorial is defined as follows: $$ n!=\begin{cases}1 & n=0\\n\times(n-1)!&n>0\end{cases} $$ Rules All default I/...
user avatar
  • 64.8k
31 votes
16 answers
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}\$...
user avatar
  • 15.2k
17 votes
13 answers
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 ...
user avatar
  • 1,398
18 votes
7 answers
718 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}...
user avatar
  • 1,989
20 votes
9 answers
647 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)\$...
user avatar
  • 23.2k
15 votes
4 answers
584 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, ...
user avatar
1 vote
19 answers
742 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 \$...
user avatar
  • 25.2k
3 votes
0 answers
169 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 <...
user avatar
15 votes
14 answers
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 ...
user avatar
  • 64.8k
20 votes
2 answers
565 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 ...
user avatar
16 votes
5 answers
625 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 ...
user avatar
  • 4,173
23 votes
14 answers
3k 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{...
user avatar
  • 1,989
26 votes
16 answers
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 ...
user avatar
  • 3,077
19 votes
10 answers
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 ...
user avatar
12 votes
4 answers
247 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 ...
user avatar
  • 4,173
10 votes
3 answers
448 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 ...
user avatar
  • 4,173
-5 votes
2 answers
191 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, ...
user avatar
  • 4,621
-1 votes
8 answers
2k 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 ...
user avatar
  • 4,621
14 votes
5 answers
975 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, ...
user avatar
24 votes
16 answers
3k 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 ...
user avatar
  • 1,989
9 votes
8 answers
2k views

Music with pi and e

Because I forgot to celebrate Pi Day (14.3), let's celebrate with \$\pi\$, \$e\$ (Euler's number) and music! Challenge No, we don't have time to eat a pi-pizza, let's make a program. What you need is ...
user avatar
  • 4,621
19 votes
31 answers
3k 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 ...
user avatar
16 votes
20 answers
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 ...
user avatar
  • 6,609
5 votes
8 answers
268 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 ...
user avatar
  • 4,621
-7 votes
4 answers
230 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 ...
user avatar
  • 4,621
19 votes
16 answers
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. ...
user avatar
  • 6,609
14 votes
8 answers
1k views

Is a statement of propositional logic always true?

The challenge is to golf a program that checks if a statement of propositional calculus/logic is a logical tautology (i.e. it is true for all possible values of the variables). Input Input formulas ...
user avatar
  • 1,398
2 votes
2 answers
196 views

Create a text image by manual automation

Challenge Premise It's 2006, and Alice is trying to send Bob their her completed notes on their newly ended expeditions into the labyrinthine school library, which the two of them found suffers from a ...
user avatar
11 votes
8 answers
1k views

Scientific notation in Base-16

Input a scientific notation number (base 10), output scientific notation in base 16 (as defined below). Details In scientific notation, all non-zero numbers are written in the form $$ m \times 10^n $$ ...
user avatar
  • 30.7k
16 votes
4 answers
2k views

Archimedes's cattle problem

Compute, O friend, the number of the cattle of the sun which once grazed upon the plains of Sicily, divided according to color into four herds, one milk-white, one black, one dappled and one yellow. ...
user avatar
  • 6,609
0 votes
6 answers
662 views

LeetCode 552: Student Attendance Record II

I'm posting my code for a LeetCode problem copied here. If you have time and would like to golf for a short solution, please do so. Requirement It has to only pass the LeetCode's Online Judge, if the ...
user avatar
  • 143
0 votes
0 answers
140 views

I am surely the fastest!... asymptotically [duplicate]

Background You are probably familiar with the "asymptotic time complexity" concept, which provides a way to measure how fast an algorithm runs as the input gets larger. For instance, if an ...
user avatar
  • 749
23 votes
9 answers
1k views

Split pythagorean triples into two sets

Task Write a program/function that when given a positive integer \$n\$ splits the numbers from \$1\$ to \$n\$ into two sets, so that no integers \$a, b, c\$, satisfying \$a^2 + b^2 = c^2\$ are all in ...
user avatar
  • 6,609

1
3 4
5
6 7
34