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
15
votes
5answers
521 views

Visualize a Difference Pyramid

A difference pyramid is a pyramid where each new diagonal is the absolute value of the differences between the elements of the last diagonal. For example, if we start with the array ...
14
votes
5answers
1k views

Simulate any 1D cellular automaton

The Challenge You are to write a complete program that takes seven numbers from STDIN, and prints the two dimensional history of the cellular automaton (CA) to STDOUT. This is code golf. Input ...
12
votes
40answers
4k views

Integer square root of integer [closed]

Problem: In your choice of language, write the shortest function that returns the floor of the square root of an unsigned 64-bit integer. Test cases: Your function must work correctly for all ...
12
votes
8answers
2k views

Calculate the Hafnian as quickly as possible

The challenge is to write the fastest code possible for computing the Hafnian of a matrix. The Hafnian of a symmetric 2n-by-2n ...
10
votes
26answers
3k views

N numbers closest to zero staying balanced

Objective: Given a positive integer n: If n is odd, output the list of n numbers closest to ...
9
votes
0answers
115 views

Order of Elements of the Rubik's Cube [duplicate]

Introduction All the possible moves and their combinations of a Rubik's Cube form a group. A group in general is a set with some binary operation defined on it. It must contain a neutral element with ...
7
votes
2answers
4k views

Print the n-th digit of pi [duplicate]

Task Given an input n, calculate the n-th decimal digit of pi Rules Answer can be a full program or a function. Input must be taken from stdin or from function ...
38
votes
19answers
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, ...
32
votes
20answers
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. ...
27
votes
35answers
2k 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: ...
23
votes
19answers
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 ...
22
votes
3answers
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 ...
22
votes
14answers
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; ...
22
votes
22answers
2k 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. ...
18
votes
12answers
1k views

Output N in base -10

Challenge: In the programming language of your choice, accept an integer as input in base 10, and output it in the negadecimal notation, which is also known as base -10 Example algorithm: This is ...
17
votes
4answers
1k views

An optimization challenge with strange coins

You have n coins which each weigh either -1 or 1. Each is labelled from 0 to n-1 so you can ...
17
votes
10answers
2k views

Write a word equation solver

Introduction Consider the following example: CODE + GOLF —————— GREAT This is an equation where each letter represents a decimal digit and the words ...
17
votes
10answers
500 views

Ascending matrix

The "ascending matrix" is an infinite matrix of whole numbers (0 included) in which any element is the smallest available element which has not been previously used on the respective row and column: <...
16
votes
31answers
1k views

Print the tetration

Tetration, represented as a^^b, is repeated exponentiation. For example, 2^^3 is 2^2^2, ...
15
votes
25answers
4k views

The program that will find the next prime number

Intro: You accidentally corrupted the flow of time with a device you made for fun, that turned out to be a time machine. As a result, you got pushed to the far future. You realized that computing, ...
14
votes
7answers
883 views

Molar masses of compounds

Task Write a program that takes in a compound made solely of elements with an atomic number less than or equal to 92 (Uranium), and outputs the molar mass of the compound in ...
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 ...
14
votes
4answers
370 views

Counting Abelian groups of a given size

Background Last time, we counted groups of a given size, which is a non-trivial problem. This time, we'll only count Abelian groups, i.e., groups with a commutative operation. Formally, a group (G, &...
11
votes
9answers
1k views

Find a fraction's position in the Stern-Brocot tree

The Stern-Brocot tree is a binary tree of fractions where each fraction is acquired by adding the numerators and denominators of the two fractions neighbouring it in the levels above. It is generated ...
11
votes
7answers
1k views

Calculate the Kronecker Product

Related, but very different. In the examples below, A and B will be 2-by-2 matrices, and the matrices are one-indexed. A ...
10
votes
5answers
1k views

Calculate a probability exactly and quickly

[This is a partner question to Calculate a probability exactly ] This task is about writing code to compute a probability exactly and quickly. The output should be a precise probability written as a ...
9
votes
3answers
734 views

Print the intersection of sequences

Sequences You are given four number sequences, numbered 1 through 4. OEIS The location of 0...
9
votes
7answers
812 views

