The challenge involves mathematics. Also consider using more specific tags: [tag:number] [tag:number-theory] [tag:arithmetic] [tag:combinatorics].
2
votes
4answers
198 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
132 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
157 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 ...
0
votes
5answers
245 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 ...
6
votes
4answers
373 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 ...
5
votes
14answers
445 views
Meta Length Logarithms
Good Evening Golfers,
Your challenge, this evening, is logarithmic, and (as Abed would put it) "Meta"
Your goal is to write a program that takes an input from stdin or the command line, and returns ...
7
votes
3answers
261 views
Rosetta Stone Challenge: Draw a Box Plot
The goal of a Rosetta Stone Challenge is to write solutions in as many languages as possible. Show off your programming multilingualism!
The Challenge
Your challenge is to implement a program that ...
12
votes
19answers
878 views
Give the smallest number that has N divisors
Your function takes a natural number and returns the smallest natural number that has exactly that amount of divisors, including itself.
Exemples:
f(1) = 1 [1]
f(2) = 2 [1, 2]
f(3) = 4 [1, 2, 4]
...
6
votes
15answers
504 views
Triangle Area Side Side Side
Given three sides of a triangle, print area of this triangle.
Test cases:
In: 2,3,4
Out: 2.90473750965556
In: 3,4,5
Out: 6
Assume the three side a,b,c always a>0,b>0,c>0,a+b>c,b+c>a,c+a>b.
2
votes
3answers
408 views
Calculating Resistance (Nerd Sniping)
Good Afternoon Golfers,
Our challenge for today is inspired by XKCD comics 356 and 370. We're going to write a program to calculate the resistance of a group of resistors. A forewarning that this is ...
3
votes
9answers
430 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, ...
6
votes
5answers
218 views
Gregorian to Noxu Time System Conversion
The world's changing to a new time system! We need to update our computer programs. Given an input of epoch time (number of seconds since January 1st, 1970 00:00), print out a time in the new Noxu ...
3
votes
5answers
723 views
Calculate e^x and ln(x)
Given a floating point x (x<100), return e^x and ln(x). The first 6 decimal places of the number have to be right, but any others after do not have to be correct.
You cannot have any "magic" ...
3
votes
5answers
326 views
Normal distribution values
Write the shortest program possible which outputs a table of Normal distribution values
phi(z) = Integral[t from -infty to z of e^(-t^2/2) /sqrt(2 pi) dt]
for z from 0.00 to 3.99, giving values ...
7
votes
5answers
320 views
Bijection between binary strings and pairs thereof
Input: Either one or two strings of '0's and '1's. If there are 2, they are separated by a space. All strings are of length at least 1.
Output: If one string was input, 2 are output. If 2 were ...
7
votes
6answers
463 views
Find the Pisano Period of a number
Input: An integer 0 < n < 2^30, taken from stdin.
Output: The Pisano period of n (the length of the cycle of the Fibonacci sequence mod n)
Input is smaller than 2^30 so that intermediate ...
3
votes
4answers
598 views
RPN calculator without pointers
Me and some other students were at a bar discussing programming languages, in particular the C programming language. At some point a first year student said he didn't need no damn pointers. Another ...
3
votes
2answers
230 views
Finding limits of functions
A limit in math determines the value that a function f(x) approaches as x gets closer and closer to a certain value.
Let me use the equation f(x)=x^2/x as an example.
Obviously, f(x) is undefined if ...
3
votes
4answers
477 views
A programming challenge. Number Cross Puzzle
This is from a programming challenge website.
The cross problem states that you can place the numbers 1 through N inside
the cross such that no two adjacent cells in
any direction (up, down, left ...
3
votes
4answers
455 views
Quickly find length of n-th term of the look-and-say sequence
The look and say sequence is defined as:
1
11
21
1211
111221
312211
13112221
1113213211
Write the shortest program to find the length of a specified term of this sequence without calculating each ...
4
votes
6answers
383 views
matrix determinant
Calculate the determinant of a n x n matrix.
Rules
read matrix from standard input
write to standard output
do not use ready solutions from library or language
input: columns separated by any ...
3
votes
6answers
415 views
Generate a Kolakoski sequence
Definition1
A Kolakoski sequence is a self-describing infinite sequence {kn} of alternating blocks of 1's and 2's, given by the following rules:
k0 = 1
kn = the length of the (n+1)'th ...
2
votes
2answers
485 views
Generate N number of “Go First” dice
Background
As described here http://www.ericharshbarger.org/dice/#gofirst_4d12, "Go First" Dice is a set of four dice, each with unique numbering, so that:
There will never be a tie. Each die has ...
7
votes
1answer
278 views
Solving Three Open Problems with a Halting Oracle
You are given the functions: h1(f,*args) and h2(f,*args)
Both are methods which are already defined for you (here the asterisk indicates a variable number of arguments)
f is a function, *args is a ...
4
votes
4answers
294 views
Given a fair coin as input, generate any particular unfair outcome
It is easy to generate a fair coin using a unfair coin, but the reverse is harder to accomplish.
Your program will receive one number X (between 0 and 1, inclusive) as input. The input must not ...
11
votes
2answers
493 views
Lego gear ratios
I'm building a giant lego robot and I need to generate some particular gear ratios using a set of gears. I have lots of gears with the common lego gear sizes: 8, 16, 24, or 40 teeth. Write a program ...
2
votes
5answers
557 views
Find the first n digits of the square root of a number
Given two integers m and n, return the first m digits of sqrt(n), with the decimal point. They will be given with a space in between.
You only have to produce m digits: so if m=5, n=500, then the ...
13
votes
29answers
2k views
Divide a number by 3 without using *, /, +, -, % operators
Quoting this question on SO (Spoiler alert!):
This question has been asked in an Oracle interview.
How would you divide a number by 3 without using *, /, +, -, %,
operators?
The number ...
1
vote
8answers
615 views
Calculate golden ratio
Write the shortest code, in number of bytes, to display, return, or evaluate to the golden ratio (that is, the positive root of the quadratic equation: , approximately
1.618033988749895), to at least ...
2
votes
9answers
965 views
Triangle Puzzle
Triangle Puzzle
Consider the triangle below.
This triangle would be represented by the following input file.
5
9 6
4 6 8
0 7 1 5
By starting at the top and ...
0
votes
3answers
572 views
Project Euler's “Harshad Numbers”
Project Euler Problem 387 states:
A Harshad or Niven number is a number that is divisible by the sum of its digits.
201 is a Harshad number because it is divisible by 3 (the sum of its digits.) ...
3
votes
23answers
1k views
Sexy Primes — codegolf
Write the shortest code to print sexy primes till n
Sexy Primes are pairs of numbers (n, m) such as n and m both are prime, and m = n + 6.
EDIT
Modifying the question a little bit after reading ...
3
votes
8answers
457 views
Pythagorean Triplets
The Pythagorean Theorem states that for a right triangle with sides a, b, and c, a2+b2=c2.
A Pythagorean triplet is a set of three numbers, where a2+b2=c2, a
To extend this even further, a primitive ...
12
votes
4answers
576 views
Shortest terminating program whose output size exceeds Graham's number
Write the shortest possible program (length measured in bytes) satisfying the following requirements:
no input
output is to stdout
execution eventually terminates
total number of output bytes ...
6
votes
7answers
554 views
Determining the continued fractions of square roots
The continued fraction of a number n is a fraction of the following form:
which converges to n.
The sequence a in a continued fraction is typically written as: [a0; a1, a2, a3, ... an].
We will ...
1
vote
5answers
210 views
All non-empty finite sets of positive integers
The challenge is to create an iterator(/generator) which iterates (in any order so as to reach all of them... ie no set should occur at infinity) over all possible non-empty finite sets(/tuples/lists) ...
4
votes
3answers
202 views
Line through Polygon
Input: A line of the standard slope-and-intercept form: mx+b, as well as a set of Cartesian points determining the vertices of a polygon. Assume that the x and y values of the points will be integers.
...
20
votes
25answers
3k views
Draw A Sierpinski Triangle
The Sierpinsky Triangle is a fractal created by taking a triangle, decreasing the height and width by 1/2, creating 3 copies of the resulting triangle, and place them such each triangle touches the ...
3
votes
5answers
221 views
Operations with Lists
Inspired by this question.
Given a list containing numbers, print:
The sum and product of the numbers in the list
The average and median
The differences between each term in the list (e.x. [1,2,3] ...
8
votes
5answers
554 views
Egyptian Fractions
Overview:
From Wikipedia: An Egyptian fraction is the sum of distinct unit fractions. That is, each fraction in the expression has a numerator equal to 1 and a denominator that is a positive integer, ...
4
votes
7answers
838 views
Big integer multiplication
Your challenge (if you choose to accept it) is to implement big integer multiplication in the shortest code possible.
Rules:
Take two integers (decimal form) as ASCII strings from the command line ...
3
votes
9answers
572 views
Subtracting, the old-fashioned way
Overview
Adding slightly to the complexity of working with Roman numerals...
The ancient Romans devised a number system using Latin letters, which served them well, and which is still used by modern ...
2
votes
9answers
424 views
Adding, the old-fashioned way
Overview
The ancient Romans devised a number system using Latin letters, which served them well, and which is still used by modern civilization, though to a much smaller degree. In the time of its ...
2
votes
3answers
210 views
maximum subarray variant
Problem
There is a circular track containing fuel pits at irregular intervals. The total amount of fuel available from all the pits together is just sufficient to travel round the track and finish ...
2
votes
3answers
654 views
Convert from postfix notation to infix notation
This question may not be that creative, but I believe that it is different enough to pose a new challenge.
The Challenge
Your challenge is to write the shortest program possible that can take any ...
7
votes
3answers
1k views
Convert infix expressions to postfix notation
When I saw the title of this closed question, I thought it looked like an interesting code golf challenge. So let me present it as such:
Challenge:
Write a program, expression or subroutine which, ...
10
votes
7answers
780 views
Sum of (at most) 5 primes
Terence Tao recently proved a weak form of Goldbach's conjecture! Let's exploit it!
Given an odd integer n > 1, write n as a sum of up to 5 primes. Take the input however you like, and give ...
7
votes
5answers
634 views
Output a list of all rational numbers
Out of all of mathematics, there will always be a few theorems that go beyond all common sense. One of these is the fact that there are different sizes of infinity. Another interesting fact is the ...
0
votes
5answers
689 views
In how many ways can a number be expressed as a sum of consecutive numbers? [closed]
All the positive numbers can be expressed as a sum of one, two or more consecutive positive integers. For example, 9 can be expressed in three such ways: 2+3+4, 4+5 or 9.
The challenge is to write a ...
9
votes
5answers
476 views
Reverse Engineer Polling Statistics
Introduction
Given a set of percentages of choices in a poll, calculate the minimum number of voters there must be in the poll to generate those statistics.
Example: What is your favorite pet?
...
