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
26 votes
54 answers
6k views

Write a microwave timer!

You are an employee of Microteque, a leading Silicon Valley startup creating smart microwave ovens for all kinds of strange places. Your customers can get their microwaves printed with patterns to ...
32 votes
87 answers
7k views

iHateOddNumbers

Task Given a non-negative number, check if it's odd or even. In case it's even, output that number. Otherwise, throw any exception/error that your language supports, and stop the program. Example with ...
7 votes
5 answers
747 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} < \...
12 votes
8 answers
630 views

Sum up snail number neighbours

Input: You are given two numbers n and m. Create the snail: Fill an n * ...
6 votes
9 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,...
25 votes
23 answers
1k views

Calculate Home Primes

The Home Prime of an integer \$n\$ is the value obtained by repeatedly factoring and concatenating \$n\$'s prime factors (in ascending order, including repeats) until reaching a fixed point (a prime). ...
24 votes
17 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: ...
42 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 ...
15 votes
7 answers
2k views

How compactly can your language perform accurate numerical integration?

WARNING: This challenge may need 128 bit floats.1 The task is to perform numerical integration. Consider the following three functions. \$ f(x) = cx^{c - 1}e^{-x^c} \$ \$ g_1(x) = 0.5e^{-x} \$ \$ ...
3 votes
4 answers
603 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 ...
22 votes
12 answers
2k views

Gamma Function Golf

Given a real number t in (-10^9,13) (not including -10^9 or ...
44 votes
18 answers
3k views

Compare Two Fractions With ASCII Art

Challenge Write a program or function that takes in 4 non-negative integers, A, B, C, and D, that represent two fractions, A/B and C/D, where B and D are non-zero and A <= B and C <= D. Output ...
36 votes
56 answers
5k views

The first n numbers without consecutive equal binary digits

The sequence contains the decimal representation of the binary numbers of the form: 10101..., where the n-th term has n bits. The sequence is probably easiest to ...
16 votes
48 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 (...
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 ...
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} \...
21 votes
31 answers
2k views

Cosine similarity of two vectors

The cosine similarity of two vectors \$A\$ and \$B\$ is defined using their dot product and magnitude as: \$\frac{A\cdot B}{\|A\|\|B\|}\$ Or in other terms \$\frac{\sum_{i=1}^nA_iB_i}{\sqrt{\sum_{i=1}^...
51 votes
41 answers
3k views

Moving modest minimum

Inspired by a question over at Stack Overflow. The title here is entirely my fault. The challenge Given a list of positive integers containing at least two entries, replace each number by the ...
109 votes
407 answers
20k views

One OEIS after another

As of 13/03/2018 16:45 UTC, the winner is answer #345, by Khuldraeseth na'Barya. This means the contest is officially over, but feel free to continue posting answers, just so long as they follow the ...
14 votes
21 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. ...
3 votes
5 answers
356 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{...
11 votes
3 answers
3k views

Evaluate the Riemann Zeta Function at a Complex Number

Introduction I found this question that was closed because it was unclear, yet it was a nice idea. I'll do my best to make this into a clear challenge. The Riemann Zeta function is a special function ...
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} \...
1 vote
8 answers
277 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 = ...
-1 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 ...
12 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 <...
26 votes
22 answers
2k views

Find the Maximal Prime Powers

A prime power is a positive integer n that can be written in the form n = pk where p is a prime and k is a positive integer. For example, some prime powers are ...
40 votes
48 answers
7k views

Lonely Multiplication

Based on this question from Code Review. Given precisely three positive integers, return the product of all of the distinct inputs. If none of the inputs are distinct, return 1. That is, implement ...
9 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 ...
4 votes
25 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\$ ...
14 votes
14 answers
2k views

Print all Polynomials

The set of all polynomials with integer coefficients is countable. This means that there is a sequence that contains each polynomial with integer coefficients exactly once. Your goal is it to write a ...
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, ...
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
924 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. ...
21 votes
93 answers
5k views

Average Two Letters

Introduction Every letter in the English alphabet can be represented as an ASCII code. For example, a is 97, and ...
47 votes
58 answers
9k views

Shift right by half a bit

The challenge is to implement a program or function (subsequently referred to as "program") that takes a nonnegative integer \$n\$ as input and returns \$n\over\sqrt{2}\$ (the input divided by the ...
22 votes
22 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 ...
31 votes
14 answers
3k views

That's a prime... almost

If you've ever learned about primes in math class, you've probably have had to, at one point, determine if a number is prime. You've probably messed up while you were still learning them, for example, ...
26 votes
25 answers
2k views

Interquartile Mean

Task Given (by any means) a sorted floating point dataset, return (by any means and within 1‰ of the correct value) the interquartile mean. One possible algorithm Discard the lowest and highest ...
-6 votes
1 answer
168 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},...
1 vote
1 answer
506 views

Find the optimum circle in an infinite grid

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 ...
11 votes
20 answers
5k views

Calculate 500 digits of e

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 ...
14 votes
13 answers
1k views

Definite integral of polynomial functions

You will need to evaluate the definite integral (bounded by \$a\$ and \$b\$) of a certain polynomial function that takes the form of: $$\int_a^b \left( k_n x^n + k_{n-1} x^{n-1} + \cdots + k_2x^2 + ...
15 votes
24 answers
1k views

Find the rate of change at a point on a polynomial

Given the equation of a polynomial and an x-coordinate find the rate of change of the point at that x-coord on the curve. A polynomial is in the form: axn + axn-1 + ... + ax1 + a, where a ϵ Q and n ϵ ...
33 votes
27 answers
4k views

Circumference of an ellipse

Challenge Unlike the circumference of a circle (which is as simple as \$2\pi r\$), the circumference (arc length) of an ellipse is hard. Given the semi-major axis \$a\$ and semi-minor axis \$b\$ of an ...
19 votes
9 answers
966 views

Output an infinitely proportional sequence

In this challenge, an infinitely proportional sequence is defined as a infinite sequence of positive integers such that: All positive integers are contained infinitely many times within the sequence. ...
18 votes
24 answers
2k views

Test whether a sequence is bitonic

You know what a monotonic sequence is: each element is bigger than its predecessor (monotonically rising) or as its successor (monotonically falling). Bitonic means you have two arms of the sequence, ...
24 votes
24 answers
2k views

Approximate the Dottie number to arbitrary precision

The Dottie number is the fixed point of the cosine function, or the solution to the equation cos(x)=x.1 Your task will be to make code that approximates this constant. Your code should represent a ...
14 votes
17 answers
3k views

What's the character limit of this text field? [duplicate]

Someone I know has no coding experience, but has proposed an algorithm* to determine the character limit of text fields they find online. They copy a string containing the numbers from 1 to 1,000 ...
15 votes
2 answers
569 views

Construct this point

Given a constructible point \$(x, y) \in \mathbb R^2\$, output the steps required to construct \$(x, y)\$ Constructing a point Consider the following "construction" of a point \$(\alpha, \...

1
2 3 4 5
36