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

learn more… | top users | synonyms

6
votes
2answers
217 views

Fastest way to compute order of magnitude in x86 assembly

The task is simple: write assembly that computes the order of magnitude of an integer using as few clock cycles as possible. Order of magnitude is defined as log10, not log2. The range of valid ...
11
votes
1answer
99 views

Analyzing Collatz-like sequences

We define a Collatz-like sequence s with 4 positive integers: n starting value d > 1 divisor m > 1 multiplier i increment (In the original Collatz sequence d = 2 m = 3 and i = 1.) Given ...
1
vote
0answers
58 views

Weighted distribution [closed]

Your code should: Take in a set of values, each value should be given a weighted percentage. In a loop, up to 1000 iterations, each value should be incremented by one each time it is returned, ...
-1
votes
1answer
204 views

Find the inverse of a matrix

Write a full program to calculate the inverse of a 4-by-4 matrix. Rules The sixteen values of the initial matrix must be hard-coded to variables, as follows: _ _ |a b c d| |e f g h| |i j k l| ...
0
votes
0answers
165 views

Rise and Shine! [duplicate]

Challenge The challenge is to create a program which takes a date, a latitude, and a longitude, and prints the time of the sunrise on that date for the given location. The program must work for any ...
5
votes
3answers
560 views

Solve a 2x2 Eigensystem

For those with a little linear algebra background, the challenge is as simple as this: determine the eigenvalues and eigenvectors of a given complex 2x2 matrix. You may skip ahead to The Challenge for ...
3
votes
3answers
506 views

Generate all 4-perfect numbers

Your program or function should output all the 36 4-perfect numbers in increasing order separated by newlines. An n positive integer is a k-perfect number (multiply perfect number) if the sum of its ...
8
votes
1answer
409 views

Bad News, Someone

In the Futurama episode The Prisoner of Benda members of the crew swap bodies with each other, with the catch that no pair of bodies can have their minds swapped more than once. Challenge Write a ...
12
votes
1answer
564 views

Sharing pizza fairly

The difficulty with sharing pizza with friends is that it is hard to make sure that everyone gets the same amount of pepperoni on their slice. So, your task is to decide how to fairly slice a pizza so ...
9
votes
11answers
629 views

Find pairs of numbers with a particular LCM and GCD

I was working on a math question with a friend of mine, and we decided to write a script that finds the answer. The original question is as follows: The difference of two natural numbers is 2010 ...
13
votes
3answers
1k views

Computer: you do the math

This challenge is partly an algorithms challenge, involves some math and is partly simply a fastest code challenge. For some positive integer n, consider a uniformly random string of 1s and 0s of ...
5
votes
2answers
697 views

Coding a recursive function for highest possible input

Challenge You are given the following function:- which is the same as:- with the base cases q(r, b, L) = 1 whenever r ≤ L, q(r, 0, L) = 0, if r > L and q(r, 0, L) = 1, if r ≤ L. Your task is to ...
2
votes
4answers
420 views

Use threes to count the threes!

Write a program or function that takes two numbers - x>3 and n>0 - as input, and finds all possible bases b where the digit 3 appears at least n times in (x in base b). Input and output may be ...
20
votes
21answers
2k views

Shortest Minmod Function

The minmod function is a variant of the familiar min, which appears in slope-limiting high-resolution schemes for partial differential equations. Given a number of slopes, it picks out the flattest ...
5
votes
6answers
334 views

Mobius inversion

Your goal is to implement Möbius inversion, a linear operation on a sequence of numbers that is used in combinatorics and number theory. Fewest bytes wins. What is Möbius inversion? Given a (finite) ...
5
votes
4answers
562 views

Shortest program to split special array

