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
62
votes
149answers
13k views

Sum of all integers from 1 to n

I'm honestly surprised that this hasn't been done already. If you can find an existing thread, by all means mark this as a duplicate or let me know. Input Your input is in the form of any positive ...
22
votes
9answers
2k views

Fermat's polygonal number theorem

Fermat's polygonal number theorem states that every positive integer can be expressed as the sum of at most \$n\$ \$n\$-gonal numbers. This means that every positive integer can be expressed as the ...
24
votes
14answers
3k views

Are my triangles similar?

Given (in any structure; flat list, two lists of lists, a tuple of matrices, a 3D array, complex numbers,…) the coordinates for two non-degenerate triangles ...
15
votes
40answers
3k views

Find the percentage

We haven't had any nice, easy challenges in a while, so here we go. Given a list of integers each greater than \$0\$ and an index as input, output the percentage of the item at the given index of the ...
44
votes
66answers
6k views

It's Hip to be Square

Challenge So, um, it seems that, while we have plenty of challenges that work with square numbers or numbers of other shapes, we don't have one that simply asks: Given an integer ...
40
votes
65answers
5k views

Greatest Common Divisor

Your task is to compute the greatest common divisor (GCD) of two given integers in as few bytes of code as possible. You may write a program or function, taking input and returning output via any of ...
14
votes
21answers
2k views

Do Matrix Multiplication!

In mathematics, matrix multiplication or the matrix product is a binary operation that produces a matrix from two matrices. The definition is motivated by linear equations and linear transformations ...
9
votes
26answers
835 views

Are the numbers amicable?

Two numbers are considered amicable if the proper divisor sum of the first is the same as the second number, the second number's proper divisor sum is equal to the first number, and the first and ...
35
votes
50answers
7k views

I reverse the source code, you negate the input!

Blatant rip-off of a rip-off. Go upvote those! Your task, if you wish to accept it, is to write a program/function that outputs/returns its integer input/argument. The tricky part is that if I ...
46
votes
27answers
2k views

Divisor skyline

For any positive integer k, let d(k) denote the number of divisors of k. For example, ...
91
votes
35answers
16k views

Mandelbrot image in every language

I always used a Mandelbrot image as the 'graphical' version of Hello World in any graphical application I got my hands on. Now it's your guys' turn. Language must be capable of graphical output or ...
67
votes
23answers
8k views

Yo boy, must it sum

Every positive integer can be expressed as the sum of at most three palindromic positive integers in any base b≥5.   Cilleruelo et al., 2017 A positive integer is palindromic in a given base if ...
22
votes
122answers
7k views

Multiply two numbers

Input: Two decimal integers. These can be given to the code in standard input, as arguments to the program or function, or as a list. Output: Their product, as a decimal integer. For example, the ...
18
votes
8answers
802 views

Is this quadrilateral cyclic?

In mathematics, a cyclic quadrilateral is one whose vertices all lie on the same circle. In other words, every vertex is on the circumcircle of the other three. For more information, see the MathWorld ...
-9
votes
22answers
383 views

Sum the unique numbers in a list

For this challenge, the objective is to take a list of integers, and output the sum of every unique integer in that list, i.e. count multiples of the same integer only once. Your input will be a ...
19
votes
36answers
2k 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: By letting x equal 1, we obtain Challenge Write a ...
33
votes
50answers
6k views

Generate Pascal's triangle

Pascal's triangle is generated by starting with a 1 on the first row. On subsequent rows, the number is determined by the sum of the two numbers directly above it to the left and right. To ...
24
votes
59answers
4k views

Adding without using a + or - sign

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
37answers
4k views

Implement hyperexponentiation/tetration without the use of '^'

The Challenge Implement tetration (aka Power Tower or Hyperexponentiation) with the least amount of characters. The Conditions Don't use the 'power' operator or its equivalents (such as ...
26
votes
63answers
3k views

The Non-Zero Digital Product Challenge

Originally the Multiplicative digital root Challenge Basically do what the title says Method Given a positive integer 1 <= N <= 100000000 through one of our standard input methods, multiply ...
5
votes
78answers
3k views

Summation from a to b

The program has an input of a and b, and outputs the sum of numbers from a to b, inclusive. Score is in bytes. As always, standard loopholes are disallowed. If your input is in the format [a,b], +3 ...
20
votes
40answers
3k views

Parallel resistance in electric circuits

Introduction: Two resistors, R1 and R2, in parallel (denoted R1 || R2) have a combined ...
38
votes
83answers
4k views

Product over a range

Your task is simple: given two integers a and b, output ∏[a,b]; that is, the product of the ...
30
votes
6answers
3k views

Find Primes in Pi

Primes are everywhere... they hide inside Pi 3.1415926535897932384626433832795028841971693993751 Let's get those primes! The Challenge Given as input an integer ...
54
votes
35answers
6k views

Print the N-bonacci sequence

This isn't very widely known, but what we call the Fibonacci sequence, AKA 1, 1, 2, 3, 5, 8, 13, 21, 34... is actually called the Duonacci sequence. This is ...
15
votes
1answer
1k views

Golf a number bigger than Loader's number

