Questions related to elementary arithmetic.

learn more… | top users | synonyms

0
votes
15answers
173 views

Given two numbers, output their sum

Input: Two decimal integers, in the form m n. The separator between the integers may be any whitespace character. They can be given as standard input or as arguments to the program or function. ...
14
votes
20answers
1k 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 item. nr + nr-length + {sum of individual digits} = output For example: Input: 99 ...
9
votes
10answers
710 views

Choose from an existing set of weights to make a target sum

When doing weightlifting, I want to make a specific weight by attaching several plates to a bar. I have the following plates: 6 plates of 1 kg each 6 plates of 2.5 kg each 6 plates of 5 kg each 6 ...
22
votes
14answers
2k views

Simplify a square root

Given a positive integer n, simplify the square root √n into the form a√b by extracting all square factors. The outputted a,b should be positive integers with n = a^2 * b with b as small as possible. ...
10
votes
3answers
260 views

Ways to get to the number

Given the input of the first number and the second number (both positive integers, zero exluded), determine in how many ways could you make the second out of the first, using following actions: +1,+2 ...
18
votes
26answers
2k views

Count Up, Replace, Repeat!

Definition Define the nth array of the CURR sequence as follows. Begin with the singleton array A = [n]. For each integer k in A, replace the entry k with k natural numbers, counting up from 1 to k....
7
votes
4answers
223 views

Count, Replace, Add Up! [duplicate]

Definition Define the nth term of the CRAU sequence as follows. Begin with the singleton array A = [n]. Do the following n times: For each integer k in A, replace the entry k with k natural ...
28
votes
37answers
2k views

Difference of the square of the sum

Find the difference between the square of the sums and sum of the squares. This is the mathematical representation: (∑n)^2-∑n^2 Your program/method should take two inputs, these are your lower ...
30
votes
22answers
2k views

Leyland Numbers

Given a natural number n, return the n-th Leyland number. Leyland Number Leyland numbers are positive integers k of the form k = x^y + y^x Where x,y are integers strictly greater than 1. They ...
2
votes
29answers
4k views

The handshake problem

The handshake problem is the classic problem that for n people in a room, if they all shake hands, what's the total number of handshakes that occur. You code should take an input of any number and ...
7
votes
8answers
476 views

Excludivisible numbers

Given an integer N, output the Nth positive number K with the following property in decimal base: For each digit I at position P of K, the number formed from K by removing the Pth digit (i.e. I) is ...
10
votes
3answers
353 views

A Hundred Squares!

Back to basics... As a teacher at the local primary (grade?) school, you need a way to teach your class their times tables. At your disposal, you have hundred squares and a load of red pens. You need ...
35
votes
28answers
7k views

Weapons of Math Instruction

Last time when I tried to come up with something easy that wasn't a duplicate, it ended up being way too hard.. So hopefully this time it's indeed something newcomers can try as well. Input: An ...
28
votes
15answers
2k views

Turn an Array into a Math Problem

