Questions tagged [arithmetic]

Challenges related to elementary arithmetic.

Filter by
Sorted by
Tagged with
14 votes
6 answers
608 views

False Positives on an Integer Lattice

Leaderboard ...
Martin Ender's user avatar
50 votes
5 answers
2k views

Multiply with restricted operations

There's a 500 rep unofficial bounty for beating the current best answer. Goal Your goal is to multiply two numbers using only a very limited set of arithmetic operations and variable assignment. ...
xnor's user avatar
  • 144k
12 votes
6 answers
4k views

Implement an 8 bit adder

The Challenge Implement a function which accepts two integers whose values range from 0 - 255 and returns the sum of those integers mod 256. You may only use bitwise negation (~), bitwise or (|), bit ...
Orby's user avatar
  • 874
11 votes
7 answers
654 views

Find the maximum operation

The challenge is to find the maximum number you can get from a list of integer using basic arithmetic operators (addition, substraction, multiplication, unary negation) Input A list of integers ...
CNicolas's user avatar
  • 119
7 votes
6 answers
6k views

Solve quadratic equation using only 3 variables and arithmetic [closed]

Write function which solves equation of degree less than or equal to 2 (ax^2 + bx + c = 0). Input Function should get 3 parameters - floating point numbers which ...
Somnium's user avatar
  • 2,669
24 votes
22 answers
10k views

Check if a number is a product of consecutive integer numbers

Some numbers such as: 6, 12, 20, 30, 42, 56, 60, 90, 120 and so on as can be expressed as a product of consecutive integer numbers as shown below. ...
Suraz's user avatar
  • 371
11 votes
1 answer
463 views

Minimal cover of bases for quadratic residue testing of squareness

Challenge Find the smallest cover of bases (e.g., moduli) whose sets of quadratic residue can be tested via table-lookup to definitively determine whether or not a given non-negative integer n is a ...
Todd Lehman's user avatar
  • 1,809
13 votes
4 answers
1k views

Kakuro Combinations

Kakuro Combinations Because I can't do mental arithmetic, I often struggle with the Kakuro Puzzle, which requires the victim to repeatedly work out which distinct numbers in the range 1 to 9 (...
VisualMelon's user avatar
  • 3,878
2 votes
5 answers
1k views

Modular exponentiation using only addition and subtraction

The challenge In the least number of source code characters, in a language of your choosing, devise a function which raises base a to power b, modulo m, using purely integer arithmetic, where a, b, ...
Todd Lehman's user avatar
  • 1,809
11 votes
40 answers
5k views

Integer square root of integer [closed]

Problem: In your choice of language, write the shortest function that returns the floor of the square root of an unsigned 64-bit integer. Test cases: Your function must work correctly for all ...
Todd Lehman's user avatar
  • 1,809
7 votes
28 answers
3k views

Base-2 integer logarithm of 64-bit unsigned integer

Problem: In your choice of language, write the shortest function that returns the floor of the base-2 logarithm of an unsigned 64-bit integer, or –1 if passed a 0. (Note: This means the return type ...
Todd Lehman's user avatar
  • 1,809
-4 votes
2 answers
334 views

Shortest test for primality for byte [duplicate]

Write a function which gets as input a number (0 <= n <= 255) stored in 32-bit variable and returns non-zero integer if n ...
Somnium's user avatar
  • 2,669
25 votes
5 answers
5k views

Shortest expression for {0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4}

Given list of integers {0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4}. For those who interested these numbers are used in weekday calculation. Weekday = ...
Somnium's user avatar
  • 2,669
3 votes
4 answers
527 views

Difference of expressions when evaluated in different orders

We all know the standard order of operations for math functions (PEMDAS), but what if we instead evaluated expressions left-to-right? The Challenge Given a string through standard input or through ...
A Frayed Knot's user avatar
8 votes
12 answers
2k views

Generate all possible integers

Input: you are given 2 integers, n and k. n is a positive (>= 1) integer, and ...
Ryan Dougherty's user avatar
19 votes
21 answers
2k views

Length of String Using Set Theory

From Wikipedia Set-theoretic definition of natural numbers The set N of natural numbers is defined as the smallest set containing 0 and closed under the successor function S defined by S(n) = n ∪ ...
jing3142's user avatar
  • 365
9 votes
10 answers
3k views

how to find n'th number in the decimal expansion of a proper fraction? [duplicate]

Given three integers N,D,R write a program to output Rth digit after the decimal point in the decimal expansion for a given proper fraction N/D.
Dangling_pointer's user avatar
7 votes
2 answers
862 views

math with bitwise operators

objective write a program that can perform addition, subtraction, multiplication, and division, using only bit-wise operators, by bit-wise operators i mean the equivalent of JavaScript ...
Math chiller's user avatar
0 votes
3 answers
5k views

javascript: smallest code to convert seconds to time [closed]

Given seconds like 11728, write the smallest javascript function that returns a string like 3hrs. 15min. 28sec. ...
AwokeKnowing's user avatar
15 votes
4 answers
1k views

No branching please

Anyone who is moderately into low level code optimization know about the perils of branching, be it implemented as if-statements, loops or select-statements the possibility of a branch misprediction ...
aaaaaaaaaaaa's user avatar
  • 4,395
4 votes
1 answer
1k views

Basic Calculator with GUI [closed]

I recently had to add a small basic calculator to a project. I wrote a quick dirty one, but it seemed small enough to check with you people out here ;) Just out of curiosity & an appetite to get ...
loxxy's user avatar
  • 229
6 votes
3 answers
578 views

Simultaneous equations

