# Questions tagged [fastest-code]

The winner of a fastest-code challenge is determined by the runtime performance of the submissions. For fairness, all submissions should be benchmarked on the same machine, which usually means all submissions have to be tested by the host of the challenge. For scoring by asymptotic time complexity, use [fastest-algorithm] instead.

144 questions
Filter by
Sorted by
Tagged with
850 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 ...
632 views

### Covering Array Validator

A covering array is an N by k array in which each element is one of {0, 1, ..., v-1} (so v ...
1k views

### Super fast sampling from a tricky random distribution

This is a micro-optimization challenge. The task is to sample from the maximally skewed stable distribution F(x;1,-1,Pi/2,0). See Table 1 of http://arxiv.org/pdf/0908.3961v2.pdf . It is easiest to ...
383 views

### Help the poor Cryptographers - DLP Edition

Introduction and Motivation I'm mainly active on Cryptography.SE and as such have already stumbled across the question: "How the hell am I supposed tools like cado-nfs to do stuff!?". They are super-...
385 views

### Write a FAST word equation solver

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. ...
3k views

### Fastest array-by-array nearest neighbour search

Intro - Nearest neighbour comparison between two arrays is something that can be done very efficiently when only 1 variable per array is involved, because it can be done by sorting and then performing ...
1k views

### Code-Challenge: Farey sequence (II)

Challenge In this task you would be given an integer N (less than 10^6), output the number of terms in the Farey sequence of order N. The input N < 106 is given in a single line, the inputs ...
805 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 ...
14k views

### Solve the Magic Hexagon [closed]

A magic hexagon is a hexagon where every row and every diagonal add up to the same value. In this case the value is 38. Each number from 1 to 19 must be used exactly once. This image shows a solution ...
714 views

### Analysing the most common words in a text, and replacing them with a single byte

This is a very crude text encoding algorithm I came up with the other day. It won't work if the text has more than 256 different characters in it – but it does support Unicode, at least in my Python ...
3k views

### Fastest modular exponentiation

The challenge is to write code in any open source, available on linux, language of your choice to perform modular exponentiation. The input will be two randomly chosen 2048 bit positive integers ...
3k views

### Carmichael Numbers

EDIT: I am changing the challenge. Write a program to print Carmichael numbers. The challenge is to print the maximum number of them in less than 5 secs. The numbers should be in increasing order. ...
308 views

### Find arrays with distinct subarray sums

Consider an array A of length n. The array contains only integers in the range 1 to ...
189 views

### Fastest way to iterate over sublattice of discrete lattice

I need to construct a functor that iterates over the linear representation of a sub-lattice of size $d_x,d_y,d_z,d_q$ embedded in a lattice of size $n_x,n_y,n_z,n_q$. The sub-lattice corner is ...
4k views

### Secret Santa Challenge [duplicate]

Possible Duplicate: Holiday Gift Exchange Background: Secret Santa is a Western Christmas tradition in which members of a group or community are randomly assigned a person to whom they ...
506 views

### List ALL prime-factorized natural numbers in ANY order

This is a variant of List prime-factorized natural numbers up to N in ascending order, but the solutions can be very different. Write a program that outputs prime factorizations of all natural ...
868 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 ...
322 views

### Find minimal set of rows to retain all unique values in each column

Given a matrix, the goal is to ensure all the values in each column occur at least once, while at the same time doing so requiring the least possible amount of rows. Fastest solution wins. Note: a ...
299 views

### Reproportioning a population by adding fixed sized groups

Introduction Say you have a population of people. This population is made up of 100 Alices and 25 Bobs. So, 80% of the population are Alices and 20% are Bobs. We want to change the proportional ...
286 views

### Multiplication in Brainfuck - minimum number of evaluations [closed]

Given two numbers in tape location #0 and tape location #1 in Brainfuck, compute their product into another tape location (specify with answer). Optimize for the least amount of time-units used, where ...
1k views

### remove duplicates from array [closed]

You have given an array from which we need to remove duplicates. Rules: First or immediate duplicates gets removed first. Array contains natural numbers ...
1k views

### position of the only 1 in a number in binary format [closed]

Every number of the form 2i (where i is a non-negative integer) has a single 1 in its binary representation. Given such a number, output the 1-based position of the ...
6k views

### compute number of 1 bits in a binary representation of a number

The goal is to write a program that returns number of 1 bits in a given number. Examples 5 -> 2 1254 -> 6 56465 -> 8 Winner The winning ...
4k views

### The fastest square root calculator

Write a program which outputs the square root of a given number in the shortest time possible. Rules It may not use any builtins or powering with non-integers. Input format as a function argument ...
864 views

### Fastest C/C++ comparison function for an opaque field containing doubles

Description: Write the fastest comparison function for an opaque field containing a double. Here is my example: ...
223 views

### Tips for Fastest Code challenges [closed]

What general tips do you have for how to answer fastest-code challenges? Please post one tip per answer. The objective of these challenges is to make the program that will run in the least amount of ...
208 views

### Merging text files based on a prefix key

Imagine an ordered file set : file1, file2, ... fileN. Each file is a textual file that is ...
419 views

### given prime factors of a number, what is the fastest way to calculate it's proper divisors? [closed]

Given prime factors of a number, what is the fastest way to calculate divisors? ...
1k views

### Find nth root of variable without using math operators/functions

Write a program which, given two positive integers n and x, will display the n-th root of x (which is also x1/n) in decimal to an accuracy of 0.00001. The program must output the resulting number in ...
120 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 ...
542 views

### Race to a Million

This falls under the Code puzzles the best. Fastest way to render the numbers 1-million in a web browser. Preferably using PHP, but use what you must. Numbers must be more than one on a line in the ...
288 views

### Creating a catalogue index

You have a program which creates an index for a catalogue. The last step is missing: it must find and consolidate page ranges within the list of pages for each entry. Each entry is currently an ...
314 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 a ...
281 views

### Generalization of Eight Queen Puzzle [closed]

Here's one generalized version of the famous Eight Queen's Puzzle: Given an n × n chess board, and an integer ...
40 views

### Searching for a sum [duplicate]

In this challenge you will take two inputs One input will be a string of numbers of any length which you will put into an array/table/whatever you call it in your language Ex: ...
486 views

### Fastest algorithm to output array containing all integers in range excluding duplicate digits

Input is a single integer in ascending digit order. The only valid inputs are: 12 123 1234 ...
258 views

### Find the fastest swim relay (shortest path of unique nodes and types)

fastest relay time = lowest possible total integer value of (a freestyle swimmers time) + (1 breastroke swimmers time) + (another backstroke swimmers time) + (another butterfly swimmers time) Each ...
126 views

### Symbol Search Deleter [rephrased] [closed]

Your challenge is to parse nonsensical text and output a "congruous phrase" - which I shall define here to be text with any contiguous characters in between, and including, a given set of like symbols ...
10k views

### Triangle Puzzle [closed]

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 ...
158 views

### Magical Squares [closed]

A perfect square is a number that is the square of an integer. However, let's define something called a Magical Square, which is a perfect square with the following restriction: The perfect square ...
672 views

### Solve the Diophantine Pell equation

Given a natural number c as input, our task is finding the fastest way to calculate one -atleast- availabe integer solution (a,b) of pell equation c=a²-b². Rules Built-in functions and loopholes ...
250 views

### Fastest N times Hello World (Java/C/ C++) [closed]

Not a new one: Input N, being n, 0 ≤ n ≤ 5. Output N times "Hello World." Example: Input 3 Output Hello World. Hello World. Hello World. These 2 are my ...
170 views

### Google search result short summary [closed]

Intro When you search in google, it always shows you a result with a sample text from the found webpage. For example if you search for "Madonna greatest vinyl", google will show you one line link, ...
1k views

### write a code the find n-th number of Gray Code list [closed]

Write a function that, given N >= 0, finds the Nth number in a standard Gray code. Example input: 1 2 3 4 Example output: ...