Tagged Questions
The challenge involves mathematics. Also consider using more specific tags: [number] [number-theory] [arithmetic] [combinatorics] [graphs] [geometry].
3
votes
12answers
435 views
Divide Two Numbers Using Long Division
Your challenge is to divide two numbers using long division. The method we used to use in old days of school to divide two numbers.
Example here
You should NOT use / or any other division operator ...
-2
votes
0answers
62 views
Spiral program in popular language? [duplicate]
I want to print numbers in a spiral format
Center of the sprial should be 1 and the ending point is the
number given as input.
I looked the post Show Ulam's spiral.
But it is entirely ...
8
votes
5answers
909 views
+100
My Robot Has Escaped the Lab!
My robot has short circuited somehow and randomly run off somewhere from my lab!
Luckily, whenever he does this, his shut-down sequence initiates, giving him enough time to randomly turn and run in ...
47
votes
24answers
5k views
Mandelbrot image in every language
I always used a Mandelbrot image as the 'graphical' version of Hello World in any graphical application I got my hands on. Now it's your guys' turn.
Language must be capable of graphical output or ...
19
votes
8answers
1k views
Calculate the inverse of factorial
Write the shortest code that will take any real number greater than 1 as input and will output its positive inverse factorial. In other words, it answers the question "what number factorial is equal ...
10
votes
45answers
4k views
Write a function that takes (x, y) and return x to the power of y WITHOUT Loops
This is a really neat short challenge.
Write a function or a procedure that takes two parameters, x and y and returns the result of xy WITHOUT using loops, or built in power functions.
The winner is ...
9
votes
5answers
274 views
Solve a System of Linear Equations
Write a program to solve a series of linear equations as short as possible. It must solve arbitrary number of equations problems. They can inputted however you like, coefficients of augmented matrix ...
2
votes
2answers
207 views
Get as close to pi as you can [closed]
Your job is to write a program to find the closest number to PI.
Let me clarify.
You will first choose a number type. Let us say you choose Integer (in an actual answer, you cannot). Your program ...
10
votes
20answers
699 views
Calculate all the squares up to x using only addition and subtraction
The goal is to calculate all the squares up to x with addition and subtraction.
Rules:
The code must be a function which takes the total number of squares to generate, and returns an array ...
8
votes
21answers
1k views
Calculate the cube root of a number
The goal of this code golf is to create a program or function that calculates and outputs the cube root of a number that's given as input.
The rules:
No external resources
No use of built-in cube ...
5
votes
7answers
486 views
Shortest Program to Solve a Quartic Equation
Write the shortest program to solve a Quartic equation.
A quartic equation is a polynomial equation of the form:
ax⁴ +bx³+cx²+dx+e=0
A solution for x is a number such that the above evaluates to 0.
...
7
votes
10answers
811 views
3 and 5 Litre Jug Puzzle
You may have seen this one in Die Hard: With a Vengeance... This question is based on the famous 3 and 5 Litre Jug Puzzle, but with a slightly different slant.
Golf up some code that when given an ...
1
vote
4answers
306 views
Theoretical algorithm to compute Graham's number
Graham's number G is defined in that way:
3^n = 3*..n times ...*3
3^^n = 3^(3^n)
3^^^n = 3^^(3^^n)
3^^^^n = 3^^^(3^^^n)
g1 = 3^^^^3
g2 = 3^^...g1 times^^3
g3 = 3^^...g2 times^^3
...
G = 3^^...g63 ...
8
votes
5answers
369 views
Euler's Front 9
Project Euler is another fun programming challenge site to compete (well, play) on. Early problems start off gently, but then explode in difficulty beyond the first hundred or so. The first ...
6
votes
8answers
486 views
Calculate the super root of a number
In mathematics, tetration is the next hyper operator after exponentiation, and is defined as iterated exponentiation.
Addition (a succeeded n times)
Multiplication (a added to itself, n times)
...
2
votes
1answer
91 views
Simplifying Radicals [duplicate]
Given integers a and b in the format a√b (a on the square root of b), make a program that will reduce b and increase a until the radical statement is fully simplified.
Example
input
a = 1
b = 16
...
23
votes
56answers
5k views
Count sum of all digits [Help to determine winner]
This challenge is to write a program or script which counts the sum of all digits within the integers from 1 up to and including a given number.
Input, one positive integer.
Output, the sum of digits ...
5
votes
5answers
165 views
Convert radicals to mixed & entire radicals and to real numbers
Challenge
The goal of this challenge is to take a radical and convert it to a reduced and entire radical, and a real number. You do not have to convert it to all 3, however, you will get bonus points ...
6
votes
7answers
517 views
Minimum perimeter of an area
Just a simple code golf function for fun, intentionally left open with few rules to see what creativity comes up.
Input: An integer representing the area of a rectangle.
Output: Two integers ...
5
votes
13answers
430 views
Reciprocal Fibonacci constant
Seeing as there have been an awful lot of normal Fibonacci challenges, I decided that it might be interesting to calculate the Reciprocal Fibonacci constant - namely, the sum of the reciprocals of the ...
17
votes
8answers
643 views
Thinking outside the box
You are trying to fit a sphere into a 5-sided box, but sometimes it does not fit completely. Write a function to calculate how much of the sphere is outside (above the rim of) the box.
There are 3 ...
2
votes
14answers
814 views
Write a mathematical function whose result is “hello world”
Write a mathematical function that results in an integer representation of "hello world"
For example "hello world" in hex is 68656c6c6f20776f726c64 so the goal will be to write a mathematical ...
18
votes
5answers
540 views
Thar she blows!
Arrr... Ahoy there, me maties! Unfurl tha' mainsail! Full to starboard! Ah, feel th' wind in yer hair!
Right, me hearties... I be needin' a bit of yer codin' skills! Me crew are a li'l more ...
11
votes
8answers
643 views
How long does it take to paint a stick?
(Based on this Math.SE problem, which also provides some graphics)
I have a stick which looks kinda like this:
I want it to look kinda like this:
I'm not an expert painter, however, so before I ...
3
votes
3answers
320 views
Solve Any Motion Physics Problem (Equations Supplied)
Physics Challenge
This program should be able to solve for ANY two of the following variables the user wants to solve.
s (displacement)
v (velocity)
u (initial velocity)
a (acceleration)
t (time)
...
50
votes
14answers
11k views
9 Hole Challenge
The 9 Hole Challenge
9 code golfing challenges of varying difficulty.
Penalties for using the same language more than once.
The question will be updated with pars, hole champions and trophy ...
9
votes
1answer
312 views
Sunrise and sunset
I'm a bit of a romantic, I love taking my wife out to see the sunrises and sunsets in the place we are located. For the sake of this exercise let's say I don't have code that can tell me the time of ...
5
votes
7answers
250 views
Find a fraction's position in the Stern-Brocot tree
The Stern-Brocot tree is a binary tree of fractions where each fraction is acquired by adding the numerators and denominators of the two fractions neighbouring it in the levels above.
It is generated ...
-2
votes
4answers
170 views
Write a function that results the sum of two integers using bitwise operations, w\o conditional operation [duplicate]
You cannot use if,while,for, ?:, ||, && etc., or recursion!
Assume it is Int.32
Shortest answer wins
2
votes
3answers
293 views
Produce the most digits of an irrational number with only 64 KB of memory
Constraints:
Calculate any notable irrational number such as pi, e, or sqrt(2) to as many decimal digits as possible. If using a number not mentioned in the list above, you must cite how and where ...
28
votes
29answers
3k views
Test a number for narcissism
A Narcissistic Number is a number which is the sum of its own digits, each raised to the power of the number of digits.
For example, take 153 (3 digits):
1^3 + 5^3 + 3^3 = 1 + 125 + 27 = 153
...
11
votes
6answers
585 views
Convert 1 into any positive integer using only the operations *3 and /2
Any positive integer can be obtained by starting with 1 and applying a sequence of operations, each of which is either "multiply by 3" or "divide by 2, discarding any remainder".
Examples (writing f ...
-8
votes
12answers
557 views
Calculate the factorial of a number without using recursion or loops
The goal of this code golf is to create a program that calculates the factorial of a positive number, without using recursion or loops.
The rules:
Your program should prompt for input. This input ...
6
votes
5answers
164 views
Golfing: How many unit-length squares in a list of 2d coordinates?
Given a list of 2d (x, y) coordinates, determine how many unit squares (edge length 1 unit) can be formed using the coordinates.
Input will be an array of 0 or more pairs of coordinates: e.g. in ...
4
votes
7answers
321 views
Nth K-Ugly Number
Write the shortest code in any language of your choice to find the Nth K-ugly number.
A K-ugly number is a number whose only prime factors are the prime numbers <= K.
This K-ugly number is ...
9
votes
2answers
633 views
Implement superoptimizer for addition
The task is to write code that can find small logical formulae for sums of bits.
The overall challenge is for your code to find the smallest possible propositional logical formula to check if the sum ...
3
votes
7answers
835 views
Generate an aperiodic integer sequence
Your task is to build a piece of code that generates an aperiodic sequence of integers, either by outputting one every time it iterates, or by taking an integer n and returning the nth number in that ...
14
votes
6answers
732 views
Too Fast, Too Fourier: FFT Code Golf
Implement the Fast Fourier Transform in the fewest possible characters.
Rules:
Shortest solution wins
It can be assumed that the input is a 1D array whose length is a power of two.
You may use the ...
5
votes
3answers
307 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 ...
2
votes
2answers
187 views
Create sets with a Goldbach-like property
Goldbach's conjecture states that every even number > 4 is the sum of two prime numbers. Although this conjecture is not yet proven, similar results have been proven for other series of numbers. For ...
13
votes
24answers
2k views
Collatz Conjecture
This is the Collatz Conjecture:
Start with an integer n > 1.
Repeat the following steps:
If n is even, divide it by 2.
If n is odd, multiply it by 3 and add 1.
It is proven that for all ...
15
votes
3answers
816 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
321 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 ...
18
votes
22answers
2k views
Define a function f such that f(f(n)) = -n for all non-zero integers n
This challenge was inspired by a programming blog I frequent. Please see the original post here: A Programming Puzzle
Challenge
Define a function f:Q->Q such that f(f(n)) = -n for all ...
7
votes
5answers
495 views
Generate Skolem sequences
Beat this
I was hanging out with a friend in a pub around 11:00 last night. She told me that a Skolem sequence is a sequence of 2n numbers where every number between 1 and n is repeated twice, and ...
3
votes
7answers
593 views
Generate Pascal's Pyramid
Pascal's Pyramid is an extension of Pascal's Triangle to the third dimension. Starting with a 1 as the apex, the elements of each successive layer can be determined by summing the three numbers that ...
2
votes
3answers
218 views
Evaluate the binomial theorem!
Your mission, even if you don't accept it, is to input three numbers from STDIN or file:
5 0.5 6
What you must do is evaluate this:
(5a + 0.5b)^6
This basically means that the first two ...
7
votes
1answer
343 views
Find real roots of a polynomial
Write a self-contained program which when given a polynomial and a bound will find all real roots of that polynomial to an absolute error not exceeding the bound.
Constraints
I know that Mathematica ...
-1
votes
5answers
287 views
exp function to an arbitrary double precision
Write a function to find the solution of e^x given x, and a precision in the form 0.000001.
sample input and output:
e(4,0.00001) will return 54.5981494762146, and the precision is +/- .00001. The ...
7
votes
4answers
492 views
Display a bézier curve in the browser
The goal is to display a bézier curve in any classical browser (except maybe old IE versions, because... are they really browsers?) client side.
Rules:
You must provide one or more files (or their ...