Questions tagged [math]
The challenge involves mathematics in some central way. Also consider using more specific tags, listed in the tag wiki info.
603
questions
44
votes
68
answers
9k
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 ...
87
votes
135
answers
13k
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 ...
47
votes
85
answers
8k
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 ...
15
votes
15
answers
2k
views
Golf the Subset-Sum Problem
Task
Given a list of space-delimited integers as input, output all unique non-empty subsets of these numbers that each subset sums to 0.
Test Case
Input: ...
36
votes
49
answers
4k
views
Least Common Multiple
The least common multiple of a set of positive integers A is the smallest postive integer B such that, for each ...
84
votes
219
answers
17k
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 ...
52
votes
81
answers
7k
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 ...
36
votes
17
answers
12k
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 ...
30
votes
31
answers
3k
views
Josephus problem (counting out)
The challenge
Write a function that takes two positive integers \$n\$ and \$k\$ as arguments and returns the number of the last person remaining out of \$n\$ after counting out each \$k\$-th person.
...
63
votes
44
answers
14k
views
Find the Smoothest Number
Your challenge is to find the smoothest number over a given range. In other words, find the number whose greatest prime factor is the smallest.
A smooth number is one whose largest prime factor is ...
47
votes
35
answers
14k
views
XOR multiplication
You goal is to implement the operation of XOR (carryless) multiplication, defined below, in as few bytes as possible.
If we think of bitwise XOR (^) as binary ...
44
votes
18
answers
6k
views
Shortest terminating program whose output size exceeds Graham's number
Write the shortest possible program (length measured in bytes) satisfying the following requirements:
no input
output is to stdout
execution eventually terminates
total number of output bytes exceeds ...
27
votes
17
answers
3k
views
Compute the multinomial coefficient
Time for another easy challenge in which all can participate!
The multinomial theorem states:
$$(x_1 + x_2 + \cdots + x_m)^n = \sum_{k_1 + k_2 + \cdots + k_m = n} \binom n {k_1, k_2, \dots, k_m} \...
391
votes
156
answers
287k
views
Write a program that makes 2 + 2 = 5 [closed]
Write a program that seemingly adds the numbers 2 and 2 and outputs 5. This is an underhanded contest.
Your program cannot output any errors. Watch out for memory holes! Input is optional.
...
57
votes
77
answers
8k
views
Test a number for narcissism
A Narcissistic Number is a number which is the sum of its own digits, each raised to the power of the number of digits.
For example, take \$153\$ (3 digits):
\$1^3 + 5^3 + 3^3 = 153\$
\$1634\$:
\$1^...
47
votes
41
answers
18k
views
Draw A Sierpinski Triangle
The Sierpinsky Triangle is a fractal created by taking a triangle, decreasing the height and width by 1/2, creating 3 copies of the resulting triangle, and place them such each triangle touches the ...
35
votes
20
answers
9k
views
Balanced Ternary Converter
Credits for the challenge idea go to @AndrewPiliser. His original proposal in the sandbox was abandoned and since he has not been active here for several months, I have taken over the challenge.
...
26
votes
8
answers
2k
views
All your bijective base are belong to us
Background
A bijective base b numeration, where b is a positive integer, is a bijective positional notation that makes use of b symbols with associated values of 1 to b.
Unlike its non-bijective ...
63
votes
44
answers
9k
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 ...
37
votes
39
answers
4k
views
Determinant of an Integer Matrix
Given a square integer matrix as input, output the determinant of the matrix.
Rules
You may assume that all elements in the matrix, the determinant of the matrix, and the total number of elements in ...
32
votes
47
answers
7k
views
Implement hyperexponentiation/tetration without the use of '^' [closed]
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 ...
29
votes
5
answers
2k
views
Advanced Calculator
You must write a program that evaluates a string that would be entered into an advanced calculator.
The program must accept input using stdin and output the correct answer. For languages that do no ...
25
votes
11
answers
4k
views
Generate a Kolakoski sequence [duplicate]
Definition1
A Kolakoski sequence is a self-describing infinite sequence {kn} of alternating blocks of 1's and 2's, given by the following rules:
k0 = 1
kn = the length of the (n+1)'th ...
23
votes
4
answers
3k
views
Four fours puzzle
The Four fours puzzle is a popular recreational mathematical puzzle that involves using exactly four 4s (and no other number) and a defined set of operations to reach every number from 0 to a given ...
13
votes
3
answers
1k
views
Polynomial Interpolation
Write a program that performs Polynomial Interpolation using true arbitrary precision rational numbers. The input looks like this:
f(1) = 2/3
f(2) = 4/5
f(3) = 6/7
...
You may assume that there's ...
11
votes
25
answers
3k
views
Cartesian product of a list with itself n times
When given a a list of values and a positive integer n, your code should output the cartesian product of the list with itself n ...
83
votes
192
answers
10k
views
Output the sign
Given a number N, output the sign of N:
If N is positive, output 1
If N is negative, output -1
If N is 0, output 0
N will be an integer within the representable range of integers in your chosen ...
55
votes
9
answers
11k
views
Golf a number bigger than TREE(3)
The function TREE(k) gives the length of the longest sequence of trees T1, T2, ... where each vertex is labelled with one of k colours, the tree Ti has at most i vertices, and no tree is a minor of ...
51
votes
48
answers
4k
views
Count sums of two squares
Given a non-negative number n, output the number of ways to express n as the sum of two squares of integers ...
49
votes
48
answers
10k
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 ...
44
votes
68
answers
8k
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 ...
39
votes
62
answers
6k
views
Zeroes at the end of a factorial
Write a program or function that finds the number of zeroes at the end of n! in base 10, where n is an input number (in any ...
37
votes
29
answers
6k
views
Find the number in the Champernowne constant
Introduction
In base 10, the Champernowne constant is defined by concatenating representations of successive integers. In base 10: 0.1234567891011121314151617... ...
22
votes
19
answers
2k
views
Calculate the partitions of N
Your challenge is simple: GIven an integer N, ouput every list of positive integers that sums to N. For example, if the input was 5, you should output
...
21
votes
15
answers
2k
views
Discrete Convolution or Polynomial Multiplication
Given two non empty lists of integers, your submission should calculate and return the discrete convolution of the two. Interestingly, if you consider the list elements as coefficients of polynomials, ...
11
votes
11
answers
1k
views
Minimum perimeter of an area [duplicate]
Just a simple code golf function for fun, intentionally left open with few rules to see what creativity comes up.
Input: An integer representing the area of a rectangle.
Output: Two integers ...
7
votes
17
answers
4k
views
Multiply without multiply [closed]
Write the fastest (best big-O) and smallest multiplication algorithm for positive integers, without using multiplication operators. You are only allowed addition, subtraction, logical functions (AND, ...
326
votes
55
answers
110k
views
Tweetable Mathematical Art [closed]
Integer math can generate amazing patterns when laid out over a grid. Even the most basic functions can yield stunningly elaborate designs!
Your challenge
Write 3 Tweetable (meaning 140 characters ...
109
votes
406
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 ...
55
votes
50
answers
8k
views
Coprimes up to N
Given a number n >= 2, output all the positive integers less than n where gcd(n, k) == 1 (...
49
votes
71
answers
7k
views
An abundance of integers!
An Abundant number is any number where the sum of its proper divisors is greater than the original number. For example, the proper divisors of 12 are:
...
46
votes
44
answers
3k
views
Pseudofactorial
There is a rather curious number which shows up sometimes in math problems or riddles. The pseudofactorial(N) is the least (i.e. lowest) common multiple of the numbers 1 through N; in other words, it'...
34
votes
29
answers
5k
views
Calculate the Super-Logarithm
This should be a simple challenge.
Given a number \$n \ge 0\$, output the super-logarithm (or the \$\log^*\$, log-star, or iterated logarithm, which are equivalent since \$n\$ is never negative for ...
33
votes
68
answers
6k
views
Count the divisors of a number
Introduction
This is a very simple challenge: simply count the divisors of a number. We've had a similar but more complicated challenge before, but I'm intending this one to be entry-level.
The ...
30
votes
144
answers
9k
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 ...
29
votes
46
answers
7k
views
Additive Persistence
The shortest code to pass all possibilities wins.
In mathematics, the persistence of a number measures how many times a certain operation must be applied to its digits until some certain fixed ...
29
votes
26
answers
1k
views
Natural construction
The natural numbers including 0 are formally defined as sets, in the following way:
Number 0 is defined as the empty set, {}
For n ≥ 0, number n+1 is defined as n ∪ {n}.
As a consequence, n = {0, 1, ...
28
votes
18
answers
3k
views
Generate a pair of integers from a non-negative one
You should write a program or function which takes a non-negative integer N as input and outputs or returns two integers (negative, zero or positive) ...
26
votes
1
answer
1k
views
Find real roots of a polynomial
Write a self-contained program which when given a polynomial and a bound will find all real roots of that polynomial to an absolute error not exceeding the bound.
Constraints
I know that Mathematica ...
23
votes
28
answers
2k
views
Generalized matrix trace
Inspiration.
Given (by any means):
A two-argument (or single argument consisting of a two-element list) black box function, f: ℤ+ × ℤ+ → ℤ+ (input and output are 1,...