Background Imagine, you have a big array A, which is mostly zeroes, but contains a short subarray B which has only strictly positive entries. For instance: | A | [0 0 0 ...
3
votes
8answers
924 views

Wait, but what's e^N?

Objective: The objective is to calculate e^N for some real or imaginary N (e.g. 2, -3i, 0.7, 2.5i, but not 3+2i). This is code golf, so, shortest code (in bytes) wins. So, for example: N = 3, e^N ...
11
votes
8answers
698 views

Balanced Ternary Converter

Credits for the challenge idea go to @AndrewPiliser. His original proposal in the sandbox was abandoned and since he has not been active here for several months, I have taken over the challenge. ...
13
votes
25answers
3k views

Find i^n, given n

The Challenge In as few characters as possible, find the value of i^n, given n, a positive integer greater than 0. This should be outputted as a String. For those that don't know, i is defined such ...
0
votes
1answer
99 views

CSS attribute selector efficient “greater than selector” code [closed]

The goal is to find a way better than the current best known way of encoding the index of a child HTML element, so that encoded indices have the following property. if (index_i >= index_p) { ...
9
votes
3answers
425 views

Print the intersection of sequences

Sequences You are given four number sequences, numbered 1 through 4. OEIS The location of 0's when the natural numbers are listed in binary. Here's an example of how to calculate the sequence: ...
10
votes
5answers
1k views

Calculate the Delacorte Number of a square

Challenge: implement calculation of a Delacorte Number in any language. Shortest code wins. For a given square matrix of distinct integers 1..n² (possible side length n at least between 3 and 27), ...
4
votes
1answer
299 views

Evaluate CDF of Student-t distribution

The goal of this codegolf is evaluating the cumulative distribution function of the student-t probability distribution. This is not trivial since there is no closed form and the function is dependent ...
8
votes
1answer
446 views

WinAli - Virtual CPU for understanding assembly language

WinAli is a model assembler for Windows. It emulates a real CPU and is meant to help students learning and understanding the Assembly language. German Wikipedia article: ...
11
votes
4answers
868 views

Convert x-illion into standard form

Given a string, consisting of a prefix and then "illion", convert this number into standard form. For example: "million" -> 10^6 "trillion" -> 10^12 "quattuordecillion" -> 10^45 The ...
20
votes
1answer
592 views

Can you hear me now?

Background You are a rich executive of a software empire. Your time is worth a lot of money. As such, you must always travel in the most efficient route possible. However, as an executive, you spend ...
1
vote
1answer
269 views

Find a representative submatrix

You have a matrix of size m x n. Each cell in the matrix has a uniformly random integer value v, where 0 ≤ v < i, and i ≤ (m x n). (Meaning, the matrix contains a maximum of m x n distinct values, ...
0
votes
2answers
88 views

Approximated (unsorted) square from a set of values [closed]

So a colleaque came with this problem lately and I want to challange you to solve the problem in the code-golf style, shortest solution in any language wins. The Problem: Given is a random set of ...
5
votes
2answers
612 views

Draw a Golden Spiral!

Given a number n, you must output a golden spiral with the number of quarter turns being n. The spiral must be completely black and the background must be completely white. This must be output as a ...
8
votes
8answers
560 views

Verify Magic Square

A magic square is a square array of numbers with side n consisting of the distinct positive integers 1, 2, ..., n² arranged such that the sum of the n numbers in any horizontal, vertical, or main ...
6
votes
3answers
516 views

Riemann Series Theorem

The Riemann series theorem states that the terms of a conditionally convergent series can be permutated such that the resulting series converges to an arbitrary value. The Challenge Write a program ...
1
vote
1answer
244 views

Chotchkies Restaurant [duplicate]

Because there isn't enough xkcd on PPCG... Challenge The challenge is the same as above - given a menu and a total price, you need to find what the customer ordered. The menu will be supplied as ...
10
votes
1answer
365 views

Factor a polynomial over a finite field or the integers

Without using any built-in factoring/polynomial functions, factor a polynomial completely into irreducibles over the integers or a finite field. Input Your program/function will receive some prime ...
14
votes
8answers
626 views

Tetrahedron Surface Area

The challenge This challenge is very straightforward. Given four 3-dimensional points, calculate the surface area of the tetrahedron that they form. This is code-golf, so shortest code wins. Standard ...
6
votes
7answers
575 views

Find the simplest value between two values

Goal Your goal is to find the simplest value in an open interval. In other words, given two values a,b with a<b, output the simplest x with a<x<b. This is a code golf, so fewest bytes wins. ...
3
votes
3answers
151 views

Convert number bases [duplicate]

What your function must do: be as short (in bytes) as possible take 3 inputs that are strings: number , fromdigits, todigits assume no digit is repeated in fromdigits or todigits assume fromdigit and ...
7
votes
3answers
551 views

Help me with trigonometry!

Thank you guys so much for your help with calculus. Now I need some help with my upcoming trigonometry test. On the test, I'll need to simplify expressions. I’ll be given input like 4sin(x)/(2cos(x)) ...
7
votes
20answers
1k views

Minimum excluded number

This is intended to be an easy, bite-size code-golf. The mex (minimal excluded number) of a finite collection of numbers is the smallest non-negative integer 0, 1, 2, 3, 4, ... that does not appear ...
5
votes
8answers
396 views

Subdivide-Sum Sequence

Consider the digits of any integral base above one, listed in order. Subdivide them exactly in half repeatedly until every chunk of digits has odd length: Base Digits Subdivided Digit ...
20
votes
14answers
2k views

un-round fractions

When you convert a fraction a decimal number and you want to store that number, you often have to round it, because you only want to use a certain amount of memory. Lets say you can only store 5 ...
45
votes
10answers
8k views

Little Chandler is sad. Draw him a cloud to cheer him up

Little Chandler is sad. Draw him a cloud to cheer him up. Note: Drawing a cloud won't actually cheer him up. A circle can be defined as a 3-tuple (x,y,r) where x is the x position of the circle on a ...
11
votes
5answers
1k views

It’s time to do the math

Introduction This is one of my favorite math puzzles. Given a digit (say 3) and the number of times to use that digit (say 5), generate 10 expressions which result to 1, 2, 3, 4, 5, 6, 7, 8, 9 and ...
9
votes
4answers
785 views

Anagramming Code

Let's try this again. The object of this contest is to make two pieces of code that are anagrams of each other (the two must contain the same bytes in a different order), and they will do the ...
8
votes
9answers
1k views

Fibonacci domino tiling

There's classic combinatorial result that the number of ways to tile a 2*n strip by 1*2 dominoes is the nth Fibonacci number. You goal is to print all the tilings for a given n, drawn with dashes and ...
8
votes
7answers
2k views

The Bowlers-Golfers Fraction War

Introduction Let's start by arranging all fractions from 0 to 1 in order of lowest denominator, then lowest numerator: 1/2, 1/3, 2/3, 1/4, 3/4, 1/5, 2/5, 3/5, 4/5, 1/6, 5/6, 1/7... Note that ...
10
votes
4answers
515 views

How NOT to reduce fractions

Reducing fractions the wrong way In this code-golf challenge you have to find fractions that can be reduced the wrong way but still end up in the same number. Note: reducing fractions the worng way ...
13
votes
6answers
731 views

Electron Configurations

Electron Configurations Your mission is to accept an element's atomic number as input, and output its electron configuration (e.g. 2,8,8,2 for calcium). Input An atomic number from 1 to 118. You ...
13
votes
7answers
608 views

Find a criminal from his ear, finger, and head

Prior to the discovery of fingerprints and DNA testing, the British police used an anthropometric system to identify repeat offenders. Certain parts of the bodies of criminals were measured and stored ...
15
votes
4answers
395 views

Numbers on a Chain

Some positive integers can be shown to have a property called Chain divisibility. For a number to be chain-divisible by n, it must fulfil three requirements: Each digit divides the number formed ...
5
votes
5answers
386 views

Draw centered polygonal numbers

A centered polygonal number is able to be put into an arrangement of multiple concentric polygons, each with a side length of one more than the inner one. For example (image from linked page), the ...