This challenge is intended to be solved by using, creating, or resolving some processing algorithm.
-3
votes
1answer
214 views
Implement a Rock, Paper, Scissors algorithm which wins in the long run against a human [closed]
Rules as per Paper, Scissors, Rock
Both human and algorithm can record the history of play.
-1
votes
3answers
110 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 ...
1
vote
2answers
199 views
Giant Babylonian Matrices
Introduction
The Babylonians had a clever method for finding square roots. To find the square root of a number N, you start with a guess, then refine it by repeatedly evaluating a line of computer ...
-2
votes
0answers
64 views
List all negative cycles in a graph [closed]
Given a directed graph with vertices V, edges E, and an edge-weight dictionary W, find and list all negative cycles in the graph (positive and negative edge-weights are allowed).
15
votes
9answers
1k views
Reverse order of words in a string inplace
The Task
You are given a mutable string that matches [a-z]+( [a-z]+)*.
You must mutate it into the string which contains the same words, but in reverse order, so that "hello there everyone" becomes ...
5
votes
1answer
135 views
Challenge: compress co-occuring columns into cartesian product
This challenge is inspired by a problem I encountered recently out in the real-world, though ultimately I cheated and found a workaround.
Challenge
The input is a space-separated table of characters ...
5
votes
7answers
635 views
Super speedy totient function
The goal is simple: calculate the totient function for as many numbers as you can in 10 seconds and sum the numbers.
You must print your result at the end and you must actually calculate it. No ...
10
votes
7answers
1k views
Filter a large file quickly
The challenge is to filter a large file quickly.
Input: Each line has three space separated positive integers.
Output: All input lines A B, Tthat satisfy either of the following criterion.
...
19
votes
10answers
3k views
How high can you go? (A coding+algorithms challenge)
Now that everyone has developed their (often amazing) low level coding expertise for How slow is python really? (Or how fast is your language?) and How Slow Is Python Really (Part II)? it is time for ...
14
votes
5answers
1k views
Closest fraction
Task:
Your program is given a proper, positive simple fraction in the format <numerator>/<denominator>.
For this input, it must find two fractions.
A fraction that is less than the ...
-2
votes
2answers
98 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'):
...
16
votes
7answers
2k 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
165 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 > ...
18
votes
5answers
863 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
872 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
711 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
226 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
149 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
923 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
312 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
229 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
279 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
642 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
232 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
72 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
345 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
511 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
877 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; ...
53
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 ...
4
votes
1answer
266 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
104 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 ...
-11
votes
3answers
374 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
197 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
593 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
418 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
778 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
678 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
441 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
816 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
152 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
884 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
457 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 ...
20
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
662 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 ...