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

learn more… | top users | synonyms

-2
votes
2answers
84 views

All possible permuations in lexicographical order [duplicate]

Given a string of English alphabet characters, write the shortest code to print all possible permuations in lexicographical order without using any language based library. def function('bca'): ...
15
votes
6answers
1k views

Predict where the man will go

A man lives in the north-west corner (0, 0) of a town with height h and width w . Everyday he walks from his home to the border (?, w) or (h, ?). In the following example, the man goes to (3, 3) ...
3
votes
0answers
156 views

Hack Sequence : Simplify Hi = 2014*Hi-1 + 69*Hi-2 [closed]

Can someone help me with simplifying this sequence. I write code to loop through entire n, I am getting timeout. Hack sequence of IndiaHacks-2014 if given as below Hi = 2014*Hi-1 + 69*Hi-2 for (i > ...
16
votes
3answers
508 views

Tower of Hanoi Sort

Write a function/subroutine to sort a list of integers, Tower of Hanoi style. You will be given a stack of integers. This is the main stack. You are also given two more helper stacks. These helper ...
23
votes
6answers
834 views

Circles dividing the plane

This problem idea is borrowed from a recent Croatian programming contest but please don't cheat by looking at the solution outlines :) You are given a set of circles in the plane with their centers on ...
22
votes
1answer
658 views

Minesweeper Solver

We already generated Minesweeper fields, but someone really has to sweep those generated mines before PCG blows up! Your task is to write a Minesweeper Solver that is compatible with a slightly ...
7
votes
3answers
213 views

Determine the critical path

In project management there's a method, called the critical path method, that is used for scheduling activities and for determining which activities' timings are crucial (i.e. critical) and for which ...
2
votes
2answers
139 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 made of lines that have the same format : A concatenation of a fixed-size key (the same among all the file ...
36
votes
1answer
863 views

Minimal keystrokes needed to type a given text

We all know that programmers tend to be lazy. In order to maximize your free time, you decide to write a program that outputs a minimal number of keystrokes for text fed into it. Input: Text that ...
13
votes
2answers
302 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
182 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
276 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 ...
5
votes
10answers
617 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
212 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
279 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 ...
11
votes
19answers
1k 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: ...
5
votes
11answers
498 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
662 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; ...
51
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 ...
3
votes
1answer
199 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
97 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
347 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
192 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
590 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
392 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
610 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
653 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
92 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[]) { ...
18
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
434 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
1k 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
781 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
134 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
144 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
861 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?
8
votes
1answer
430 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 ...
18
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
642 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
457 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
1k 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
538 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
403 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
707 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
454 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
460 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
348 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
626 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 ...
6
votes
2answers
718 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, ...