Golf the pseudoprimes!

Introduction / Background In a recent discussion in the crypto chat I was challenged to discuss / help with the Fermat primality test and Carmichael numbers. This test is based on the premise that <...
7
votes
2answers
264 views

Rational Polynomial Interpolation

Explanation In this task you'll be given a set of N points (x1,y1),…,(xN,yN) with distinct xi values and your task is to interpolate a polynomial through these points. If you know what Lagrange ...
2
votes
8answers
6k views

compute number of 1 bits in a binary representation of a number

The goal is to write a program that returns number of 1 bits in a given number. Examples 5 -> 2 1254 -> 6 56465 -> 8 Winner The winning ...
2
votes
3answers
297 views

Find the sequence

The purpose of this challenge is to find the general term of a given arithmetic or geometric sequence. Explanation The formula for an arithmetic sequence is as follows an = a1 + (n-1)d where a1 ...
31
votes
41answers
3k views

Find the sum of all numbers below n that are a multiple of some set of numbers

Almost equivalent to Project Euler's first question: If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23. Find ...
31
votes
42answers
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 ...
21
votes
16answers
2k views

Verify Eigenpairs

In this challenge, you will be given a square matrix A, a vector v, and a scalar λ. You will ...
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 ...
19
votes
12answers
3k views

Codegolf the permanent

The challenge is to write codegolf for the permanent of a matrix. The permanent of an n-by-n matrix ...
19
votes
15answers
2k views

Hypercube elements

Write a function or program that outputs the number of each type of element (vertex, edge, face, etc.) of an N-dimensional hypercube. As an example, the 3 dimensional cube has 1 cell (i.e. 1 3-...
18
votes
21answers
1k views

Output diagonal positions of me squared

Given a number n, Output an ordered list of 1-based indices falling on either of the diagonals of an n*n square matrix. ...
17
votes
11answers
1k views

Gamma Function Golf

Given a real number t in (-10^9,13) (not including -10^9 or ...
16
votes
3answers
331 views

Solving less-than inequalities with positive integers

Write a program or function that takes in a nonempty list of mathematical inequalities that use the less than operator (<). Each line in the list will have the ...
16
votes
47answers
2k views

Alternating Sign Sequence

Introduction The sign of a number is either a +, or a - for every non-zero integer. Zero itself is signless (...
14
votes
17answers
2k views

Test if given number if 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 ...
13
votes
11answers
2k views

Compute the first N digits of e

Challenge Write a program to compute the the first N (<= 10^3) digits of e. Your program should take an integer N as input. Input: 100 Output: ...
12
votes
1answer
530 views

Sunrise and sunset

I'm a bit of a romantic, I love taking my wife out to see the sunrises and sunsets in the place we are located. For the sake of this exercise let's say I don't have code that can tell me the time of ...
12
votes
9answers
724 views

Find the repetend of the decimal representation!

In this challenge 2 years ago, we found the period of a unit fraction (1/n where n is a natural number). Now, your task is to write a program/function to find the ...
11
votes
16answers
694 views

Divisor sum from prime-power factorisation

The task is to compute the divisor sum of a number given its prime factorisation. Input Two arrays (or something equivalent) of length n, one containing the prime factor and the other containing the ...
11
votes
10answers
744 views

Arithmetic Progressions

Your task is to analyse the input and output the formula for the n-th term if it is an arithmetic sequence, otherwise it should print "NAAP". Input Input (from STDIN) will consist of few numbers, ...
10
votes
6answers
311 views

Binary Recurrence Sequences

A binary recurrence sequence is a recursively-defined sequence of the following form: This is a generalization of the Fibonacci (...
10
votes
4answers
1k views

Polynomial Long Division

Implement polynomial long division, an algorithm that divides two polynomials and gets the quotient and remainder: (12x^3 - 5x^2 + 3x - 1) / (x^2 - 5) = 12x - 5 R 63x - 26 In your programs, you will ...
9
votes
1answer
443 views

The working time calculator

This is based on how my company deals with the monitoring of the working times for every employee. Each one of us has a card that can be passed in front of a sensor, so that a clock registers the ...