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
31
votes
56answers
4k 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 ...
31
votes
78answers
5k views

The vanilla factorial challenge

Note: We already have the old factorial challenge, but it has some restrictions on the domain, performance, and banning built-ins. As the consensus here was to create a separate challenge without ...
17
votes
71answers
4k views

Average Two Letters

Introduction Every letter in the English alphabet can be represented as an ASCII code. For example, a is 97, and ...
18
votes
12answers
803 views

Compute modular inverse

Given two positive numbers \$x\$ and \$n\$ with \$x<2^n\$, write the shortest possible function to compute \$x^{-1} \mod 2^n\$. In other words, find \$y\$ such that \$xy=1 \mod 2^n\$. Your ...
10
votes
10answers
705 views

Fizzbuzz in any base

Challenge Input: An integer \$b\$ between 2 and 62 (inclusive). Output: Count from \$1\$ to the equivalent of \$5000_{10}\$ in base \$b\$, using any reasonable representation for the digits. ...
21
votes
14answers
2k views

Is this a truncated triangular number?

Related OEIS sequence: A008867 Truncated triangular number A common property of triangular numbers is that they can be arranged in a triangle. For instance, take 21 and arrange into a triangle of <...
27
votes
25answers
1k views

Find the sum of all possible base representations

The objective of this challenge is to write a program to convert an inputed string of what can be assumed as containing only letters and numbers from as many bases between 2 and 36 as possible, and ...
37
votes
29answers
3k views
+100

Factorials and never ending cycles!

As you may know it, the factorial of a positive integer n is the product of all the positive integers which are equal or smaller to ...
14
votes
21answers
2k views

Counter-Fibonacci Sequences

