Questions tagged [arithmetic]

Challenges related to elementary arithmetic.

Filter by
Sorted by
Tagged with
22
votes
14answers
1k views

Calculate the bounded cumulative sum of a vector

The cumulative sum of a vector is calculated by simply taking the sum of all previous elements. For instance: ...
22
votes
14answers
1k views

Dirichlet Convolution

The Dirichlet convolution is a special kind of convolution that appears as a very useful tool in number theory. It operates on the set of arithmetic functions. Challenge Given two arithmetic ...
22
votes
6answers
1k views

Subtract the Folded Matrix

Challenge: Given an NxN matrix where \$N\geq2\$ and one of eight distinct 'folding options', output a 2D array/list with the subtracted values. The eight folding options are: left-to-right; right-to-...
22
votes
7answers
1k views

Shortest Addition Chain

An addition chain is a sequence of integers starting with 1, where every integer other than the initial 1 is a sum of two previous integers. For instance, here's an addition chain: ...
22
votes
5answers
2k views

Visualize long division with ASCII art

Write a program that visualizes long division with ASCII art. Input consists of two integers, a numerator and a denominator, using the input format of your choice. Examples: 1234 ÷ 56: <...
22
votes
8answers
1k views

Crazy Librarian's Amazing Sorting System

It's back to school season! So for a part-time job, you're helping out at the school's library. The problem is, the head librarian has never even heard the words "Dewey Decimal," let alone implemented ...
22
votes
2answers
473 views

Subset Sum Orderings

A set of n positive numbers has 2^n subsets. We'll call a set "nice" if none of those subsets have the same sum. ...
21
votes
32answers
3k views

Calculate Standard Deviation

Challenge Given a list of numbers, calculate the population standard deviation of the list. Use the following equation to calculate population standard deviation: Input The input will a list of ...
21
votes
33answers
2k views

Calculate the sum of ILD

Input: An integer Output: Sum of the input itself + the length of the input + each individual digit of the input. nr + nr-length + {sum of digits} = output ...
21
votes
38answers
2k views

Given an input, print all exponents where the base and power sum to the input

