Questions related to elementary arithmetic.

learn more… | top users | synonyms

24
votes
23answers
666 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 ...
8
votes
7answers
242 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 ...
7
votes
6answers
397 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
265 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
326 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
579 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 ...
14
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, ...
6
votes
2answers
220 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
379 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
854 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 ...
2
votes
3answers
245 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 ...
22
votes
36answers
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
25answers
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 ...
12
votes
7answers
729 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
284 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 ...
13
votes
11answers
583 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
163 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' ...
24
votes
5answers
918 views

Write a Morse Calculator

Write a program or function that takes a mathematical expression in Morse code as input, and returns the solution in Morse code. Valid operations are plus: + and minus: _ (underscore). You can assume ...
20
votes
9answers
839 views

Highly composite numbers

A highly composite number is a positive integer that has more divisors than any smaller positive integer has. This is OEIS sequence A002182. Its first 20 terms are 1, 2, 4, 6, 12, 24, 36, 48, 60, ...
27
votes
12answers
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 n i.e. a decimal number that starts with all 1's and ends with all 0's. ...
13
votes
6answers
462 views

Find the optimal sliding door width

Sliding doors have varying prices based on the width of the doors. The different prices are as follows: 60 - 80 cm: ¤150 81 - 100 cm: ¤200 101 - 120 cm: ¤220 When buying a closet you would ...
11
votes
54answers
4k views

Golf the xᵗʰ root of x

While bored in high-school (when I was half my current age...), I found that f(x) = x(x-1) had some interesting properties, including e.g. that the maximum f for 0 ≤ x is f(e), and that the binding ...
35
votes
37answers
3k views

Print N Squared

Write a program or function that takes in a non-negative integer N from stdin or as a function argument. It must print or return a string of a hollow ASCII-art square whose sides are each made with N ...
8
votes
4answers
370 views

How drunk am I and when can I drive again?

It's weekend and what are the cool guys doing on weekends? Drinking of course! But you know what's not so cool? Drinking and driving. So you decide to write a program that tells you how loaded you are ...
11
votes
15answers
302 views

Congruence Relations

Given 3 positive integers a, b, and n (whose maximum values are the maximum representable integer value in your language), output a truthy value if a ≡ b (mod n), and falsey otherwise. For those ...
15
votes
3answers
302 views

Arbitrary Precision Integer Division

We will be implementing division for arbitrarily large integers. This is code-golf. The task is to write a program or function that implements arbitrary precision integers and Division on them. ...
12
votes
4answers
182 views

Help recalculate your rep!

A couple months ago, we had a discussion on meta about increasing the reputation awarded for upvotes on questions. Here's the basics of our current reputation system for votes:1 A question upvote U ...
13
votes
7answers
658 views

Recursive 2x2 determinant

The determinant of a 2 by 2 matrix a b c d is given by ad - bc. Given a matrix of digits with dimensions 2n by 2n, n ≥ 1, output the result obtained by recursively computing the determinant of ...
29
votes
18answers
3k views

Sort by Multiplying

You should write a program or function that given a list of positive integers multiplies each element with the smallest positive integer possible to create a strictly increasing list. For example if ...
9
votes
3answers
257 views

Verify the birth number

A Norwegian Birth Number consists of 11 digits, composed the following way: DDMMYYiiikk DD is the day (from 01-31) MM is the month (from 01-12) YY is the year (from 00-99). It's not differentiated ...
17
votes
7answers
2k views

Who's gonna win the football game?

The American football championship, Super Bowl 50, is happening today at 11:30pm UTC (and you can watch it live online). This challenge was made to celebrate it. In an American football game, two ...
22
votes
25answers
2k views

Difference of three input integers

Implement a function diff that takes as input three integers x, y, and z. It should return whether subtracting one of these numbers from another gives the third. Test cases: diff(5, 3, 2) yields True ...
24
votes
18answers
2k views

Inverse function

Wouldn't it be neat if programming functions could be inverted, just like the mathematical function they implement? Write a function (or program) that takes one input x in any form, that outputs ...
20
votes
33answers
3k views

Electrical outlet

This is a problem from NCPC 2005. Roy has an apartment with only one single electrical outlet, but he has a bunch of power strips. Compute the maximum number of outlets he can have using the power ...
25
votes
18answers
2k views

The RATS sequence

Your task is to generate the nth term of the RATS sequence, where n is the input. The RATS sequence is also known as the Reverse Add Then Sort sequence. This sequence can also be found here: ...
19
votes
25answers
2k views

Distance between two points in n-dimensional space

Here is another simple one: The Challenge Given two points in an n-dimensional space, output the distance between them, also called the Euclidean distance. The coordinates will be rational ...
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 ...
13
votes
3answers
790 views

Decipher the mathematical symbols

If you've read the book Contact by Carl Sagan, this challenge may seem familiar to you. Given an input of a set of mathematical equations consisting of a number, an unknown operator, another ...
22
votes
5answers
461 views

Fractal Smoke Sequence

Introduction A229037 has a quite intriguing plot (at least for the first few terms): There is the conjecture, that it might indeed have some kind of fractal property. How is this sequence ...
13
votes
8answers
346 views

Smooth a line graph

Given an input of an integer n and a list of positive integers m1, m2, ..., output a list of integers m1', m2', ... where mx' is defined as the average of mx-n through mx+n. When calculating these ...
14
votes
2answers
148 views

Add and multiply perplexing numbers

The split-complex numbers, also known as "perplex numbers" are similar to the complex numbers. Instead of i^2 = -1, however, we have j^2 = 1; j != +/-1. Each number takes the form of z = x + j*y. ...
23
votes
17answers
1k views

How many peaks in my mountain range?

A list of positive integers can be visualized as a quantized mountain range where each list entry represents the height of one vertical section of the mountains. For example, the list 1, 2, 2, 3, 4, ...
12
votes
4answers
247 views

Smooth vs. Chunky vs. Broken Squiggles

Based on Chunky vs. Smooth Strings. Squiggles /\_/\/\__/\/\/\/\_/\_/\ are fun to make on a keyboard when you are really bored. But not all squiggles are created equal. Some squiggles are smooth, ...