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
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 ...
DJMcMayhem's user avatar
  • 58.9k
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)\$ ...
Calvin's Hobbies's user avatar
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 \...
Luis Mendo's user avatar
  • 104k
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 ...
Itai Ferber's user avatar
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 ...
Seims's user avatar
  • 669
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: ...
SEJPM's user avatar
  • 3,383
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 ...
Adam Katav's user avatar
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 ...
RGS's user avatar
  • 14k
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 ...
flawr's user avatar
  • 43.7k
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, ...
ericw31415's user avatar
  • 2,284
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 ...
PyRulez's user avatar
  • 7,207
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 ...
praosylen's user avatar
  • 1,495
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 ...
Bubbler's user avatar
  • 73.8k
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 ...
shooqie's user avatar
  • 5,592
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. ...
Bijan's user avatar
  • 841
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 ...
Bubbler's user avatar
  • 73.8k
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 ...
Sok's user avatar
  • 6,144
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 ...
SEJPM's user avatar
  • 3,383
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 ...
xnor's user avatar
  • 144k
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: ...
Paul Schmitz's user avatar
  • 1,137
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, ...
Calvin's Hobbies's user avatar
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 ...
user avatar
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\$ ...
Eduardo Hoefel's user avatar
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 ...
Wheat Wizard's user avatar
  • 96.6k
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 ...
PhiNotPi's user avatar
  • 29k
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. ...
anna328p's user avatar
  • 6,332
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 ...
TuxCrafting's user avatar
  • 4,817
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_−...
Luis Mendo's user avatar
  • 104k
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+\...
Meow Mix's user avatar
  • 913
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 ...
fR0DDY's user avatar
  • 4,579
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. ...
Halvard Hummel's user avatar
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, ...
Ilmari Karonen's user avatar
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 ...
Mayube's user avatar
  • 11.6k
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 ...
Nirvana's user avatar
  • 359
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 ...
Rydwolf Programs's user avatar
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: ...
SteeveDroz's user avatar
  • 2,463
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 ...
Digital Trauma's user avatar
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, ...
clismique's user avatar
  • 6,982
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 &...
flawr's user avatar
  • 43.7k
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 ...
caird coinheringaahin g's user avatar
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 ...
Aiden4's user avatar
  • 2,435
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 ...
Alexis Andersen's user avatar
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: ...
mellamokb's user avatar
  • 6,073
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 ...
Ashwin Gupta's user avatar
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\$. ...
hakr14's user avatar
  • 4,964
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 ...
SEJPM's user avatar
  • 3,383
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; ...
Zach Gates's user avatar
  • 6,660
22 votes
12 answers
2k views

Gamma Function Golf

Given a real number t in (-10^9,13) (not including -10^9 or ...
user avatar
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 ...
Stewie Griffin's user avatar
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 ...
Daniel Schepler's user avatar

1 2 3
4
5
13