Questions related to elementary arithmetic.
21
votes
24answers
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 ...
26
votes
13answers
1k 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 ...
11
votes
5answers
481 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
268 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 ...
16
votes
12answers
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, ...
56
votes
8answers
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 ...
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
155 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
912 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
820 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, ...
26
votes
11answers
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
460 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 ...
10
votes
49answers
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 ...
34
votes
35answers
2k 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
367 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
296 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
294 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
181 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
649 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 ...
28
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
252 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 ...
21
votes
14answers
1k 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
23answers
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
782 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
456 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
341 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
145 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, ...
11
votes
4answers
186 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, ...
54
votes
26answers
1k views
Expand the number
You may remember in first or second grade using expanded form to learn about place value of numbers. It's easier to explain with an example, so consider the number 123. In expanded form it is ...
17
votes
8answers
658 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 x1 = 2, x2 = 1, the sequence begins like this:
2 1 3 4 7 11 18 29 47 76 123 ...
24
votes
6answers
3k views
1+1 = 10, 1+2 = 3
Write a function or program than can do simple arithmetic (addition, subtraction, multiplication and division) in both base 10 and base 2.
The function will take a mathematical expression as input, ...
17
votes
16answers
533 views
Output the Partial Products
In long multiplication, after multiplying the numbers, you are left with the partial products, in this challenge you will output those partial products.
Because long multiplication is long, to ...
22
votes
15answers
943 views
Co-primality and the number pi
Introduction
Number theory is full of wonders, in the form of unexpected connections. Here's one of them.
Two integers are co-prime if they have no factors in common other than 1. Given a number N, ...
19
votes
3answers
437 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 ...
15
votes
6answers
785 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 ...
28
votes
16answers
2k views
How much present did you get for Christmas?
Yes, how much, not how many...
As we all know, a large present is far better than a small one. Therefore, the value of the presents should always be measured in total volume, not number of presents, ...
9
votes
2answers
225 views
Solve a mathematical expression from alternating sides
Create a program that solves a mathematical expression using the elements from alternating sides of the expression. The way it’s done is, instead of reading from left to right, you read the first ...
46
votes
31answers
4k views
Alex-style Addition
Inspired by Alex's glorious Learn you an R for great good, we are going to humbly recreate Alex's "one true R program" -- but with a twist.
Alex-style Addition works like this -- it has a 90% chance ...
16
votes
9answers
555 views
Seven's Cycle Sum Sequence
Take a look at the sevens multiplication table from 7×0 to 7×9:
0, 7, 14, 21, 28, 35, 42, 49, 56, 63
If we just look at the digits in the one's place we get a permutation of the digits ...
10
votes
9answers
549 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, ...
33
votes
13answers
5k views
The sum is always 15
Write a program or function that takes an array of non-negative integers as input and outputs a set of vectors/arrays with the elements of the input array in order, split so that each vector sums up ...