Questions tagged [math]
The challenge involves mathematics in some central way. Also consider using more specific tags, listed in the tag wiki info.
608
questions
55
votes
22
answers
3k
views
Dennis numbers 2.0
PPCG user and elected mod, @Dennis just became the second ever user to earn over 100k rep!
This is a totally original idea, that I did not get from anybody else, but let's make a challenge based off ...
53
votes
43
answers
3k
views
Illustrate the Least Common Multiple
Given two positive integers, \$A\$ and \$B\$, illustrate their least common multiple by outputting two lines of dashes (-) with length \$\text{lcm}\$\$(A, B)\$ ...
48
votes
32
answers
3k
views
Divisor skyline
For any positive integer \$k\$, let \$d(k)\$ denote the number of divisors of \$k\$. For example, \$d(6)\$ is \$4\$, because \$6\$ has \$4\$ divisors (namely \$1, 2, 3, 6\$).
Given a positive integer \...
45
votes
22
answers
6k
views
Universal Spooky Meme Translator
Introduction
Turns out, aliens love memes just as much as we do. Every alien race we've encountered so far has their own version of 2spooky4me (see the following ...
45
votes
86
answers
8k
views
Print a bunch of uninteresting numbers!
An uninteresting number (which I totally didn't make up only for this challenge) is created like this:
Take a positive integer N
Create a new number O by adding the digits of N at the end of N
...
45
votes
44
answers
13k
views
Fibonacci reversed!
Introduction
We all know and love our Fibonacci sequence and have seen a myriad of challenge on it here already. However, we're still lacking a very simple case which this answer is going to provide: ...
42
votes
70
answers
5k
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 ...
40
votes
52
answers
9k
views
Is this a triangle?
Task
Write a function/program that, given three positive integers a, b and c, prints a ...
39
votes
4
answers
3k
views
Addition on Elliptic Curves
Disclaimer: This does not do any justice on the rich topic of elliptic curves. It is simplified a lot. As elliptic curves recently got a lot of media attention in the context of encryption, I wanted ...
39
votes
24
answers
3k
views
Print the nth prime that contains n
This question will be a twist on finding the nth prime number.
Challenge
You must write a program that will take one input n, ...
38
votes
6
answers
3k
views
Make the largest infinity that you can!
The ordinal number system is a system with infinite numbers. A lot of infinite numbers. So many infinite numbers that it literally does not have an infinity to represent its own infiniteness. The ...
38
votes
91
answers
6k
views
Is this number a repdigit?
Challenge
A repdigit is a non-negative integer whose digits are all equal.
Create a function or complete program that takes a single integer as input and outputs a truthy value if the input number is ...
35
votes
2
answers
3k
views
Tribute to John Conway: Collatz in FRACTRAN
John Horton Conway was a brilliant mathematician. Among his contributions were three Turing-complete esolangs: Game of Life (esolangs wiki), FRACTRAN (esolangs wiki), and Collatz function (esolangs ...
34
votes
15
answers
2k
views
One-zero dividend
Challenge description
For every positive integer n there exists a number having the form of 111...10...000 that is divisible by ...
33
votes
20
answers
2k
views
Superior Passtimes
Sometimes, when I'm really bored I like to take the sum of an array of non-negative integers. I only take the sum of arrays of lengths that are powers of two. Unfortunately I often make mistakes. ...
33
votes
26
answers
4k
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 ...
32
votes
25
answers
2k
views
Output the nth rational number according to the Stern-Brocot sequence
The Stern-Brocot sequence is a Fibonnaci-like sequence which can be constructed as follows:
Initialise the sequence with s(1) = s(2) = 1
Set counter ...
31
votes
43
answers
2k
views
Return the integers with square digit-sums
Introduction and Credit
We all know and love our awesome rules to test whether a number is divisble by 11 or 3, which is just some clever sum over the digits of the number. Now this challenge takes ...
31
votes
18
answers
3k
views
Simplify a square root
Given a positive integer n, simplify the square root √n into the form a√b by extracting all ...
31
votes
47
answers
3k
views
Subtract the next numbers
Description
Subtract the next P numbers from a N number. The next number of N is N + 1.
Look at the examples to get what I mean.
Examples:
...
30
votes
20
answers
2k
views
Expand Exponentiation
Given two integers greater than one, A and B, output four mathematical expressions in this order:
The plain expression A^B (A to the power B). e.g. if A = 2 and B = 3, ...
30
votes
9
answers
5k
views
Calculate the permanent as quickly as possible
The challenge is to write the fastest code possible for computing the permanent of a matrix.
The permanent of an n-by-n matrix ...
29
votes
63
answers
3k
views
Sum square difference
The sum of the squares of the first ten natural numbers is,
\$1^2 + 2^2 + \dots + 10^2 = 385\$
The square of the sum of the first ten natural numbers is,
\$(1 + 2 + ... + 10)^2 = 55^2 = 3025\$
...
29
votes
2
answers
900
views
Hilbertify an image
I like the Hilbert Curve.
Your task for this challenge is to take an image (strictly a square image where all the sides are a power of two pixels wide) and unravel it line by line in a zig-zagging ...
29
votes
75
answers
6k
views
Adding without using a + or - sign [closed]
There have been many "Do __ without __" challenges before, but I hope that this is one of the most challenging.
The Challenge
You are to write a program that takes two natural numbers (whole numbers ...
28
votes
42
answers
4k
views
Simple integer operation calculator
Implement a simple integer operation scriptable calculator.
Concept
The accumulator starts at 0 and has operations performed on it. At the end of the program output the value of the accumulator.
...
28
votes
27
answers
3k
views
Calculate A190810
Your task is pretty simple, calculate the n-th element of A190810.
Elements of A190810 are calculated according to these rules:
The first element is 1
The sequence is increasing
If ...
28
votes
23
answers
2k
views
Find prime gaps
A prime gap is the difference between two consecutive primes. More specifically, if p and q are primes with p <q and p+1, p+2, ..., _q_−1 are not primes, the primes p and q define a gap of n = q_−...
27
votes
55
answers
4k
views
Approximation of e
We all know that the Euler's number, denoted by \$e\$, to the power of some variable \$x\$, can be approximated by using the Maclaurin Series expansion:
$$e^x=\sum_{k=0}^{\infty}{\frac{x^k}{k!}}=1+x+\...
27
votes
19
answers
5k
views
Last non-zero digit of n!
Given an integer 1 ≤ N ≤ 1,000,000 as input, output the last non-zero digit of N!, where ! is the factorial (the product of all numbers from 1 to N, inclusive). This is OEIS sequence A008904.
Your ...
26
votes
25
answers
3k
views
Modular multiplicative inverse
Your task is to given two integer numbers, a and b calculate the modular multiplicative inverse of a modulo b, if it exists.
...
26
votes
8
answers
7k
views
Convert infix expressions to postfix notation
When I saw the title of this closed question, I thought it looked like an interesting code golf challenge. So let me present it as such:
Challenge:
Write a program, expression or subroutine which, ...
26
votes
19
answers
3k
views
Analog is Obtuse!
An analog clock has 2 hands*: Hour and minute.
These hands circle the clock's face as time goes by. Each full rotation of the minute hand results in 1/12th of a rotation of the hour hand. 2 full ...
25
votes
77
answers
4k
views
Implement the hyperfactorial
The objective
Given the non-negative integer \$n\$, output the value of the hyperfactorial \$H(n)\$. You don't have to worry about outputs exceeding your language's integer limit.
Background
The ...
25
votes
8
answers
2k
views
Implement Ash's float division
Ash has a bit of an interesting float division algorithm. It's designed to never return NaN, and things like signed zero and infinity need to be handled.
How it ...
24
votes
34
answers
9k
views
Give the smallest number that has N divisors
Your function takes a natural number and returns the smallest natural number that has exactly that amount of divisors, including itself.
Examples:
...
24
votes
4
answers
1k
views
Three-pointer! But what kind?
From http://en.wikipedia.org/wiki/Triangle:
Write a program that takes three 2d coordinate tuples (Cartesian), and classifies what shape these three points describe.
In almost all cases these points ...
24
votes
28
answers
2k
views
Get the decimal!
Task:
Your task is, when given three inputs:
a numerator n
a denominator d
another integer, ...
24
votes
10
answers
1k
views
Calculate Power Series Coefficients
Given a polynomial \$p(x)\$ with integral coefficients and a constant term of \$p(0) = \pm 1\$, and a non-negative integer \$N\$, return the \$N\$-th coefficient of the power series (sometimes called &...
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 ...
23
votes
18
answers
1k
views
Interpret Interval Notation
Interval notation is a way to write complicated range bounds more conveniently and concisely than writing an inequality. The challenge, should you choose to accept it, is to write a program or ...
23
votes
25
answers
787
views
Product over exclusive and inclusive ranges
Inspired by this question by @CᴏɴᴏʀO'Bʀɪᴇɴ.
Taken from the question:
Your task is simple: given two integers a and b, output ∏[a,b]; that
is, the product of the range between a and b. You may ...
23
votes
7
answers
1k
views
Reverse Engineer Polling Statistics
Introduction
Given a set of percentages of choices in a poll, calculate the minimum number of voters there must be in the poll to generate those statistics.
Example: What is your favorite pet?
Dog: ...
23
votes
21
answers
2k
views
Diamond Puzzles!
Explanation:
Last year in math class, on homework we would occasionally get these extremely simple, although equally annoying questions called diamond puzzles. These were basically questions where we ...
23
votes
34
answers
3k
views
Sum of two squares
Given a nonnegative integer \$n\$, determine whether \$n\$ can be expressed as the sum of two square numbers, that is \$\exists a,b\in\mathbb Z\$ such that \$n=a^2+b^2\$.
...
22
votes
3
answers
3k
views
Prove me wrong!
Introduction
Your mission in life is simple: Prove people wrong on the internet!
To do this you usually carefully analyze their statements and point out the contradiction in them.
It's time to ...
22
votes
16
answers
2k
views
The Euclidean Algorithm (for finding the greatest common divisor)
The Challenge
Write a program or function that takes two input integers, i and j, and outputs their greatest common divisor; ...
22
votes
12
answers
2k
views
Gamma Function Golf
Given a real number t in (-10^9,13) (not including -10^9 or ...
22
votes
48
answers
3k
views
Parallel resistance in electric circuits
Introduction:
Two resistors, R1 and R2, in parallel (denoted R1 || R2) have a combined ...
21
votes
12
answers
3k
views
Calculate Landau's function
Landau's function \$g(n)\$ (OEIS A000793) gives the maximum order of an element of the symmetric group \$S_n\$. Here, the order of a permutation \$\pi\$ is the smallest positive integer \$k\$ such ...