# Questions tagged [arithmetic]

Challenges related to elementary arithmetic.

543 questions
Filter by
Sorted by
Tagged with
3k views

### How far away is n to the next power of b?

Let n and b be positive integers larger than 1. Output the distance from ...
• 49.7k
5k views

### Fastest algorithm to take the product of all subsets

Given n numbers in an array (you can't assume they are integers), I would like to compute the product of all subsets of size n-1....
1k views

### LCM of Rational Numbers

The least common multiple (LCM) of a set of numbers A is the smallest integer b such that b/a...
• 13.8k
2k views

### How many carries do I need to add these two numbers?

Task Given two positive integers, output the number of carries needed to add them together in long addition in base 10. Examples ...
• 49.7k
2k views

### Climb a step to a prime

The title of Numberphile's newest video, 13532385396179, is a fixed point of the following function $f$ on the positive integers: Let $n$ be a positive integer. Write the prime factorization in ...
• 49.7k
805 views

### Counting N-bit integer multiplication overflows

Given a positive integer N, output the number of pairs of integers 0 <= a <= b < 2**N such that ...
6k views

### Is this number a repdigit?

Challenge A repdigit is a non-negative integer whose digits are all equal. Create a function or complete program that takes a single integer as input and outputs a truthy value if the input number is ...
• 1,495
5k views

### CSI: Minecraft Items

Minecraft 1.12 will be released tomorrow, so let's celebrate! Write code that takes in a non-negative integer N which represents the number of items of something in Minecraft. Output it in a way more ...
• 89.3k
1 vote
1k views

### A+B using C++ language

I'm golfing a program to sum two numbers in C++. Example: 10 3 13 I found out that this problem can be solved in 54 symbols (without spaces and so on) using C++....
756 views

### Do two numbers contain unique factorials?

Break two numbers up into their factorials; if they share any, return a falsey value. Otherwise, return a truthy value. (inspired by this recent question) In other words, write each input number as ...
• 15.4k
2k views

### Do two numbers contain unique powers of 2

Break two numbers up into their powers of 2, if they share any, return a falsey value. Otherwise, return a truthy value. If one input is 0, the answer will always ...
• 10.8k
538 views

### Evaluate modular power towers

Given two numbers n and m, evaluate the infinite power tower: n^(n+1)^(n+2)^(n+3)^(n+4)^... mod m Keep in mind that ^ is right-associative. So 2^3^4 = 2^(3^4). Now how can you possibly assign a ...
• 39.1k
12k views

### What do you get when you multiply 6 by 9? (42)

I love math. But I can't find a single calculator that can multiply correctly. They seem to get everything right except 6*9 (It's the question to life, the universe, and everything! How could they get ...
• 1,547
3k views

### Opposite of the digital root!

Also known as the [analog root] (Opposite of the digital root!) ;) The digital root of a number is the continuous summation of its digits until it is a single digit, for example, the digital root of ...
• 1,576
3k views

### Is it a Cyclic number?

A cyclic number is a number of "n" digits that when multiplied by 1, 2, 3,...n, results in the same digits but in a different order. For example, the number 142,857 is a cyclic number since ...
• 1,576
2k views

An addition chain is a sequence of integers starting with 1, where every integer other than the initial 1 is a sum of two previous integers. For instance, here's an addition chain: ...
• 42k
5k views

### Show me the nearest demon

A demonic number is a positive integer whose decimal representation consists of only 6. The list of demonic numbers starts with 6, 66, 666, 6666. Given a positive integer, output the nearest demonic ...
• 49.7k
362 views

### (Can I) Add parentheses to make this true

I saw this recent Puzzling question: Add parentheses to make this true And saw that one answer used a Python script to try all possibilities. Your challenge is, given an expression (as a string) ...
1k views

### Does the sum of 2 numbers in the list equal the desired sum? [duplicate]

The Task This is my first challenge so apologies if it is very simple! In this challenge, your task is to write a program or function which takes in a list of integers and a desired sum and outputs ...
• 431
775 views

### Sigmafy the expression

For those who didn't know, Sigma is a Greek letter which is heavily used in mathematics as the summation sign. Given a string representing an expression depending on $k$ that we will denote $E(k)$...
• 42.4k
3k views

### Abandon all squares, ye who divide me

Definitions A perfect square is an integer which can be expressed as the square of another integer. For example, 36 is a perfect square because ...
• 49.7k
3k views

### Raise integer x to power x, without exponentiation built-ins

Task - The title pretty much sums it up: raise an integer x to power x, where 0<x. Restrictions: Use of exponentiation, ...
832 views

### Visualize the Euclidean algorithm again

Task Given two positive integers: Draw the rectangle with dimensions specified by the two integers. Repeat Step 3 until there is no more space. Draw and fill the largest square touching three sides ...
• 49.7k
6k views

### The forbidden built-in

