Questions tagged [arithmetic]

Challenges related to elementary arithmetic.

Filter by
Sorted by
Tagged with
13
votes
7answers
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 ...
10
votes
5answers
555 views

Khinchin's constant bad estimate [closed]

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\$ ...
19
votes
20answers
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 ...
26
votes
12answers
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 {...
17
votes
4answers
557 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 ...
10
votes
32answers
1k 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
6answers
377 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,...
23
votes
8answers
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 ...
36
votes
15answers
2k 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
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, \...
8
votes
3answers
754 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....
5
votes
3answers
164 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
10answers
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 ...
-5
votes
7answers
227 views

Take the numbers 1 to 100, square them, and add all the even numbers while subtracting the odd ones [closed]

Description The task is simple enough: Take the numbers 1 to 100, square them, and add all the even numbers while subtracting the odd ones. It is taken from this blog post: R Coding Challenge: 7 (+1) ...
25
votes
12answers
2k 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}\...
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
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 ...
10
votes
21answers
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
16answers
388 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
11answers
231 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 ...
16
votes
16answers
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
19answers
1k 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 ...
12
votes
14answers
1k 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+\...
13
votes
8answers
703 views

Next to the middle

Given an array of integers, find "the next to the middle". The next to the middle is the smallest integer greater than the smallest among mean, median and mode of the given numbers, that is ...
9
votes
0answers
151 views

8 out of 10 programmers like countdown [duplicate]

Edit (Jan 24/2021): The original specification for the challenge had a few problems. Underneath the original text, I have added alternate conditions that were suggested by @caird-coinheringaahing (...
-1
votes
2answers
150 views

increment a binary number without arithmetic manipulations [closed]

Input: binary string Output: binary string that represents the binary input + 1 Example: Given 10111 as an input, output 11000 ...
30
votes
31answers
2k views

Ken Iverson’s Favourite APL Expression?

Ken Iverson, 1920–2020 Let's implement his favourite expression: Given a row of Pascal's triangle, compute the next row. This can for example be computed by taking the input padded with a zero on the ...
30
votes
50answers
4k views

Multiply or Divide by n

Here's a simple challenge, so hopefully lots of languages will be able to participate. Given a positive integer \$n\$, output \$A076039(n)\$ from the OEIS. That is, start with \$a(1)=1\$. Then for \$n&...
-1
votes
1answer
184 views

Square root of a base 10 positive integer, digit by digit [closed]

It is possible (Wikipedia reference) to compute the square root of any number in a digit by digit fashion using a simple (I had learned it in primary school) algorithm. Challenge: read a positive ...
14
votes
8answers
2k views

We're much closer than you think

Martin Ender's 2D programming language Alice has two different modes depending on what orientation the IP has: orthogonal (Cardinal mode) or diagonal (Ordinal mode). Commands in Alice change their ...
30
votes
7answers
4k views

Shortest "arithmetic" formula to output 1000 primes

Write a formula using only the digits 0-9, +, *, -, <...
15
votes
16answers
1k views

Concatenations of powers and their squares

At time of writing, my reputation is \$16,256\$. As I noted in chat, Oh cool my rep is the concatenation of two powers of 2: 16,256 Or even the concatenation of a power of 2 and its square, which is ...
40
votes
106answers
6k views

The vanilla factorial challenge

Task Given a non-negative integer \$n\$, evaluate the factorial \$n!\$. The factorial is defined as follows: $$ n!=\begin{cases}1 & n=0\\n\times(n-1)!&n>0\end{cases} $$ Rules All default I/...
1
vote
19answers
728 views

Find your dog's age

Task Take the (integer) number of human years that the dog has lived, \$n\$, as input and return its age in dog years, \$d\$, to two decimal places. The number of human years, \$n\$, will be between \$...
19
votes
12answers
2k views

Slowing Down Sped Up Videos

Summary Videos which are sped up every time a particular word is said exist for everything from the Bee Movie to the classic Rick Roll. The goal for this challenge is to figure out how much you'd have ...
28
votes
55answers
3k views

Sum the array times n, except the last

I've been posting relatively hard challenges recently, so here goes an easy one. Task Given an array \$A\$ and a number \$n\$, calculate the sum of all numbers of \$A\$ multiplied by \$n\$, except the ...
42
votes
5answers
4k views

Compute xkcd's Wrong Times Table

The 2020-05-29 xkcd comic showed us the numbers that Randall Munroe feels would be most likely to result from multiplication, other than the correct answers. The table does seem to have some sort 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 ...
9
votes
8answers
661 views

Perfect scores in Martian rules football

Story Martians have been observing Aussie rules football matches from space with great curiosity. Having totally fallen in love with the game, they have been inspired to start their very own football ...
-2
votes
1answer
77 views

How to find the original value based on modulus/reminder and some other information [closed]

This might be a very basic question in terms of math, x % constant = x_modulus (x + some_number) % constant = y_modulus Given the value of ...
9
votes
1answer
291 views

Multiplication algorithm on a 4004

So I was playing around with this emulator of the Intel 4004 and decided I wanted to set a challenge for myself. The first use for the 4004 was in a calculator, so I decided that I would try to code ...
24
votes
11answers
2k views

Generate A065825

(This is A065825.) The sequence defaults apply, so you can pick another format other than this one. Given an input integer n, find the smallest number ...
17
votes
9answers
2k views

Euler's Geometry Puzzle

Today (or tomorrow, depending on your timezone, by the time of posting) is the birthday of the great mathematician and physicist Leonhard Euler. To celebrate his birthday, this challenge is about one ...
13
votes
6answers
823 views

Boil eggs using hourglasses

These are the classical puzzles: You need to boil eggs for exactly 9 minutes, or else the visiting Duchess will complain, and you will lose your job as head chef. But you have only 2 Hourglasses, one ...
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 ...
37
votes
50answers
3k views

(RGS 1/5) Binary multiples

A binary multiple of a positive integer k is a positive integer n such that n is written ...
39
votes
13answers
3k views

Phony fractions

Context If a0 and b0 are two decimal numbers, with a and ...
2
votes
5answers
182 views

Shift the digits [closed]

Here, x (supplied as input) and n (the result of your computation) are both positive integers. n * x = n shifted. Find n. Here's an example of shifting: ...
12
votes
9answers
1k views

Integer Logarithm

Objective Take \$a \in ℤ_{>1}\$ and \$b \in ℤ_+\$ as inputs. Write a function \$f\$ such that: $$ f(a,b) = \left\{ \begin{array}{ll} \log_ab & \quad \text{if} \space \log_ab \in ℚ \\...
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: ...

1
2 3 4 5
11