Questions tagged [math]

The challenge involves mathematics. Also consider using more specific tags: [number] [number-theory] [arithmetic] [combinatorics] [graph-theory] [geometry] [abstract-algebra] [integer].

Filter by
Sorted by
Tagged with
11
votes
32answers
4k views

Generate Sexy Primes

Sexy Primes are pairs of numbers (n, m) such as n and m both are prime, and ...
10
votes
1answer
549 views

Evaluate expressions with significant figures

Given an expression, your task is to evaluate it. However, your answer cannot show more digits than necessary, as this gives the impression of having more precise measurements than reality. The ...
9
votes
3answers
768 views

Print the intersection of sequences

Sequences You are given four number sequences, numbered 1 through 4. OEIS The location of 0...
7
votes
2answers
279 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 ...
4
votes
8answers
7k 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 ...
3
votes
13answers
3k views

Transpose a 3x3 matrix across the anti-diagonal

Write a program which takes a 3x3 matrix on stdin and prints its transpose along the anti-diagonal to stdout. You may assume that all elements of the matrix will be integers. Columns are space-...
2
votes
3answers
304 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 ...
30
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 ...
23
votes
23answers
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. ...
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 ...
20
votes
13answers
2k views

Gamma Function Golf

Given a real number t in (-10^9,13) (not including -10^9 or ...
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-...
19
votes
16answers
1k views

(RGS 4/5) Inverting matrices modulo m

Task Given an integer matrix M and a modulus m, find an inverse of M modulo ...
18
votes
22answers
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
23answers
1k views

Enumerate Derangements

Given some positive integer \$n\$ generate all derangements of \$n\$ objects. Details A derangement is a permutation with no fixed point. (This means in every derangement number \$i\$ cannot be in ...
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 ...
16
votes
3answers
355 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
15answers
968 views

Fun With Permutations

Who doesn't absolutely love permutations, right? I know, they are amazing––so much fun! Well, why not take this fun and make it funner? Here's the challenge: Given an input in the exact form: ...
15
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
4answers
402 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, ∗) ...
13
votes
6answers
423 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 ...
13
votes
4answers
1k views

How NOT to reduce fractions

Reducing fractions the wrong way In this code-golf challenge you have to find fractions that can be reduced the wrong way but still end up in the same number. Note: reducing fractions the wrong way ...
13
votes
13answers
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
570 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
17answers
747 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 ...
12
votes
2answers
3k views

Test if a given number is a Vampire Number [duplicate]

EDIT: In the interest of increasing the complexity, i've added more to the challenge. In mathematics, a vampire number (or true vampire number) is a composite natural number v, with an even ...
10
votes
10answers
826 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
362 views

Binary Recurrence Sequences

A binary recurrence sequence is a recursively-defined sequence of the following form: $$F(1) = a_1 \\ \vdots \\ F(y) = a_y \\ F(n) = \alpha F(n-x) + \beta F(n-y), n > y$$ This is a generalization ...
9
votes
1answer
468 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 ...
8
votes
2answers
283 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 <...
6
votes
4answers
2k views

Calculate e^x and ln(x)

Given a floating point x (x<100), return e^x and ln(x)...
5
votes
13answers
1k views

Linear Independence

Given a set of vectors all of the same positive finite dimension, output a falsey value if they are linearly dependent and a truthy value if they are linearly independent. A set of vectors v1, v2, ... ...
2
votes
1answer
185 views

Advent Challenge 7: Balance the storage carts!

<< Prev Next >> After some careful analysis, Santa was able to determine the dock size ranges and get the presents into the correct transportation dock. Now, he needs you to help him balance ...
0
votes
1answer
297 views

Calculate the a ^ b WITHOUT using *, / and ^ [duplicate]

Challenge Your goal is, given two positive integer numbers a and b, to calculate (and output) a ^ b without using either multiplication, division and the power itself (not directly, at least). And, of ...
-1
votes
1answer
534 views

Find the square root, BUT [closed]

Write a square root function that takes an input, positive or negative, and calculate it's square root, correct up to six decimal places (then truncate after the sixth decimal place). But, you cannot ...
-6
votes
20answers
803 views

XOR reduction bools

Description : Given a string of space separated binary digits or space separated booleans or an array of binary digits or array of booleans . Your job is to find the xor of each until you end up with ...
124
votes
11answers
12k views

(-a) × (-a) = a × a

We all know that \$(-a) \times (-a) = a \times a\$ (hopefully), but can you prove it? Your task is to prove this fact using the ring axioms. What are the ring axioms? The ring axioms are a list of ...
184
votes
54answers
29k views

Mathematics is fact. Programming is not

In mathematics an exclamation mark ! often means factorial and it comes after the argument. In programming an exclamation mark ! ...
65
votes
10answers
5k views

How lit is this mountain? 🔥

A mountain is defined to be a set of line segments whose first point has coordinates (0,a) where a > 0, and whose last point ...
46
votes
5answers
2k views

Multiply with restricted operations

There's a 500 rep unofficial bounty for beating the current best answer. Goal Your goal is to multiply two numbers using only a very limited set of arithmetic operations and variable assignment. ...
47
votes
20answers
10k views

Draw/plot a heart graph

Your challenge is to draw/plot one of the hearts below. The size must be at least 50x50 pixels (vector graphics is OK). You may choose which of the hearts you want to draw/plot. Axes, grid lines etc. ...
34
votes
6answers
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 ...
47
votes
18answers
5k views

Knight on the Rim is Grim

Introduction Aron Nimzowitsch was a leading chess master and a influential chess writer. In his book 'My System', the first chapter deals about the importance of the center and why you should dominate ...
34
votes
5answers
8k views

Historical difference between `/` and `÷` in mathematical expressions

Introduction: Inspired by a discussion that is already going on for many years regarding the expression \$6÷2(1+2)\$. With the expression \$6÷2(1+2)\$, mathematicians will quickly see that ...
56
votes
10answers
10k views

Little Chandler is sad. Draw him a cloud to cheer him up

Little Chandler is sad. Draw him a cloud to cheer him up. Note: Drawing a cloud won't actually cheer him up. A circle can be defined as a 3-tuple (x,y,r) where <...
50
votes
37answers
4k views

How many steps does it take from n to 1 by subtracting the greatest divisor?

Inspired by this question over at Mathematics. The Problem Let n be a natural number ≥ 2. Take the biggest divisor of ...
50
votes
66answers
11k views

Divide a number by 3 without using *, /, +, -, % operators [closed]

Quoting this question on SO (Spoiler alert!): This question has been asked in an Oracle interview. How would you divide a number by 3 without using *, /, +, -, %, operators? The number ...
43
votes
32answers
4k views

Define a function f such that f(f(n)) = -n for all non-zero integers n

This challenge was inspired by a programming blog I frequent. Please see the original post here: A Programming Puzzle Challenge Define a function \$f:\mathbb{Q}\to\mathbb{Q}\$ such that \$f(f(n)) = -...
41
votes
38answers
7k views
+500

Shift right by half a bit

The challenge is to implement a program or function (subsequently referred to as "program") that takes a nonnegative integer \$n\$ as input and returns \$n\over\sqrt{2}\$ (the input divided by the ...
37
votes
5answers
1k views

Overcoming cluster size

Fed up with the reliability of flash storage, you decided to store all your programs on one of those good old 1,440 KiB floppies. However, after copying not even 3,000 programs, the disk was full. How'...

1
3 4
5
6 7
11