Questions tagged [math]
The challenge involves mathematics. Also consider using more specific tags: [number] [number-theory] [arithmetic] [combinatorics] [graph-theory] [geometry] [abstract-algebra].
1,471
questions
10
votes
20answers
916 views
Calculate probability of getting half as many heads as coin tosses.
Write a program that, given a small positive even integer from standard input, calculates the probability that flipping that many coins will result in half as many heads.
For example, given 2 coins ...
27
votes
19answers
4k views
My Word can beat up your Word
PROBLEM
Given two words, find the winner in a digital root battle.
Define the digital root of a word this way:
Each letter of the alphabet is assigned a number: A = 1, B = 2, C = 3, ..., Z = 26
...
8
votes
13answers
1k views
How many switches are ON
A class has N student and the class room has N switches (all turned OFF and numbered 1 to N). Each student has an enrollment number assigned from 1 to N. Each student serially (by number) toggles the ...
10
votes
3answers
456 views
Physics golf: inclined shooting
"And now for something, completely different."
An angry bird is shot at an angle β to the horizontal at a speed u. The ground is steep, inclined at an angle α. Find the horizontal distance q that the ...
5
votes
7answers
877 views
Modulo code golf
Write a function f(a,b) that returns a mod b given the constraints:
you can't use division in any way
...
4
votes
3answers
673 views
Implement BCD Arithmetic
Write the shortest function you can that takes two binary-coded decimal integers and a character indicating an arithmetic operation to perform and return the result.
Input Specification
You will be ...
15
votes
5answers
2k views
Polynomial Long Division
Implement polynomial long division, an algorithm that divides two polynomials and gets the quotient and remainder:
(12x^3 - 5x^2 + 3x - 1) / (x^2 - 5) = 12x - 5 R 63x - 26
In your programs, you will ...
15
votes
3answers
3k views
Roman numeral converter function
Create the shortest function to convert a string of Roman numerals to an integer.
The rules for each letter can be found at the Wikipedia page. Letters above 1,000 will have parentheses placed ...
23
votes
17answers
4k views
Last non-zero digit of n!
Given an integer 1 ≤ N ≤ 1,000,000 as input, output the last non-zero digit of N!, where ! is the factorial (the product of all numbers from 1 to N, inclusive). This is OEIS sequence A008904.
Your ...
8
votes
17answers
3k views
Multiply without multiply [closed]
Write the fastest (best big-O) and smallest multiplication algorithm for positive integers, without using multiplication operators. You are only allowed addition, subtraction, logical functions (AND, ...
29
votes
5answers
2k views
Advanced Calculator
You must write a program that evaluates a string that would be entered into an advanced calculator.
The program must accept input using stdin and output the correct answer. For languages that do no ...
20
votes
19answers
3k 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/...
13
votes
5answers
594 views
Perfect powers in more than one way?
Challenge
Your task is to write a program or function which, given a positive integer \$N\$, finds all positive integers less than or equal to \$N\$ that can be expressed as a perfect power in more ...
2
votes
1answer
116 views
Five aligned points and some of the pairwise distances. Infer the relative positions! [closed]
Given five points on a straight line such that their pairwise distances are 1,2,4, ..., 14,18,20 (after ordering), find the respective positions of the five points (relative to the furthest point on ...
44
votes
43answers
8k views
Reverse Polish notation
You must evaluate a string written in Reverse Polish notation and output the result.
The program must accept an input and return the output. For programming languages that do not have functions to ...
13
votes
2answers
3k views
Test if a given number is a Vampire Number
EDIT: In the interest of increasing the complexity, i've added more to the challenge.
In mathematics, a vampire number (or
true vampire number) is a composite
natural number v, with an even ...
4
votes
3answers
255 views
Sharing Inherited Land [closed]
You and your brother have inherited a rectanglar block of land. This block of land's corners are read in from stdio as TLX,TLY,TRX,TRY,BLX,BLY,BRX,BRY (all decimal ...
24
votes
38answers
4k views
Reimplementing square root [duplicate]
Define a function, s, which takes a number and returns the square root.
No use of library functions, such as Java's Math.sqrt() or PHP's built in sqrt(), allowed.
37
votes
21answers
7k views
Angle between the hands on a clock [duplicate]
Given the time in 24 hour format (2359 = 11:59pm) return the angle between the minute and hour hands on a standard clock (on the ...
5
votes
7answers
842 views
Find an unknown very large number [closed]
Let's suppose there is a finite unknown number n (n can be very large, does not necessarily fit 64-bits; think of ...
32
votes
31answers
15k views
Rand5() to Rand7() [closed]
You are provided with a function Rand5(). This function returns perfectly random (equal distribution) integers between 1 and 5.
Provide the function Rand7(), which uses Rand5() to produce perfectly ...