Questions tagged [arithmetic]

Challenges related to elementary arithmetic.

Filter by
Sorted by
Tagged with
35 votes
44 answers
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 ...
Leaky Nun's user avatar
  • 49.7k
22 votes
9 answers
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....
user avatar
21 votes
13 answers
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...
JungHwan Min's user avatar
  • 13.8k
27 votes
11 answers
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 ...
Leaky Nun's user avatar
  • 49.7k
27 votes
21 answers
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 ...
Leaky Nun's user avatar
  • 49.7k
16 votes
12 answers
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 ...
user avatar
38 votes
91 answers
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 ...
praosylen's user avatar
  • 1,495
22 votes
21 answers
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 ...
Calvin's Hobbies's user avatar
1 vote
1 answer
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++....
eaglemango's user avatar
12 votes
7 answers
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 ...
Greg Martin's user avatar
  • 15.4k
10 votes
32 answers
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 ...
ATaco's user avatar
  • 10.8k
13 votes
4 answers
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 ...
orlp's user avatar
  • 39.1k
69 votes
87 answers
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 ...
Tezra's user avatar
  • 1,547
19 votes
33 answers
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 ...
qqq's user avatar
  • 1,576
19 votes
8 answers
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 ...
qqq's user avatar
  • 1,576
23 votes
8 answers
2k views

Shortest Addition Chain

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: ...
isaacg's user avatar
  • 42k
42 votes
27 answers
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 ...
Leaky Nun's user avatar
  • 49.7k
8 votes
1 answer
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) ...
user avatar
27 votes
25 answers
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 ...
maple_shaft's user avatar
20 votes
16 answers
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)\$...
Mr. Xcoder's user avatar
  • 42.4k
36 votes
24 answers
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 ...
Leaky Nun's user avatar
  • 49.7k
26 votes
98 answers
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, ...
user avatar
14 votes
9 answers
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 ...
Leaky Nun's user avatar
  • 49.7k
64 votes
51 answers
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 ...
Leaky Nun's user avatar
  • 49.7k
9 votes
15 answers
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 ...
Doorknob's user avatar
  • 71.4k
7 votes
1 answer
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 ...
user avatar
47 votes
47 answers
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 ...
Wheat Wizard's user avatar
  • 97.6k
20 votes
11 answers
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: ...
Daniel's user avatar
  • 6,703
51 votes
41 answers
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 ...
Luis Mendo's user avatar
  • 104k
29 votes
7 answers
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 ...
Digital Trauma's user avatar
-6 votes
12 answers
171 views

Restricted powers of two [closed]

Challenge Given a number x, output the first x powers of two, starting with 2¹ (2). Example ...
anna328p's user avatar
  • 6,348
18 votes
16 answers
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 ...
user avatar
19 votes
6 answers
2k views

Contradictory Polyglots

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 ...
Mr. Xcoder's user avatar
  • 42.4k
26 votes
7 answers
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: ...
Ankoganit's user avatar
  • 502
13 votes
1 answer
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) ...
Tweakimp's user avatar
  • 233
24 votes
13 answers
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 ...
Wheat Wizard's user avatar
  • 97.6k
22 votes
11 answers
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 ...
user avatar
24 votes
14 answers
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 ...
PhiNotPi's user avatar
  • 29k
19 votes
6 answers
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 ...
Leo's user avatar
  • 12.6k
17 votes
8 answers
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 ...
Mr. Xcoder's user avatar
  • 42.4k
27 votes
24 answers
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 ...
Locoluis's user avatar
  • 741
37 votes
68 answers
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 ...
Mr. Xcoder's user avatar
  • 42.4k
18 votes
48 answers
4k views

Robbers - square times square root

Task: Crack the scrambled code for multiplying the square root of an integer n by the square of it! You must post a comment in the cops' thread with a link to your working source, mentioning clearly ...
Mr. Xcoder's user avatar
  • 42.4k
17 votes
14 answers
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 (...
Kevin Cruijssen's user avatar
-12 votes
23 answers
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,...
anna328p's user avatar
  • 6,348
27 votes
1 answer
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 ...
Wheat Wizard's user avatar
  • 97.6k
28 votes
98 answers
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 ...
anna328p's user avatar
  • 6,348
15 votes
2 answers
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 ...
user avatar
49 votes
97 answers
5k views

Division and remainder

This challenge, while probably trivial in most "standard" languages, is addressed to those languages which are so esoteric, low-level, and/or difficult to use that are very rarely seen on this site. ...
Leo's user avatar
  • 12.6k
31 votes
80 answers
5k views

Sum the numbers on standard in

Consider a stream/file with one integer per line. For example: 123 5 99 Your code should output the sum of these numbers, that is ...
user avatar

1
3 4
5
6 7
11