In the standard loopholes, the following is forbidden: Claiming that your answer is written in "MyOwnLanguage", where the command x means "read a sequence of ...
• 49.7k
821 views

### Implement Euler's method

The goal of this challenge is to use Euler's method to approximate the solution of a differential equation of the form f(n)(x) = c.† The input will be a list of integers in which the nth value ...
• 71.4k
368 views

### Roots and operators

I used to play a game while I was in the car, it consisted in taking the n-1 first numbers of another car plate and use operators and roots on them to get the ...
4k views

### Replace twos with threes

Given a positive integer n write some code to take its prime factorization and replace all of its factors of 2 with 3. For ...
• 97.6k
1k views

### Linear interpolation of the Fibonacci sequence

Your task is to find the nth Fibonacci number, but n is not necessarily an integer. The Fibonacci sequence, 0-indexed, goes as follows: ...
• 6,703
3k views

### Moving modest minimum

Inspired by a question over at Stack Overflow. The title here is entirely my fault. The challenge Given a list of positive integers containing at least two entries, replace each number by the ...
• 104k
2k views

### Fake Statistics

If you're going to invent some fake news, you'll want to fabricate some data to back it up. You must already have some preconceived conclusions and you want some statistics to strengthen the argument ...
• 71.9k
171 views

### Restricted powers of two [closed]

Challenge Given a number x, output the first x powers of two, starting with 2¹ (2). Example ...
• 6,348
3k views

### Plus or minus polyglots!

Your submission must take a list of numbers (in whatever list format your language supports, or using multiple function / command-line parameters) or a string of numbers separated by any character ...
2k views

Well, everyone loves Polyglots. You will be given two integers, in any standard form of input (no hardcoding). Your task is to write a polyglot which finds the minimum value in a language and the ...
• 42.4k
1k views

### One Expression, Many Values

Using our familiar mathematical symbols: +, x, parenthesis, and any rational number, it's easy to create expressions that evaluates to some desired number. For example: ...
• 502
336 views

### Help Gödel with his β function [closed]

Gödel's β function takes three natural numbers as arguments. It is defined as β(x,y,z) = rem(x, 1 + (z + 1) · y) = rem(x, (z · y + y + 1) ) where rem(a, b) ...
• 233
3k views

### Is my Diffy game degenerate?

Recently I posted a question about Diffy games which has gone unanswered. Thats fine, the question is really hard, but I would like to make an easier question about Diffy games so that we can get the ...
• 97.6k
2k views

### Let's do some location arithmetic!

From the Wikipedia article: Location arithmetic (Latin arithmeticæ localis) is the additive (non-positional) binary numeral systems, which John Napier explored as a computation technique in his ...
5k views

### How fast is my Hot Wheels car?

Several years back, Hot Wheels made a simple flash game called "Formula Fuelers Racers"*. To play the game, you select three ingredients from a fridge to put into your car, which is then raced ...
• 29k
924 views

### Summing? That's my forte!

Introduction Forte is a very peculiar esoteric language based on the concept of modifying the values of numbers. In Forte numbers are not constants but variables, you can use the ...
• 12.6k
1k views

### Detect the Nearly Perfect Licence Plates

Note: This is inspired by this question by @Willbeing where task was to count the number of perfect plates of a certain length, but it's slightly different. We call a perfect licence plate that plate ...
• 42.4k
2k views

### Operator that combines sum, product and difference between two numbers

Challenge: There's a silly puzzle circulating on social networks that reads: 8 + 2 = 16106 5 + 4 = 2091 9 + 6 = ? Implement a function or operator that, when ...
• 741
6k views

### Cops - square times square root

Note: This is the cops' thread, where one should post the scrambled code. Here is the robbers' thread where the cracked source should be posted and linked to the cop's answer. Task: Write the ...
• 42.4k
4k views

• 42.4k
1k views

### Integer-Digits of the Arithmetic-Tables

Challenge: Output the 'integer-digits' of one of the following six arithmetic-tables based on the input: - addition (+); - subtraction (...
• 125k
832 views

### Divide one number by another

Challenge Given two numbers, output their quotient. In other words, integer divide one number by another. Both divisor/dividend will be under 10001. Division must be performed using integer division,...
• 6,348
1k views

### Find Diffy Games

A fun game to play if you are bored is the Diffy Game. It is a one player game that is pretty simple and can consume a good deal of your time. The Diffy game works like as follows: You start with a ...
• 97.6k
19k views

### Reciprocal of a number (1/x)

Challenge Given a (floating-point/decimal) number, return its reciprocal, i.e. 1 divided by the number. The output must be a floating-point/decimal number, not just an integer. Detailed ...
• 6,348
456 views

### Make mathematics with minimal matchsticks

Meta-background This was set as a question on Puzzling, and the instant reaction was "well, someone will just solve that by computer". There was a debate about just how complex a program to solve ...