Questions related to elementary arithmetic.

learn more… | top users | synonyms

9
votes
19answers
1k views

Integer square root of integer

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 ...
3
votes
9answers
414 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 ...
5
votes
5answers
326 views

Permutation Numbering

The Challenge For a given set of n integers, write a program which will output its lexicographic index. The Rules The input must only be a set of unique non-negative integers separated by spaces. ...
-1
votes
2answers
227 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 is prime number and 0 otherwise. Considern = 0 and n = 1 as non-primes. ...
18
votes
5answers
3k 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 = (m[n] + d + y + y>>2 + y/400 - y/100) % 7;, where ...
3
votes
4answers
392 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 ...
5
votes
9answers
712 views

Generate all possible integers

Input: you are given 2 integers, n and k. n is a positive (>= 1) integer, and k an integer, which is the number of times you are allowed to use n. Output: output all of the non-negative integers ...
14
votes
16answers
1k 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 ...
1
vote
0answers
91 views

Give all the ways to reach 100 [duplicate]

Write a program that finds all the ways you can write 100 as 123456789 separated only by the characters +-*/ and space. Example: 123 + 4 - 5 + 67 - 89 = 100. You can output your answers in any format ...
6
votes
10answers
315 views

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

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.
5
votes
2answers
443 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 &, |, ^, ...
0
votes
3answers
947 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. signature textTime([int] t,[bool] z,[bool] m) t is the time like 11728 and you can ...
8
votes
4answers
841 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 ...
1
vote
1answer
478 views

Basic Calculator with GUI

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 ...
6
votes
3answers
330 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 ...
5
votes
5answers
823 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 ...
16
votes
3answers
887 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 ...
7
votes
4answers
331 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 input.txt and prints the lines of input.txt which contain any ...
1
vote
2answers
285 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: ...
3
votes
9answers
422 views

Evaluate the primorial of a number

The primorial of a number is the product of all the primes till that number, itself included. Input a number from STDIN and evaluate its primorial. Don't use libraries. Shortest code wins.
4
votes
7answers
544 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 ...
4
votes
9answers
839 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, ...
9
votes
5answers
429 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: ...
5
votes
3answers
638 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 binary(integer(n1)+integer(n2)) or anything ...
-5
votes
1answer
288 views

Sort an array with values of integer

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. ...
1
vote
1answer
771 views

Getting an answer from a string of digits.

Write a program which will find all solutions to make the string "123456789" evaluate to a integer input value by inserting any of the four basic arithmetic operations (+ - * /) into the string in any ...
7
votes
17answers
1k 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 ...
12
votes
4answers
993 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: ...
5
votes
4answers
384 views

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

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 2-3+4+5 EDIT: ...
7
votes
16answers
1k 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 ...
13
votes
30answers
2k 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. ...