Questions tagged [arithmetic]
Challenges related to elementary arithmetic.
548 questions
14
votes
17
answers
1k
views
Compute the NFL passer rating
Each quarterback in the NFL is given a passer rating at the end of the game, which measures how good their forward passes were. It is not strictly a basic arithmetic formula, and is calculated as ...
3
votes
4
answers
253
views
Fill in the blanks of this equation
Your task is to write a program or function that can fill in the blanks of an equation provided in this form:
_ + _ / _ = 4
In this case, a valid solution would be:
2 + 8 / 4 = 4
Each blank must be ...
12
votes
22
answers
1k
views
Find all unique quintuplets in an array that sum to a given target
Inspiration: Leetcode's [3Sum] link
Problem
Given an array nums of n (not necessarily distinct) integers, and given a target ...
8
votes
7
answers
850
views
Complex Exponentiation [closed]
As the title says! Raise one complex number to the power of another.
(a+bi)^(c+di)(using the principal branch of the complex logarithm)
Requires four inputs a, b, c, d. You can combine a, b, c, d into ...
20
votes
24
answers
2k
views
Infer pluses and minuses
The problem
Consider an equation such as "3 ± 2 ± 4 ± 1 = 4" and determine if there exists a sequence of pluses and minuses that makes it arithmetically correct. If it exists, ...
-3
votes
8
answers
1k
views
Number of cigarettes that can be made from a given number of butts
Assumption
A cigarette can be made by combining four cigarette butts. Cigarette butts last infinitely until smoked.
Explanation
Say you have 31 butts. That means, you can make 7 cigarettes from 28 ...
11
votes
12
answers
2k
views
Solve a squared cryptarithm
Inspired by Greg Martin's "Shiny cryptarithm" puzzle.
A cryptarithm is a game consisting of a mathematical equation among unknown numbers, whose digits are represented by letters of the ...
20
votes
14
answers
2k
views
Number of ways to partition n into n = K + ꓘ
In this challenge you are asked to find in how many ways we can express a positive integer n as the sum of two positive integers ...
26
votes
14
answers
4k
views
80% of respondents agreed…
Sometimes I see a claim like "80% of respondents agreed" and I think "what was your sample size? 5?" because, of course, with a sample size of 5 it's possible to get 80% to agree ...
13
votes
21
answers
4k
views
German pharmacy payment
Your task is to calculate the amount you have to pay for prescribed medication at a pharmacy in Germany. The amount is simply based on the full price of the item, which will be your input. It is a ...
24
votes
23
answers
4k
views
American odds to probabilities
American odds (aka moneyline odds) are numbers like \$+150\$ or \$-400\$ used to express how much a winning bet would pay out. Convert odds to a fair win probability like this:
Positive odds \$+n\$ ...
9
votes
11
answers
913
views
Otteretto Classic game scoring method
Brief description of the game
In the game Otteretto Classic (which you can test directly in your browser; try it!) the player has to form palindromic sequences using adjacent cells on a square grid. ...
44
votes
18
answers
3k
views
Compare Two Fractions With ASCII Art
Challenge
Write a program or function that takes in 4 non-negative integers, A, B, C, and D, that represent two fractions, A/B and C/D, where B and D are non-zero and A <= B and C <= D.
Output ...
22
votes
26
answers
4k
views
Given 4 fence lengths, what's the largest rectangular yard you can make?
Here's a very simple little problem that I don't believe has been asked before.
Challenge
Write a program or a function that takes in four positive integers that represents the lengths of movable but ...
24
votes
5
answers
3k
views
Add two real numbers ... probably
The problem statement here is pretty simple, take two real numbers on the range [0,1) as input and output their sum, with probability 1.
The catch here is that there are a lot of real numbers. There ...
15
votes
81
answers
4k
views
Summing the Digits of a Number
Challenge
Given a non-negative integer, find the sum of its decimal digits.
Rules
Your program must take a non‐negative integer as input.
Your program should output the sum of the digits of the ...
12
votes
9
answers
2k
views
Parse basic arithmetic into an AST
Introduction
An abstract syntax tree (AST) is a tree of tokens that shows their connection to each other and syntactical meaning. They are commonly used in compilers and static analysis tools, as ...
16
votes
15
answers
2k
views
Division between two strings
Inverse function of this challenge
To (properly) multiply an string by an integer, you split the string into characters, repeat each character a number of times equal to the integer, and then stick ...
5
votes
21
answers
619
views
Iterate through addition of number sequence until a single digit [closed]
Challenge: With any given number that has multiple digits, every digit in the number needs to repeatedly be summed together until the sum is a single digit number. To make things interesting, if there'...
19
votes
25
answers
2k
views
Carry-less sum given a base b
Given a list of positive integers \$\mathcal I=I_1,I_2,I_3,...,I_n\$ and a base \$b>1\$ return their "carry-less sum", i.e. represent \$\mathcal I\$ in base \$b\$ and sum digit-by-digit ...
18
votes
22
answers
1k
views
Cartesian - polar conversion couple
We don't have a challenge for conversion between Cartesian and polar coordinates, so ...
The challenge
Write two programs (or functions) in the same language:
one that converts from polar to ...
19
votes
9
answers
1k
views
Cryptic Multiplications
Given two non-negative integers e.g. 27, 96 their multiplication expression would be 27 x 96 = 2592.
If now each digits is ...
2
votes
0
answers
439
views
Decompose number N into the sum of three triangular numbers [closed]
It is known that any natural number can be decomposed into the sum of three triangular numbers (assuming 0 is triangular), according to Fermat's Polygonal Number Theorem. Your task is to come up with ...
17
votes
17
answers
2k
views
Implement Binary Exponentiation
Background
In programming, there is a recursive algorithm called binary exponentiation, which allows for large integer powers to be calculated in a faster way. Given a non-zero base \$x\$ and a non-...
12
votes
17
answers
1k
views
Extract the contained powers of two!
Take as input an integer in any reasonable format.
Then, output all the proper sub-strings of the base-10 digits of that integer that are powers of two, in any reasonable format.
Test cases
...
5
votes
19
answers
2k
views
Palindromic Powers
Powers
We define an important power as a number that can be represented as \$ x^y \$ where \$ x ≥ 2 \$ and \$ y ≥ 2 \$.
Palindrome
We define an ...
17
votes
12
answers
3k
views
Random Point from a 2D Donut Distribution
A donut distribution (for lack of a better term) is a random distribution of points in a 2-dimensional plane, forming a donut-like shape. The distribution is defined by two parameters: the radius <...
9
votes
2
answers
385
views
No parentheses shall be omitted
This expression actually has an omitted pair of parentheses.
1 + 2 * 3
To make things clear, it should be,
1 + (2 * 3)
Even ...
15
votes
7
answers
3k
views
Make S + S + ... + S as Large as Possible!
Let \$S \subset \mathbb N_{\geq0}\$ be a subset of the nonnegative integers, and let $$
S^{(k)} = \underbrace{S + S + \dots + S}_{k\ \textrm{times}} = \{ a_1 + a_2 + \dots + a_k : a_i \in S\}.
$$
For ...
12
votes
6
answers
795
views
Khinchin's constant bad estimate
Inspired by How to write down numbers having an infinity of decimals? Link 🇫🇷
Background
From Wikipedia: for almost all real numbers \$x\$, coefficients \$a_i\$ ...
26
votes
27
answers
3k
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 ...
28
votes
12
answers
2k
views
Rows of the Collatz tree
Consider a binary tree built the following way:
The root node is \$1\$
For a given node \$n\$:
If \$n\$ is odd, its only child is \$2n\$
If \$n\$ is even, one of its children is \$2n\$. If \$\frac {...
19
votes
4
answers
812
views
Calculate the integer square root of a matrix
Let \$A\$ be a square matrix that is at least \$2 \times 2\$ where each element is an integer. \$A^2 = A \times A\$ will then have the same dimensions as \$A\$, and will have integer elements. For ...
15
votes
41
answers
2k
views
Index and return 3 characters
The challenge is simple: Read 3 letters from a system input¹ and convert them to numbers (A-1, B-2, C-3...Z-26)². Print each of those numbers in the order the ...
6
votes
6
answers
445
views
Blinking Lighthouses – Founder's Day Upgrade
To celebrate the island's next Founder's Day, colored filters (fuchsia, chartreuse, and aquamarine*) have been installed in every lighthouse. All lighthouses begin operation with their fuchsia filter,...
25
votes
11
answers
2k
views
Blinking Lighthouses
Lighthouses on an island have blink codes that let ships know which lighthouse they are seeing. Input should be strings of S and L. Here is a (Python) example of codes for 4 lighthouses as a list of ...
39
votes
15
answers
3k
views
Maximum number of squares touched by a line segment
Consider a square grid on the plane, with unit spacing. A line segment of integer length \$L\$ is dropped at an arbitrary position with arbitrary orientation. The segment is said to "touch" ...
19
votes
10
answers
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, \...
8
votes
3
answers
914
views
Crack the Lost Numbers
The Lost Numbers are 4, 8, 15, 16, 23, 42. Your goal is to create an expression to output them all.
Your allowed characters are 0123456789, ^+-*/, (), % for modulo and n as the single variable allowed....
7
votes
3
answers
241
views
Distribute the additions!
Challenge: Given an expressions made of additions and multiplications, output an expression that is a sum of products. The output must be equivalent to the input modulo the law of distribution. For ...
5
votes
10
answers
1k
views
Odds that a string of N digits contains two or more of the same
I have to fill in 2fa codes all day. They're 6-digit strings. One day I noticed that not once did any of these codes contain 6 unique digits, like 198532 There was always at least one double, like ...
28
votes
13
answers
3k
views
Collatz's ice cream cone factory
The Collatz sequence
Given a positive integer \$a_1\$, the Collatz sequence with starting value \$a_1\$ is defined as
\begin{equation}
a_{n+1} =
\begin{cases}
a_n/2 & \mathrm{if}\ a_n\ \mathrm{is}\...
22
votes
14
answers
3k
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
6
answers
2k
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 ...
11
votes
21
answers
3k
views
Exciting Mario Kart Grand Prix - Minimize the point difference!
Introduction
When playing Mario Kart the other day, an interesting question popped up when a Grand Prix with my 2 roommates, 9 AI drivers and myself seemed to be fairly close and therefore exciting ...
14
votes
16
answers
846
views
Sum over an Interval [duplicate]
Inspired by this challenge, and similar to this and this.
After seeing these, I figured I would continue the trend as there was no inclusive/exclusive sum.
The goal here is to sum an interval of ...
1
vote
11
answers
415
views
Implement ΔList [duplicate]
Given a list of integers, such as {1, 4, 2, 8, 10}, TI-Basic's ΔList will determine the difference between every overlapping ...
17
votes
17
answers
3k
views
Number of coins needed to make change
Relatable scenario: I'm going to the store to buy a single item, but only have a $100k bill. As a result, I need exactly $99,979 in change, and in the fewest coins/bills possible because I'm quite ...
16
votes
19
answers
2k
views
Multiplicative Persistence #2
We had a challenge on Multiplicative Persistence here.
As a recap, to get a multiplicative persistence of a number, do these steps:
Multiply all the digits of a number (in base \$10\$)
Repeat Step 1 ...
15
votes
14
answers
2k
views
Verify the inequality!
Left in sandbox for at least 3 days.
I want to verify if this inequality is true:
for \$n\geq4\$, if \$a_1,a_2,a_3,\dots,a_n\in R_+\cup\{0\}\$ and \$\sum_{i=1}^na_i=1\$, then \$a_1a_2+a_2a_3+a_3a_4+\...