As a follow up to Shortest terminating program whose output size exceeds Graham's number and Golf a number bigger than TREE(3), I present a new challenge. Loader's number is a very large number, ...
15
votes
7answers
1k views

Decimal “XOR” operator

Many programming language provide operators for manipulating the binary (base-2) digits of integers. Here is one way to generalize these operators to other bases: Let x and y be single-digit numbers ...
13
votes
11answers
717 views

Output Distinct Factor Cuboids

Output Distinct Factor Cuboids Today's task is very simple: given a positive integer, output a representative of each cuboid formable by its factors. Explanations A cuboid's volume is the product ...
17
votes
23answers
1k views

Enumerate Derangements

Given some positive integer \$n\$ generate all derangements of \$n\$ objects. Details A derangement is a permutation with no fixed point. (This means in every derangement number \$i\$ cannot be in ...
39
votes
100answers
5k views

Divisibility test

Task Given two strictly positive integers n and d as input, determine whether n is evenly divisible by d, i.e., if there exists an integer q such that n = qd. You ...
25
votes
8answers
1k views

Verify Topology

Challenge Given a set T of subsets of a finite set S={1,2,3,...,n}, determine whether T is ...
16
votes
14answers
1k views

Permutations in Disguise

Given a \$n\$-dimensional vector \$v\$ with real entries, find a closest permutation \$p\$ of \$(1,2,...,n)\$ with respect to the \$l_1\$-distance. Details If it is more convenient, you can use ...
8
votes
11answers
675 views

Olympic game scoring [closed]

The challenge is to write a golf-code program that, given n positive real numbers from 0 to 10 (format x.y, y only can be 0 or 5: 0, 0.5, 1, 1.5, 2, 2.5 … 9.5 and 10), discard the lowest and highest ...
17
votes
8answers
1k views

Dividing Divisive Divisors

Given a positive integer \$n\$ you can always find a tuple \$(k_1,k_2,...,k_m)\$ of integers \$k_i \geqslant 2\$ such that \$k_1 \cdot k_2 \cdot ... \cdot k_m = n\$ and $$k_1 | k_2 \text{ , } k_2 | ...
41
votes
20answers
5k views

Calculate the Mean mean of two numbers

disclaimer: the Mean mean is made up by me Define the arithmetic mean of \$n\$ numbers as $$M_1(x_1,...,x_n)=\frac{x_1+x_2+...+x_n}{n}$$ Define the geometric mean of \$n\$ numbers as $$M_0(x_1,...,...
31
votes
21answers
6k views

Random point on a sphere

The Challenge Write a program or function that takes no input and outputs a vector of length \$1\$ in a theoretically uniform random direction. This is equivalent to a random point on the sphere ...
15
votes
3answers
750 views

Fibonacci’s sexagesimals

Leonardo da Pisano a.k.a Fibonacci was instrumental in bringing the Hindu-Arabic numeral system into Europe. Before that, mathematicians there worked in base sixty with Roman numerals. For example, ...
11
votes
11answers
2k views

Do these squares overlap?

Given the coordinates of the upper left corners of two squares and their side lengths, determine whether the squares overlap. A square includes the top and left lines, but not the bottom and right ...
16
votes
12answers
5k views

Divide Numbers by 0

We've all been told at some point in our lives that dividing by 0 is impossible. And for the most part, that statement is true. But what if there was a way to perform the forbidden operation? Welcome ...
66
votes
95answers
9k views

Collatz Conjecture (OEIS A006577)

This is the Collatz Conjecture (OEIS A006577): Start with an integer n > 1. Repeat the following steps: If n is even, divide it by 2. If n is odd, multiply it by 3 and add 1. It is proven that ...
36
votes
21answers
7k views

Angle between the hands on a clock [duplicate]

Given the time in 24 hour format (2359 = 11:59pm) return the angle between the minute and hour hands on a standard clock (on the ...
38
votes
51answers
6k views

Don't give me five!

Question : You will be given the starting and ending integers of a sequence and should return the number of integers within it which do not contain the digit 5. ...
33
votes
18answers
7k views

Find the nth decimal of pi

There are already 30 challenges dedicated to pi but not a single one asks you to find the nth decimal, so... Challenge For any integer in the range of ...
19
votes
12answers
2k 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 ...
12
votes
12answers
2k views

Round like a Zero

Goal Given an input number, round it off to the nearest number with one significant figure. Requirements Input A floating point number. Assume the input number results in an output within the data ...
22
votes
15answers
4k views

The infinite power tower

The challenge Quite simple, given an input x, calculate it's infinite power tower! x^x^x^x^x^x... For you math-lovers out ...
19
votes
4answers
444 views

Compute height of Bowl Pile

Bowl Pile Height The goal of this puzzle is to compute the height of a stack of bowls. A bowl is defined to be a radially symmetric device without thickness. Its silhouette shape is an even ...
9
votes
2answers
372 views

​Plane​ ​Blow​up​

The Blow-up is a powerful tool in algebraic geometry. It allows the removal of singularities from algebraic sets while preserving the rest of their structure. If you're not familiar with any of that ...
41
votes
43answers
7k views

Reverse Polish notation

You must evaluate a string written in Reverse Polish notation and output the result. The program must accept an input and return the output. For programming languages that do not have functions to ...
42
votes
35answers
10k 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: ...