With equations that have more than one unknown, simultaneous equations can be used in solving for them. This challenge will only deal with linear equations with two unknowns, to make things as ...
Volatility's user avatar
  • 3,364
6 votes
5 answers
3k views

Build a solver for the cow and chicken problem

The cow and chicken problem is a traditional problem for introducing young students to the concept of systems of equations. It goes as follows: A farmer raises cows and chickens on his farm. His ...
Joe Z.'s user avatar
  • 34.8k
23 votes
4 answers
3k views

Four fours puzzle

The Four fours puzzle is a popular recreational mathematical puzzle that involves using exactly four 4s (and no other number) and a defined set of operations to reach every number from 0 to a given ...
Volatility's user avatar
  • 3,364
9 votes
4 answers
389 views

Fourth of July Edition: Print lines of a file containing multiples of a specific number

Create a program which takes one command-line argument, n, which will be an integer less than 2147483648 (2^31), and then reads a file ...
ojblass's user avatar
  • 2,837
1 vote
2 answers
472 views

Floating points: Make Gaussian elimination go wrong

You know that some decimal numbers can't be expressed as IEEE 754 floating points. You also know that arithmetic with floating points can give results that seem to be wrong: ...
Martin Thoma's user avatar
7 votes
18 answers
2k views

Evaluate the primorial of a number [duplicate]

The primorial of a number is the product of all the primes until that number, itself included. Take a number from STDIN as the input and evaluate its primorial, ...
Soham Chowdhury's user avatar
18 votes
15 answers
3k views

Evaluate the nth hyperoperation

I do realise that this is a bit math-y, but - here goes. In mathematics, the hyperoperation sequence is an infinite sequence of arithmetic operations (called hyperoperations) that starts with the ...
Soham Chowdhury's user avatar
7 votes
11 answers
1k views

Generate math problems

Generate math problems (addition, subtraction, or multiplication) using numbers 0-10. Provide feedback on whether the user was right or wrong and show a score. Specifics: Must generate addition, ...
Doorknob's user avatar
  • 71.4k
11 votes
1 answer
2k views

Generate a number by using a given list of numbers and arithmetic operators

You are given a list of numbers L = [17, 5, 9, 17, 59, 14], a bag of operators O = {+:7, -:3, *:5, /:1} and a number ...
Martin Thoma's user avatar
12 votes
5 answers
755 views

Visualise long multiplication with ASCII art

The challenge Write a program that takes two integers from standard input, separated by a comma, and then prints a visualisation of long multiplication of those two integers to standard output. Eg: ...
Averroes's user avatar
  • 4,087
90 votes
98 answers
20k views

When does (x == x+2)? [closed]

The challenge: Define x in such a way that the expression (x == x+2) would evaluate to true. I tagged the question with C, but ...
5 votes
4 answers
573 views

Implement half away from 0 rounding

Overview: Using you language of choice, implement a complete "half away from 0" rounding function in the shortest amount of code possible. Rules/Constraints: Direct, predefined ...
Gaffi's user avatar
  • 3,617
6 votes
3 answers
1k views

Implementing Binary Arithmetic

Given two binary numbers (strings containing 0s and 1s), perform operations on them, with one problem: You must keep them in binary. That means no going ...
beary605's user avatar
  • 4,310
4 votes
21 answers
2k views

Arithmetic Sequences

An arithmetic sequence is a sequence of numbers of the form a,a+n,a+2n,...
beary605's user avatar
  • 4,310
-9 votes
1 answer
448 views

Sort an array with values of integer [closed]

There is an array of integer values to be sorted.During the sorting process, the places of two numbers can be interchanged. Each interchange has a cost, which is the sum of the two numbers involved. ...
Bhavik Ambani's user avatar
29 votes
47 answers
7k views

Additive Persistence

The shortest code to pass all possibilities wins. In mathematics, the persistence of a number measures how many times a certain operation must be applied to its digits until some certain fixed ...
Kevin Brown-Silva's user avatar
22 votes
5 answers
2k views

Visualize long division with ASCII art

Write a program that visualizes long division with ASCII art. Input consists of two integers, a numerator and a denominator, using the input format of your choice. Examples: 1234 ÷ 56: <...
Joey Adams's user avatar
  • 10.6k
7 votes
4 answers
935 views

Obtain a number from 4 numbers using any combination of mathematical operations [closed]

Given 4 numbers n1, n2, n3, n4, and a goal n5, obtain n5 using n1 through n4 combined with any operations. Eg. Given four numbers 2,3,4,5 and the goal as 8, output (one of many) is ...
CMR's user avatar
  • 181
91 votes
216 answers
22k views

Find the Factorial!

Create the shortest program or function that finds the factorial of a non-negative integer. The factorial, represented with ! is defined as such $$n!:=\begin{...
Kevin Brown-Silva's user avatar
22 votes
20 answers
4k views

Basic Calculator

You must write a program to evaluate a string that would be entered into a calculator. The program must accept input and output the correct answer. For languages that do not have standard input/...
Kevin Brown-Silva's user avatar
15 votes
28 answers
3k views

Implement division

Implement a division algorithm in your favourite language which handles integer division. It need only handle positive numbers - but bonus points if it handles negative and mixed-sign division, too. ...
Thomas O's user avatar
  • 3,338
62 votes
64 answers
9k views

The Luhn algorithm for verifying credit card numbers, etc

Challenge Write the shortest program or function to calculate the Luhn Algorithm for verifying (credit card) numbers. Luhn algorithm explained From RosettaCode, this algorithm for the purposes of ...
Chris Laplante's user avatar

1
7 8 9 10
11