The challenge involves mathematics. Also consider using more specific tags: [number] [number-theory] [arithmetic] [combinatorics] [graphs] [geometry].

learn more… | top users | synonyms

-5
votes
3answers
111 views

Convert to uppercase and lowercase without branching and comparisons

Write two functions/programs which take an ASCII code of character (8-bit unsigned integer) and one of them converts char to uppercase and other to lowercase. That is, they must be equivalent to ...
23
votes
14answers
3k views

Find the Smoothest Number

Your challenge is to find the smoothest number over a given range. In other words, find the number whose greatest prime factor is the smallest. A smooth number is one whose largest prime factor is ...
12
votes
3answers
646 views

Expression that equals its length

Given a number, find an expression in words equaling that number, with a length of that number. Thus, to an input of 15, you might output sixteen minus one, which has fifteen characters (not counting ...
0
votes
0answers
13 views

Find mathematical art [migrated]

How can I get enough reputation to be able to actually post an answer here?! It seems that I need 10 reputation to answer the one question that I really want to. I have some awesome answers to the ...
3
votes
6answers
847 views

Solve quadratic equation using only 3 variables and arithmetic

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 are coefficients of this equation. ...
5
votes
2answers
577 views

The distance between circles

Imagine you are given two lists of numbers which are to be interpreted as points on a circle of circumference 1000. Let us say circleA = [10, 24, 44, 175, 321, 579, 618, 841, 871, 979] circleB = ...
4
votes
9answers
791 views

Stack a random number of cups into a perfect two dimensional pyramid (triangle)

You are given a certain number of cups (n). You are tasked with stacking these cups into a pyramid, with each row having one more cup than the row above it. The number you are given may or may not be ...
9
votes
1answer
199 views

Primality Testing in Manufactoria

Background Manufactoria is a game about programming. The player must use a form of two-dimensional programming language to complete tasks. If you've never heard of it, the easiest way to learn is to ...
8
votes
7answers
709 views

is_gaussian_prime(z)?

Task Write a function that accepts two integers a,b that represent the Gaussian integer z = a+ib (complex number). The program must return true or false depending on whether a+ib is a Gaussian prime ...
1
vote
0answers
95 views

Push Button Probabilities [duplicate]

The Challenge The challenge is that I have a standard mechanical push button lock and you need to find out every possible code that could unlock it. With a standard mechanical push button lock you ...
8
votes
5answers
692 views

Raise to the Power

Challenge Challenge is writing a program that takes a positive numbers a and a nonzero number b and outputs a^b (a raised to the power b). You can only use + - * / abs() as mathematical ...
3
votes
1answer
148 views

Calculate the Riemann Zeta Function [closed]

Calculate the Riemann zeta function to the maximum primitive precision in your language (for C-family, that would be double or long double, var in JS, etc.) No need for BigDecimal or the like unless ...
10
votes
7answers
456 views

Molar masses of compounds

Task Write a program that takes in a compound made solely of elements with an atomic number less than or equal to 92 (Uranium), and outputs the molar mass of the compound in grams/mole. Rules and ...
257
votes
56answers
63k views

Tweetable Mathematical Art

Integer math can generate amazing patterns when laid out over a grid. Even the most basic functions can yield stunningly elaborate designs! Your challenge Write 3 Tweetable (meaning 140 characters ...
1
vote
5answers
307 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, ...
14
votes
3answers
495 views

Find the shortest bracket numbers

Bracket numbers provide a simple way to express large integers using only left bracket, space, and right bracket ([ ]). A bracket number is defined as a string of one or more pairs of matching ...
11
votes
24answers
2k 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
10answers
489 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 ...
16
votes
4answers
584 views

Three-pointer! But what kind?

From http://en.wikipedia.org/wiki/Triangle: Write a program that takes three 2d coordinate tuples (Cartesian), and classifies what shape these three points describe. In almost all cases these ...
11
votes
2answers
383 views

place vials in your centrifuge

This question originates in this reddit thread by reddit user taho_teg but it is expanded to a more general 'puzzle'. You have a centrifuge with 24 holes for the vials uniformly distributed in a ...
2
votes
1answer
303 views

Recursive Mathematical Puzzle from a high school contest

The problem appeared on the 2013 SJCNY High School Programming Contest. It was the last question in the set of problems and no team produced a correct answer during the 2.5 hours they had to work on ...
7
votes
8answers
1k views

Write an IBAN validator

Write a program (the body of the function is enough) that accepts a string of alphanumeric characters and validates it according to ISO 13616:2007. The algorithm for validation is (source: wikipedia ...
1
vote
6answers
126 views

Generate the group table for Z_n

Groups are a widely used structure in Mathematics, and have applications in Computer Science. This code challenge is about the fewest # of characters to create a group table for the additive group ...
1
vote
3answers
285 views

Solving Systems of Equations using Cramer's Rule

Create an algorithm that uses Cramer's Rule (with determinants of matrices) to solve for the solutions of a system of linear equations. The code should work for an "n" number of variables. You may ...
2
votes
0answers
103 views

Write program which finds shortest expression for number [duplicate]

Write program which finds shortest expression for big integer. Expression may consist of + - * / ^ ! ( ) operations. ! stands for factorial, ^ - exponentiation, / - rational division. Number itself ...
4
votes
0answers
249 views

Write a FAST word equation solver [duplicate]

This question is similar to Write a word equation solver by David Frank but different in three important ways: (1) David asked for just the first solution found, and I am asking for all the solutions. ...
8
votes
3answers
551 views

Calculate to how many cubes one cube can be cut

Imagine some cube which we can cut into smaller cubes without remaining pieces. Find to how many cubes a cube can be cut. For example, a cube can be cut into 8, 27 (obviously 3rd powers of integers) ...
11
votes
9answers
2k views

Write program which verifies Erdős–Straus conjecture

Write program, which verifies Erdős–Straus conjecture. Program should take as input one integern (3 <= n <= 1 000 000) and print triple of integers satisfying identity 4/n = 1/x + 1/y + 1/z, 0 ...
5
votes
5answers
446 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. ...
18
votes
13answers
1k views

Khinchin's constant to as many decimal places as possible in 64 bytes or less

Khinchin's constant is a curious mathematical constant that, according to Wolfram MathWold, is "notoriously difficult to calculate to high precision". Here it is to 100 digits: ...
18
votes
5answers
4k 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 ...
6
votes
5answers
467 views

Output nth term in Catalan type sequence

Given a number, starting with 1, create new numbers (children) by taking the last digit, n, and concatenating 1 through n+1. This seems to be a much better explanation of the sequence A071159. ...
3
votes
4answers
399 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 ...
0
votes
1answer
280 views

Solve this math problem in smallest amount of code [closed]

Here I found a cool math problem. I thought you could write some golfed code to compute all answers between x and x.(there is an infinite amount). Problem: Once upon a time, and old lady went to sell ...
5
votes
5answers
457 views

Operations on Sets

Note: I have accepted an answer, but I'm willing to accept a better answer if it comes. Write a program that computes operations on sets. You may take input either from standard input or from command ...
48
votes
14answers
7k views

“Disprove” Fermat's Last Theorem

Write a program, in the language of your choice, that appears to successfully find a counterexample to Fermat's Last Theorem. That is, find integers a, b, c > 0 and n > 2 such that an + bn = cn. Of ...
3
votes
1answer
213 views

Finding internal rate of return (IRR)

In investing, internal rate of return (IRR), the continuously compounded rate of return economically equivalent to a specified series of cashflows, is often a valuable concept. Your challenge is to ...
4
votes
2answers
617 views

Longest mathematical expression in a grid

Given a grid which contains these signs: 0..9, x, =, write the fastest code that outputs the longest string of connected (horizontally, vertically, and diagonally adjacent), distinct cells which is a ...
15
votes
7answers
1k views

Write a word equation solver

Introduction Consider the following example: CODE + GOLF —————— GREAT This is an equation where each letter represents a decimal digit and the words represent natural numbers (similar letters ...
21
votes
13answers
3k views

Calculate `n % 12`

Calculate n modulo 12 for an unsigned 32 bit integer. The Rules: Must work for all n between 0 and 23. Other numbers optional. Must only use any of the operators +-*, ~&^| or <<, ...
28
votes
7answers
2k views

Newtons Method by Recursive Quines

Newtons Method by Recursively Generating Code Your task is to calculate the square root of 2 using Newton's Method - with a slight twist. Your program is to calculate an iteration using Newton's ...
46
votes
9answers
3k views

Help me with differential calculus!

I love programming and know every language, but I suck at math. Unfortunately, my school requires that computers students must take a year of calculus. There's a test next week, and I don't know any ...
4
votes
0answers
207 views

Approximate square root from algorithm time complexity

There have been a few square root challenges lately, but I think this one is different. Challenge Find an algorithm such that the worst case time complexity is proportional to n^2 and the best case ...
51
votes
2answers
1k views

“KNOT” or “NOT”?

Write a program that processes an ASCII art representation of a tangled string and decides whether or not it can be untangled into a simple loop. The tangle is represented using the characters - and | ...
11
votes
6answers
1k views

Fast Trig Calculation

Fast Trigonometry Calculations Your task is to create a program which can calculate the sine, cosine and tangent of an angle in degrees. Rules No built-in trigonometry functions (not even secant, ...
4
votes
16answers
1k views

Find all numbers between 2 and 100 co-prime to a given number

Your program will be given a number as input. Your challenge is to output all the numbers between 2 and 100 inclusive that are co-prime to the given number. (Two numbers are co-prime if their GCD is ...
3
votes
2answers
377 views

Find number of polynomials with a root which is a root of unity

Write a program which takes an integer argument and outputs the number of degree n monic polynomials with coefficients that are -1,1 or 0 which have a root which is a root of unity. To make it a ...
260
votes
96answers
139k views

Write a program that makes 2 + 2 = 5

Write a program that seemingly adds the numbers 2 and 2 and outputs 5. This is an underhanded contest. Your program cannot output any errors. Watch out for memory holes! Input is optional. ...
48
votes
18answers
6k views

Program that adds all natural numbers and yields -1/12

As you might know there is a mathematical fun-fact that if you add all natural numbers you end up with... -1/12 (see Wikipedia here). Of course this is very strange result and can not be obtained by ...
-1
votes
3answers
143 views

Puzzle : Find minimum resource allocation on multiple of 10 or 12 only [closed]

I have two types of notebook . 10 problems could be solved in one page, in the first notebook. 12 problems could be solved in one page, in the second notebook. For given n problems I have to use ...