Skip to main content

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
44 votes
69 answers
10k 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 ...
Peter Olson's user avatar
  • 7,732
86 votes
138 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 ...
Doorknob's user avatar
  • 71.5k
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 ...
Mike Shlanta's user avatar
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: ...
arshajii's user avatar
  • 2,172
85 votes
222 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 ...
Gareth's user avatar
  • 1,299
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 ...
user avatar
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 ...
Shaggy's user avatar
  • 42.1k
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. ...
Howard's user avatar
  • 23.5k
62 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 ...
isaacg's user avatar
  • 42k
47 votes
35 answers
15k 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 ...
xnor's user avatar
  • 145k
45 votes
18 answers
9k 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 ...
r.e.s.'s user avatar
  • 3,122
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... ...
Adnan's user avatar
  • 44.4k
37 votes
18 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 ...
Bassdrop Cumberwubwubwub's user avatar
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} \...
quintopia's user avatar
  • 4,138
390 votes
156 answers
290k 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. ...
qwr's user avatar
  • 12.1k
57 votes
79 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^...
Iszi's user avatar
  • 2,537
47 votes
44 answers
19k 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 ...
Kibbee's user avatar
  • 959
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. ...
user avatar
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 ...
Dennis's user avatar
  • 210k
65 votes
44 answers
10k 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 ...
DJMcMayhem's user avatar
  • 59.3k
50 votes
48 answers
11k 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 ...
user avatar
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 ...
user avatar
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 ...
MrZander's user avatar
  • 942
28 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 ...
Kevin Brown-Silva's user avatar
25 votes
11 answers
5k 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 ...
ardnew's user avatar
  • 2,329
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 ...
FUZxxl's user avatar
  • 10.1k
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 ...
JoshM's user avatar
  • 447
83 votes
193 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 ...
user avatar
56 votes
11 answers
12k 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 ...
Christopher King's user avatar
52 votes
50 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 ...
xnor's user avatar
  • 145k
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 ...
Adám's user avatar
  • 30.4k
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 ...
Arcturus's user avatar
  • 7,387
32 votes
29 answers
2k 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, ...
Luis Mendo's user avatar
  • 105k
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 ...
DJMcMayhem's user avatar
  • 59.3k
21 votes
16 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, ...
flawr's user avatar
  • 43.8k
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 ...
Hand-E-Food's user avatar
  • 8,750
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, ...
Thomas O's user avatar
  • 3,348
326 votes
55 answers
111k 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 ...
A Frayed Knot's user avatar
110 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 ...
caird coinheringaahin g's user avatar
57 votes
154 answers
8k 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/...
Bubbler's user avatar
  • 77k
55 votes
50 answers
9k views

Coprimes up to N

Given a number n >= 2, output all the positive integers less than n where gcd(n, k) == 1 (...
Riker's user avatar
  • 7,850
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: ...
DJMcMayhem's user avatar
  • 59.3k
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'...
Tony Ruth's user avatar
  • 761
45 votes
96 answers
14k views

Count sum of all digits

This challenge is to write a program or script which counts the sum of all digits within the integers from 1 up to and including a given number. Input, one positive integer. Output, the sum of digits ...
ST3's user avatar
  • 1,359
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 ...
mbomb007's user avatar
  • 23.4k
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 ...
jqkul's user avatar
  • 2,272
30 votes
144 answers
10k 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 ...
anna328p's user avatar
  • 6,396
30 votes
47 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 ...
Kevin Brown-Silva's user avatar
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 ...
Peter Taylor's user avatar
  • 43.1k
24 votes
4 answers
4k 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 ...
Volatility's user avatar
  • 3,374

1
2 3 4 5
13