This challenge is intended to be solved by using, creating, or resolving some processing algorithm.

learn more… | top users | synonyms

6
votes
0answers
49 views

Crossword Compulsions!

Chris, a cryptic crosswords addict, has a set algorithm for the order in which he solves them. We will use the above image as a guide. Chris always starts off with the first across clue, in this ...
0
votes
0answers
121 views

Find the best path in a “match-3” game

Suppose you want to cheat in a "match-3" game. In this "match-3" game: In each turn you can move a gem along a path. For example, you can move a gem right-right-down, as in A. (The gems are ...
5
votes
6answers
267 views

Generate lists in which every sublist has a unique element

The problem is defined as follows: Create a function that takes an integer and returns a list of integers, with the following properties: Given a positive integer input, n, it produces a list ...
3
votes
10answers
588 views

Write a hash function for Morse Code

Your goal is to write a hash function, that accepts morse code character and returns a hash code that you get to define. You can be sure, passed string will be: One of the Latin characters (A-Z) ...
9
votes
1answer
186 views

Find the best immediate move in a “match-3” game

Your challenge today is to take input like this: fbcfbee ffcabbe debceec bccabbe edcfbcd daeaafc eebcbeb And output the best possible move in a Bejeweled-like game that will match three or more ...
0
votes
0answers
70 views

Last-letter-first-letter sort [duplicate]

Given a list/array of names(String) sort them such that each name is followed by a name which starts with the last character of the previous name. input [ Luis Hector Selena Emmanuel ...
-7
votes
2answers
217 views

Algorithm to find one unique number in one million and 1 numbers [closed]

I have been asked this question in an interview. In 1 million and 1 numbers, all the numbers having the duplicate except only one number. How to find that one number ? I got an idea to use EXOR gate ...
9
votes
17answers
939 views

Sort the distinct elements of a list in descending order by frequency

Write a function which takes a list or array, and returns a list of the distinct elements, sorted in descending order by frequency. Example: Given: ...
4
votes
11answers
425 views

Convert a decimal to a fraction

Write a program that converts a decimal to a mixed, simplified fraction. Sample input: 5.2 Sample output: 5 + (1/5) The code with the shortest length in bytes wins.
3
votes
12answers
532 views

Array Merge without Duplicates

I recently saw this Javascript code on StackOverflow for merging two arrays, and removing duplicates: Array.prototype.unique = function() { var a = this.concat(); for(var i=0; i<a.length; ...
48
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 ...
2
votes
1answer
153 views

Decompose a range in aligned blocks of size 2^n

Given an arbitrary contiguous range of positive integers, find the decomposition in the minimum number of sub-ranges of size L = 2^n, with the constraint that each range must be aligned, that is the ...
-5
votes
2answers
88 views

Primality Number test [duplicate]

For given number, output true or false(*1* or 0 is also fine) if it's prime or not. Rules If your language have a native method isPrime() you can't use it. Winning condition: Most time-efficient ...
-12
votes
3answers
297 views

Swapping numbers, the shortest code wins [closed]

The goal is to swap 2 numbers. The shortest code wins. Temporary variables are not allowed You can manipulate only one variable at a time One of the variables may be 0
4
votes
3answers
187 views

Update All with O(1) [closed]

Create a data structure to represent an array. It must implement those function in O(1) get(index); // return the data at @index update(index, value); // update the data at @index to ...
11
votes
6answers
579 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 ...
3
votes
0answers
347 views

Efficiently packing rectangles on a strip of paper

Algorithm for nesting submited jobs to reduce paper roll usage. Working with a 36" large format printer, with paper roll as source (150feet=45meters). With a delay loop on print server queue: ...
12
votes
14answers
2k views

Write a program which performs brute force letter combination until the word “password” is found

The program should print every letter combination (lowercase or uppercase, it doesn't matter) in alphabetic order. It must start with a and the last printed combination should be password. The output ...
0
votes
3answers
490 views

javascript: smallest code to convert seconds to time [closed]

Given seconds like 11728, write the smallest javascript function that returns a string like 3hrs. 15min. 28sec. signature textTime([int] t,[bool] z,[bool] m) t is the time like 11728 and you can ...
8
votes
4answers
642 views

No branching please

Anyone who is moderately into low level code optimization know about the perils of branching, be it implemented as if-statements, loops or select-statements the possibility of a branch misprediction ...
0
votes
0answers
89 views

reversion of string in c [duplicate]

In python reversing of string is as easy as: string[::-1] But not very same in c. This is the code I am using to reverse integers in C: #include <stdio.h> int main(int argc, char *argv[]) { ...
17
votes
10answers
2k views

Flipping pancakes

In pancake sorting the only allowed operation is to reverse the elements of some prefix of the sequence. Or, think of a stack of pancakes: We insert a spatula somewhere in the stack and flip all the ...
9
votes
1answer
419 views

Fix unbalanced brackets

Consider the alphabet A ="()[]{}<>". Think of the characters in the alphabet as opening and closing brackets of 4 different types. Let's say that a string over the alphabet A is balanced if it ...
21
votes
6answers
982 views

Shortest common superstring

Given a list of strings s_0, s_1, ..., s_n find the shortest string S that contains each of s_0, s_1, ..., s_n as a substring. Examples: S('LOREM', 'DOLOR', 'SED', 'DO', 'MAGNA', 'AD', ...
17
votes
2answers
759 views

The number of possible numeric outcomes of parenthesizations of 2^2^…^2

Consider an expression 2^2^...^2 with n operators ^. Operator ^ means exponentiation ("to the power of"). Assume that it has no default assosiativity, so the expression needs to be fully parenthesized ...
-1
votes
1answer
133 views

Filling slot based on limit [closed]

Duplicate of http://stackoverflow.com/questions/15726734/iterating-item-in-a-loop I have a List<int> with the values like 60,45,45,45,45,30,60,60,15 people Also i have two slots. 1st slot is ...
-2
votes
1answer
140 views

IPv4 “in subnet” function [closed]

Implement the following JavaScript method as short as possible: function same_subnet(ip_a,ip_b,sn_mask) { } It should get 2 IP addresses and a subnet mask. It should return true if ip_a and ip_b ...
1
vote
10answers
796 views

recursive power algorithm

Have a look at my (javascript) version of a O(log(n)) xn algorithm: function pow(x,n) { return n==0?1:n==1?x:n==2?x*x:pow(pow(x,(n-n%2)/2),2)*(n%2==0?1:x); } Can you get it shorter?
7
votes
1answer
413 views

Generate a number by using a given list of numbers and arithmetic operators

You have a list of numbers L = [17, 5, 9, 17, 59, 14], a dictionary of operators O = {+:7, -:3, *:5, /:1} and a number N = 569. Task Output an equation that uses all numbers in L on the left-hand ...
17
votes
3answers
3k views

Solve Rubik's cube

Write the shortest program that solves Rubik's cube (3*3*3) within a reasonable amount of time and moves (say, max. 5 seconds on your machine and less than 1000 moves). The input is in the format: ...
9
votes
5answers
634 views

Swapping numbers

This is a common puzzle many of you have solved manually. Now this is the time to write an algorithm to solve the same. There are equal number match sticks lined up in two different side facing each ...
8
votes
8answers
444 views

Make a pattern alternate

Problem You are given a sequence of coloured balls (red R and green G). One such possible sequence is: RGGGRRGGRGRRRGGGRGRRRG In as few moves as possible, you must make it so that each ball is a ...
2
votes
2answers
870 views

Rail fence cipher

Write a program which reads a string and a key and encodes the string into a rail-fence cipher using that key. Similarly, write a program for reverse function, ie, deciphering a rail fence using a ...
12
votes
2answers
503 views

Compact a Befunge program

Befunge is a 2-dimensional esoteric programming language. The basic idea is that (one-character) commands are placed on a 2-dimensional grid. Control flow walks across the grid, executing commands it ...
-1
votes
2answers
399 views

“Defragmenting” a list

A fragmented file is a file which is seperated into several parts on a harddrive, because it can't fit into a certain space. On all harddrives, there are files called unmovable files, which are ...
3
votes
3answers
671 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 ...
4
votes
4answers
436 views

Fast inverse square root

Inspired by Write a code golf problem in which script languages are at a major disadvantage question on meta, I've decided to make a question which could be problematic for scripting languages. The ...
3
votes
2answers
438 views

Implement DES key expansion

I wanted to make a challenge to do the full DES encryption algorithm, but that may be a bit too involved to get a ton of participation. This challenge is to simply generate the 16 48-bit subkeys used ...
7
votes
5answers
340 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 ...
8
votes
7answers
605 views

Output a shuffled deck using random input

Input/Output: Input: A uniformly random, infinitely long, string of '0's and '1's, taken from stdin. The string is assumed to be truly random, not pseudo-random. It is uniform in that each ...
5
votes
2answers
665 views

Domino Effect Problem

Last week we had a programming contest in my university and I am very curious about one of the problems , one which only one team (but from another city) was able to solve. May be its not that hard, ...
-1
votes
1answer
328 views

The real knapsack problem

Given the number of goods N positive weight of each good weight[N] positive profit of each good profit[N] and a positive number W which is the knapsack capacity. This problem is called “the ...
4
votes
7answers
1k views

Generating n unique random numbers with a specific sum

Write an algorithm in any programming language you desire that generates n unique randomly-distributed random natural numbers (i.e. positive integers, no zero), sum of which is equal to t, where t is ...
12
votes
7answers
544 views

Write all possible Braille characters

An interesting puzzle came to me looking at the elevator buttons this morning. You are required to generate a list of all Braille patterns that fit in a 2x3 grid. Use a hash # to denote a bump and a ...
5
votes
1answer
215 views

Write a CFG acceptor

Write a program that, given a context free grammar and a string, returns whether the string is a word of the language defined by the grammar. Input Your program should read a context free grammar ...
2
votes
2answers
560 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 ...
2
votes
0answers
350 views

Splitting goods among people so that everyone feels happy

A favorite puzzle of mine: There are n people and k goods. The goods can be arbitrarily split (let's imagine they're different raw metals, for example). Your task is to split them among those n people ...
2
votes
1answer
266 views

Minimum number of transactions so everyone has paid the same

On a road trip, N people pay for fuel. Each pays a different amount. At the end of the trip, calculate the minimum number of transactions so that each person has paid the same amount. e.g. on the ...
-5
votes
2answers
323 views

Help Alice in giving candies

Alice is a kindergarden teacher. She wants to give some candies to the children in her class. All the children sit in a line and each of them has a rating score according to his or her usual ...
10
votes
19answers
2k views

Calculate pi to 5 decimals

This comes from http://programmers.blogoverflow.com/2012/08/20-controversial-programming-opinions/ "Given that Pi can be estimated using the function 4 * (1 – 1/3 + 1/5 – 1/7 + …) with more terms ...