So this is my first challenge on this site. The challenge is to take in an input integer \$n\$, which will be positive, and print, in ascending order (\$1\$ to \$n\$, including n), the output of \$i^{...
21
votes
21answers
2k views

Hunt for discount

Story My local pizza delivery introduced new discount. You get 50% discount from every second item on your order. But being greedy capitalists, they forgot to mention that they will rearrange items ...
21
votes
23answers
3k views

Is q a quadratic residue of n?

Given two inputs q n determine if q is a quadratic residue of n. That is, is there an ...
21
votes
8answers
3k views

X+Y=Z - but in which base?

The Challenge Given 3 numbers X, Y and Z in base B, ...
21
votes
26answers
2k views

Start from ones

Given a strictly positive integer n, follow these steps: Create an array A with n 1s. If A only has one element, terminate. Otherwise, starting from the first element, replace each pair of A with its ...
21
votes
19answers
2k views

Pascal's Alternating Triangle

Pascal's triangle is generated by starting with 1 and having each row formed from successive additions. Here, instead, we're going to form a triangle by alternating ...
21
votes
13answers
1k views

What's the point?

Write a program or function that takes in two integers that represent the X and Y coordinates of a point on a Cartesian plane. The input may come in any reasonable format as long as the X value comes ...
21
votes
25answers
2k views

Power-Ending Patterns

When you look at the last decimal digit of each power of a non-negative integer a repeating pattern forms. For example, 3: ...
21
votes
12answers
2k 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 ...
21
votes
25answers
3k views

Ten-pin bowling score - World Bowling edition

World Bowling scoring Many people have gone to their local bowling center to play a few games of bowling, and many people continue to struggle to calculate their scores. World Bowling has introduced ...
21
votes
7answers
818 views

Outputting a base-proof expression

Background In some possible futures, the world will convert their numerical systems from decimal (base 10 or b10) to some other base (binary ...
21
votes
11answers
815 views

Sort a concatenated sequence

Consider a sequence based on recurrence relations, f(n) = f(n-1)+f(n-2), starting with f(1) = x1, f(2) = x2. For ...
21
votes
4answers
496 views

Compute height of Bowl Pile

Bowl Pile Height The goal of this puzzle is to compute the height of a stack of bowls. A bowl is defined to be a radially symmetric device without thickness. Its silhouette shape is an even ...
21
votes
2answers
675 views

Double a number's continued fraction

Your task is, given x, output 2*x. Easy right!? But there's a catch: x will be given as a (...
21
votes
3answers
724 views

Parenthesize an expression

Recently I've been writing a new language, to avoid needing to handle order of operations, I simply parenthesize each expression properly to avoid this entirely. Because parenthesis are at char-...
20
votes
72answers
2k views

Raise integer x to power x, without exponentiation built-ins

Task - The title pretty much sums it up: raise an integer x to power x, where 0<x. Restrictions: Use of exponentiation, ...
20
votes
19answers
4k views

Basic Calculator

You must write a program to evaluate a string that would be entered into a calculator. The program must accept input and output the correct answer. For languages that do not have standard input/...
20
votes
16answers
739 views

Sigmafy the expression

For those who didn't know, Sigma is a Greek letter which is heavily used in mathematics as the summation sign. Given a string representing an expression depending on \$k\$ that we will denote \$E(k)\$...
20
votes
13answers
2k views

Make a "proof" generator

Introduction How to prove that 1 = 2: 1 = 2 2 = 4 (*2) -1 = 1 (-3) 1 = 1 (^2) You can just multiply both sides by 0, but that's cheating. This is just bending the ...
20
votes
26answers
2k views

Given a number, print out its "collective sum"

Given a number as input, print out its collective sum What is a collective sum? Consider the number 13214, the input Looping through each of the digits starting ...
20
votes
20answers
1k views

Make two numbers co-prime while preserving their least common multiple

Given two positive integers a and b, output two positive integers c and ...
20
votes
21answers
2k views

Length of String Using Set Theory

From Wikipedia Set-theoretic definition of natural numbers The set N of natural numbers is defined as the smallest set containing 0 and closed under the successor function S defined by S(n) = n ∪ ...
20
votes
12answers
2k views

Evaluating Parentheses and Brackets as Integers

Write a program that takes in a string of the four characters ()[] that satisfies these points: Every left parenthesis ( has a ...
20
votes
13answers
1k views

LCM of Rational Numbers

The least common multiple (LCM) of a set of numbers A is the smallest integer b such that b/a...
20
votes
9answers
2k views

Dead code elimination

Dead code sits there doing nothing, staring at us knowing it will never be executed... but today we can take revenge. Specification The input will be a multiline string. Each line may either be an ...
20
votes
6answers
926 views

D&D point buy cost

When making a Dungeons & Dragons character, an alternative to rolling ability scores is to assign them within a power budget called point buy. Higher ability scores cost more points, especially ...
20
votes
6answers
1k views

Inserting digits to satisfy equation

You are given 3 non negative numbers: \$x\$, \$y\$ and \$z\$, and must minimize the number of digits (non negative) inserted at any place in the numbers \$x\$, \$y\$, or \$z\$ to make $$x + y = z$$ (a ...
20
votes
5answers
1k views

Golfing out the haters

The setup: A social network reports the number of votes a post has in two ways: the number of net upvotes (total upvotes - total downvotes), and the % of votes that were upvotes, rounded to the ...
20
votes
13answers
912 views

Zipper multiplication

Introduction Let's define a new arithmetical operation, which I call zipper multiplication. To zipper multiply two nonnegative integers, you add leading zeros to make the lengths match, multiply the ...
20
votes
11answers
983 views

Linear interpolation of the Fibonacci sequence

Your task is to find the nth Fibonacci number, but n is not necessarily an integer. The Fibonacci sequence, 0-indexed, goes as follows: ...
19
votes
30answers
3k views

Opposite of the digital root!

Also known as the [analog root] (Opposite of the digital root!) ;) The digital root of a number is the continuous summation of its digits until it is a single digit, for example, the digital root of ...
19
votes
53answers
3k views

Check if an array (or equivalent) has the same number of odd and even numbers - Code Golf Edition!

Inspired by this code review question, I am curious to see what happens if we turn that into a code-golf challenge! The description is easy, the input is an array or any similar data structure with ...
19
votes
18answers
6k views

Center of Mass from a list of coordinates and their masses

Here is a quick Monday morning challenge... Write a function or program in the least number of bytes that: Takes as input a list of [x,y] coordinates Takes as ...
19
votes
20answers
2k views

Arithmetic mean of prime Fibonacci Numbers up to the x Fibonacci Number

You should have heard about the Fibonacci Numbers, often called the Fibonacci Sequence. In this sequence the first two terms are 0 and 1, and every number after the first two is the sum of the two ...
19
votes
20answers
2k views

The Written Digits Sequence

Here's a reasonably trivial sequence which is not in the Online Encyclopedia of Integer Sequences. Start with an empty sequence then define each term as the number of characters required to write out,...
19
votes
16answers
3k views

Divisible by 1000003? Easy, just multiply the last digit by 300001 and add!

Given a prime P greater than 10, your program or function must figure out its divisibility rule ...
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 ...
19
votes
15answers
1k views

Spot all (anti)diagonals with duplicated values

Challenge: Given a matrix input, determine the amount of diagonals and anti-diagonals with duplicated numbers. So if we have a matrix like this: ...
19
votes
6answers
2k views

Contradictory Polyglots

Well, everyone loves Polyglots. You will be given two integers, in any standard form of input (no hardcoding). Your task is to write a polyglot which finds the minimum value in a language and the ...
19
votes
10answers
1k views

Ploughed fields via moduli

Let \$R, C\$ be positive integers and let \$0 < s \leq 1\$. Consider the \$R \times C\$ matrix \$\mathbf M\$ defined as \begin{equation} M(i,j) = \frac{\mathrm{mod}\,(j, i^s)}{R^s}, \quad i = 1, \...
19
votes
20answers
2k views

Find the n-th perfect power!

A perfect power is a number of the form \$a^b\$, where \$a>0\$ and \$b>1\$. For example, \$125\$ is a perfect power because it can be expressed as \$5^3\$. Goal Your task is to write a program/...

1
3 4
5
6 7
11