Given a nonempty list of nonnegative integers, consider rewriting it as an arithmetic problem where: A plus sign (+) is inserted between pairs of numbers that increase from left to right (a.k.a. ...
23
votes
21answers
1k views

Sum It Up with a Digital Triangle

Well, sum it down really. Write a program or function that takes in a nonempty list of decimal integers (0-9) and outputs a downward pointing "triangle" of digits with the input list at the top where ...
9
votes
3answers
264 views

Simplify a Date

This is similar to simplifying fractions, but with Dates! The input of your program must be of the form mm/dd For example 3/4 //March 4 12/15 //December 15 1/1 // January 1 We assume that the ...
35
votes
16answers
3k views

Has My Pie Been Bisected?

Write a program or function that takes in a nonempty list of positive integers. You may assume it is input in a reasonable convenient format such as "1 2 3 4" or [1, 2, 3, 4]. The numbers in the ...
16
votes
10answers
765 views

Jam don't add like that

Background Jelly's arithmetic atoms vectorize automatically. In fact, x + y is well-defined whenever x and y are numbers or ragged arrays of numbers. Jelly's source code implements this behavior ...
22
votes
27answers
2k views

Find the smallest number bigger than the input whose digital sum is the input

"Digital sum" refers to the sum of all the digits in a number. For example, the digital sum of 1324 is 10, because 1+3+2+4 = 10. The challenge is to write a program/function to calculate the ...
18
votes
28answers
3k views

24 and 12 Hour Times

Write a program or function with no input that prints or returns this string of 24-hour and 12-hour times: 00:00 12:00am 01:00 1:00am 02:00 2:00am 03:00 3:00am 04:00 4:00am 05:00 5:00am 06:00 6:...
-2
votes
2answers
154 views

Restricted average (arithmetic mean) – i.e. without obvious built-ins [closed]

Introduction The arithmetic mean is defined as being equal to the sum of the numerical values of each and every observation divided by the total number of observations. Symbolically, if we have a ...
6
votes
6answers
177 views

Find how many pair elements sums up to N [closed]

Based on a recent question in StackOverflow Write a program/function that takes in one ARRAY/list and returns the number of pair-values which sums up to a given TOTAL. Explaining TOTAL=4, ARRAY=[1,...
42
votes
27answers
3k 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 n – which is different from n itself – and subtract it from n. Repeat until ...
4
votes
6answers
468 views

Traveling on a flat Earth

Coordinates in the flat-Earth world consist of latitude (x) and longitude (y), which are integers in the range 0...9999. Much like Gaussian integers, but they are always written using this notation: ...
14
votes
15answers
920 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/function that ...
6
votes
15answers
300 views

Find the positive divisors!

Definition A number is positive if it is greater than zero. A number (A) is the divisor of another number (B) if A can divide B with no remainder. For example, 2 is a divisor of 6 because 2 can ...
30
votes
33answers
3k views

Compute the Adler-32 checksum

Background Adler-32 is a 32-bit checksum invented by Mark Adler in 1995 which is part of the widely used zlib library (also developed by Adler). Adler-32 is not as reliable as a 32-bit cyclic ...
9
votes
7answers
285 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 repetend of a unit fraction. The ...
8
votes
6answers
438 views

Calculate the Kronecker sum of two matrices

In the examples below, A and B will be 2-by-2 matrices, and the matrices are one-indexed. A Kronecker product has the following properties: A⊗B = A(1,1)*B A(1,2)*B A(2,1)*B A(2,2)*B ...
8
votes
3answers
280 views

One-to-one correspondence between pairs of integers and the positive integers

It is well-known that there are one-to-one correspondences between pairs of integers and the positive integers. Your task is to write code defining such a correspondence (by defining a pair of ...
8
votes
8answers
334 views

m-nomial coefficient

While binomial coefficient is the coefficient of (1+x)**n, m-nomial coefficient is the coefficient of (1+x+x**2+...+x**(m-1))**n. For example, m(3,5,6) is the coefficient of x**6 in the expansion of (...
7
votes
9answers
606 views

How many minimum days will he take to complete N units of work?

A person has to complete N units of work; the nature of work is the same. In order to get the hang of the work, he completes only one unit of work in the first day. He wishes to celebrate the ...
15
votes
33answers
2k views

Sum the odd square numbers less than N

Write a program or function to output the sum of the odd square numbers (OEIS #A016754) less than an input n. The first 44 numbers in the sequence are: 1, 9, 25, 49, 81, 121, 169, 225, 289, 361, 441,...
6
votes
2answers
278 views

Federal income tax calculator for procrastinators

Today is Tax Day! Oops. Well, today is tax day if you are a resident of Maine or Massachusetts. So you're probably still completing your return and need a calculator for when you get to Line 44. ...
10
votes
7answers
411 views

Convert to Roman Numeral!

Your task is to convert a given positive integer from Arabic numeral to Roman numeral. Things get difficult when you count to 4000. The romans did this by adding a line above a symbol to multiply ...
20
votes
14answers
883 views

Generate the minimal remainder sequence

Every number can be represented using an infinitely long remainder sequence. For example, if we take the number 7, and perform 7mod2, then 7mod3, then 7mod4, and so on, we get 1,1,3,2,1,0,7,7,7,7,.......
2
votes
3answers
251 views

Solve a quadratic equation using Vieta's formulas

Exposition Your mathematics teacher is a big fan of Vieta's formulas, and he believes that you should use them to solve quadratic equations. Given the equation ax^2 + bx + c = 0 the product of its ...
25
votes
39answers
2k views

Greatest Common Divisor

Your task is to compute the greatest common divisor (GCD) of two given integers in as few bytes of code as possible. You may write a program or function, taking input and returning output via any of ...
21
votes
27answers
2k views

The plus-minus sequence

The plus-minus sequence The plus-minus sequence is one that starts with two seeds, a(0) and b(0). Each iteration of this sequence is the addition and subtraction of the previous two members of the ...
27
votes
14answers
2k views

The Arithmetic Derivative

The derivative of a function is a cornerstone of mathematics, engineering, physics, biology, chemistry, and a large number of other sciences as well. Today we're going to be calculating something only ...
13
votes
8answers
765 views

Express a number with only 0-9 and the four operations

Explanation Befunge is a two-dimensional program that uses stacks. That means, to do 5 + 6, you write 56+, meaning: 56+ 5 push 5 into stack 6 push 6 into stack + pop the first two items in ...
-5
votes
20answers
301 views

Print the sum of the squares of some numbers

This is a little codegolf challenge from codingame.com. I was wondering how much Python3 code is necessary (but of course answers are not limited to Python3). Input The first line contains one ...
18
votes
6answers
2k views

X+Y=Z - but in which base?

The Challenge Given 3 numbers X, Y and Z in base B, find a B in which the addition of X and Y yields Z. The inputs x = 2 0, Y = 1 2 and Z = 3 2 could yield 5 because 2 0 + 1 2 = 3 2 in base 5. You ...
17
votes
13answers
2k views

A curious prime fraction formula

Given a positive integer n output the integers a and b (forming reduced fraction a/b) such that: Where pk is the k th prime number (with p1 = 2). Examples: 1 -> 3, 5 2 -> 12, 25 3 -> 144, ...
58
votes
9answers
4k views

Addition in base -1+i

Gaussian integers are complex numbers of the form a+bi where a and b are both integers. In base -1+i, all Gaussian integers can be uniquely represented using the digits 0 and 1, without the need for a ...
25
votes
37answers
7k views

Happy Rounded Pi Day

To celebrate Rounded Pi Day, you must take advantage of today's date to make a program that takes in a circle's diameter and outputs its circumference by multiplying the diameter by 3.1416, where 3....
13
votes
11answers
597 views

Minimum Scalar Product

Minimum Scalar Product The inspiration for this code golf problem is from Google's code jam competition. The premise behind the problem is, given the input of two vectors of varying lengths, find the ...
18
votes
12answers
2k views

Calculate the volume of an object

You can determine the volume of objects based on a given set of dimensions: The volume of a sphere can be determined using a single number, the radius (r) The volume of a cylinder can be determined ...
-5
votes
4answers
174 views

Solve an algebraic expression

The Challenge Your task is to create a program that can solve an algebraic equation. Input Input will consist of a String. The string will be an equality involving the variable x, and follows the ...
18
votes
16answers
2k 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 input a list of the [x,y] coordinates' ...