Given three numbers m,n and p, your task is to print a list/array of length p starting with m and n and each element after p represents the difference of the 2 numbers before it, m-n (Counter-...
48
votes
32answers
2k 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
3answers
4k views
+500

Construct a pentagon avoiding compass use

Rules You will start with only two elements: Points \$A\$ and \$B\$ such that \$A \neq B\$. These points occupy a plane that is infinite in all directions. At any step in the process you may do any ...
23
votes
36answers
2k views

Display the exponent from a binary floating point number as a decimal value

Had my software final exams recently, one of the last questions had me thinking for a while after the exam had finished. Background IEEE754 numbers are according to the below layout The exponent is ...
21
votes
26answers
2k views

“Factorise” a quadratic

When learning to factorise quadratics in the form \$x^2 + ax + b\$, a common technique is to find two numbers, \$p, q\$ such that $$pq = b \\ p + q = a$$ as, for such numbers, \$x^2 + ax + b = (x + p)(...
44
votes
34answers
3k views

Is this number Loeschian?

A positive integer \$k\$ is a Loeschian number if \$k\$ can be expressed as \$i^2 + j^2 + i\times j\$ for \$i\$, \$j\$ integers. For example, the first positive Loeschian numbers are: \$1\$ (\$i=1, ...
17
votes
13answers
3k views

Landau logarithm

Related: Landau's function (OEIS A000793) Background Landau's function \$g(n)\$ is defined as the largest order of permutation of \$n\$ elements, which is equal to \$\max(\operatorname{lcm}(a_1,a_2,\...
25
votes
43answers
5k views

Smallest integers after N divisible by 2, 3, and 4

Give credit to whom credit is due. Objective Given an integer N > 0, out the smallest integers A, ...
16
votes
48answers
3k views

Find the number of integers in the range from 1 to N that ends with 2

Task As input you have: a positive integer N And you should output: The number of integers in \$[1,N]\$ (an inclusive range) which end with the digit \$2\$ in ...
9
votes
3answers
328 views

Find the nth base-b digit of (b^k-1)^-2

Task Your task is simple. Write a program or function which takes three positive integer arguments n, k, and b in any order, such that 2 ≤ b ≤ 36, and returns or outputs the nth (1-indexed) base-b ...
104
votes
348answers
17k views

One OEIS after another

As of 13/03/2018 16:45 UTC, the winner is answer #345, by Scrooble. This means the contest is officially over, but feel free to continue posting answers, just so long as they follow the rules. As well,...
13
votes
3answers
901 views

Irreducible polynomials over GF(5)

A polynomial with coefficients in some field F is called irreducible over F if it cannot be decomposed into the product of lower degree polynomials with coefficients in F. Consider polynomials over ...
30
votes
13answers
4k views

Absolute Sums of Sidi Polynomial Coefficients

Background The Sidi polynomial of degree \$n\$ – or the \$(n + 1)\$th Sidi polynomial – is defined as follows. $$S_n(x) = \sum^n_{k=0}s_{n;k}x^n \text{ where } s_{n;k} = (-1)^k\binom n k (k+1)^n$$ The ...
95
votes
36answers
18k 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 ...
29
votes
24answers
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 ...
26
votes
62answers
6k views

Golf the xᵗʰ root of x

While bored in high-school (when I was half my current age...), I found that \$f(x) = x^{x^{-1}}\$ had some interesting properties, including e.g. that the maximum \$f\$ for \$0 ≤ x\$ is \$f(e)\$, and ...
15
votes
5answers
3k views

Long multiply, 8 bits at a time

You are given a 16-bit machine and told to implement multiplication of arbitrary-sized integers. Your registers can only hold 16-bit numbers, and the biggest multiply instruction takes two 8-bit ...
3
votes
0answers
331 views

Solve a Cubic Equation [closed]

Input Your program will take in the integer coefficients of the equation \$ax^3+bx^2+cx+d=0\$ as inputs (a, b, c, and d). Output All real solutions of the input equation, with an accuracy of at ...
20
votes
15answers
1k views

Penney-Conway odds

Background Penney's game is a two-player game about coin tossing. Player A announces a sequence of heads and tails of length \$n\$, then player B selects a different sequence of same length. The ...
13
votes
20answers
1k views

Linear integer function generator

Inspired by a recent challenge involving Fibonacci numbers in which OEIS was mentioned, I would like to present a challenge of creating a function that generates a wide array of different linear ...
22
votes
18answers
969 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 ...
20
votes
27answers
967 views

Partial sums of the Kempner series

The Kempner series is a series that sums the inverse of all positive integers that don't contain a "9" in their base-10 representations (i.e., \$\frac{1}{1} + \frac{1}{2} + \frac{1}{3} + .. +...
6
votes
5answers
581 views

Polynomial extrapolation

Task Given a list of integers a1, a2, …, ak (k ≥ 2) and a positive integer m, write a function or a complete program that calculates the next m numbers of the list. Assume that ai = P(i) where P(x) = ...
8
votes
2answers
281 views

Implement the Method of Finite Differences

The Method of Finite Differences is a technique used to find the next term in a sequence of numbers, given that the sequence is governed by consecutive values of a certain polynomial. Given a list of <...
10
votes
19answers
847 views

Output a unique sign sequence

A sign sequence is an infinite sequence consisting entirely of \$1\$ and \$-1\$. These can be constructed a number of ways, for example: Alternating signs: \$1, -1, 1, -1, ...\$ \$-1\$ for primes, \$...
11
votes
17answers
1k views

Polynomial Laplace transform

This is a repost of this challenge, intended to revamp it for looser I/O formats and updated rules You are to write a program which takes an integer polynomial in \$t\$ as input and outputs the ...
13
votes
10answers
2k views

Base85 Encoding

The Challenge Write a program that can take an input of a single-line string containing any ASCII printable characters, and output the same string encoded in Base85 (using a big-endian convention). ...
11
votes
5answers
565 views

Ellipsoid surface area

Related: Ellipse circumference Introduction An ellipsoid (Wikipedia / MathWorld) is a 3D object analogous to an ellipse on 2D. Its shape is defined by three principal semi-axes \$a,b,c\$: $$ \frac{x^2}...
13
votes
6answers
420 views

Implement Multiplicative Fuzzy Logic

Inspired by this excellent challenge (from which the bulk of this text is blatantly duct-taped) – and my highschool philosophy project... I define the following operators: Fuzzy Conjunction a ×F b is ...
34
votes
48answers
4k views

Infinitely Print Zeno's Dichotomy Paradox (1/(2^n))

Wikipedia: Zeno's Dichotomy Paradox An infinite number of mathematicians walk into a bar. The first one orders a beer. The second one orders half a beer. The third one orders a fourth of a beer. The ...
24
votes
34answers
3k views

Write out the Thue-Morse sequence

There's quite a few challenges on this site that ask you to print out a sequence, and this is no exception. (The following explanation of the sequence for this challenge assumes the symbols in the ...
12
votes
12answers
2k views

Verify Magic Square

A magic square is a square array of numbers with side n consisting of the distinct positive integers 1, 2, ..., n² arranged such that the sum of the n numbers in any horizontal, vertical, or main ...
7
votes
11answers
945 views

Find the nth digit of Euler's number

Challenge Given a positive integer n, you must calculate the nth digit of \$e\$, where \$e\$ is Euler's number (2.71828...). The format of the output can be a ...
30
votes
2answers
1k views

Golf the smallest sphere!

Inspired by this challenge, as well as a problem I've been working on Problem: Given a non-empty set of points in 3D space, find the diameter of the smallest sphere ...
16
votes
35answers
2k views

An Array of Challenges #3: Moving Averages

Note: This is #3 in a series of array-manipulation challenges. For the previous challenge, click here. Moving Average of a List The moving average of a list is a calculation resulting in a new, ...
34
votes
22answers
7k views

Random point on a sphere

The Challenge Write a program or function that takes no input and outputs a 3-dimensional vector of length \$1\$ in a theoretically uniform random direction. This is equivalent to a random point on ...
13
votes
7answers
619 views

Generalised Taxicab Numbers

\$\newcommand{T}[1]{\text{Ta}(#1)} \newcommand{Ta}[3]{\text{Ta}_{#2}^{#3}(#1)} \T n\$ is a function which returns the smallest positive integer which can be expressed as the sum of 2 positive integer ...
14
votes
47answers
3k views

What is the standard scratch?

In golf, the standard scratch of a course is calculated using this formula: ...
23
votes
2answers
1k views

Eye test - How many squares are in this picture?

The picture: Sick of the same old grid where the answer is simply a square pyramidal number? Accept the challenge and write a program that given a positive integer \$n\$ counts how many squares are ...
16
votes
18answers
2k views

Test if given number is a Keith number

Since Fibonacci numbers and sequences seems like a popular subject for code golf I thought that it might be a fun challenge to code golf with Keith numbers. So I propose a challenge that is to create ...
11
votes
5answers
377 views

Taxi me some numbers

Taxicab Numbers or OEIS A011541 are the least numbers that are able to be represented as \$n\$ different sums of two positive cubed integers, for successive \$n\$. You'll need to print out the \$n\$th ...
22
votes
16answers
2k views

Sort a number's divisors by prime factorization

Given an input of an integer \$n ≥ 2\$, output a list of its divisors sorted by the exponents in their prime factorizations, in ascending order, ordering first by the largest prime, then by the second ...

1
2 3 4 5
30