A puzzle is a problem or enigma that tests the ingenuity of the solver. Solutions may require recognizing patterns and creating a particular order.

learn more… | top users | synonyms

15
votes
1answer
541 views

Android Lock Screen

Intro You are sitting in a board room at the end of a long table. You look around and see Tim Cook, the Apple Board of Directors, the ghost of Steve Jobs, and Jack Donaghy. Apple has called this ...
15
votes
1answer
239 views

Fillomino Solver

Fillomino is a puzzle where you fill a grid with polyominoes. Each polyomino is an area of contiguous cells. The grid representation shows what size polyomino is covering each cell. For example, a ...
28
votes
9answers
3k views

Kolmogorov-mania

The Kolmogorov complexity of a string s is defined as the length of the shortest program P that outputs s. If the length of P is shorter than the length of s, then s is said to be compressible, ...
-3
votes
4answers
176 views

Generate a number series that resembles multiplication table [closed]

Write a program that print following series 12345678910, 2468101214161820, 36912151821242730 ..... As you see these are multiplication tables for 1, 2 ,3 Catch here is that you have to use ...
8
votes
10answers
885 views

3 and 5 Litre Jug Puzzle

You may have seen this one in Die Hard: With a Vengeance... This question is based on the famous 3 and 5 Litre Jug Puzzle, but with a slightly different slant. Golf up some code that when given an ...
3
votes
1answer
195 views

Match strings whose length is isolated prime

Isolated prime definition from Wikipedia: An isolated prime is a prime number p such that neither p − 2 nor p + 2 is prime. In other words, p is not part of a twin prime pair. For example, 23 is ...
14
votes
4answers
857 views

Match strings whose length is a fourth power

Within the scope of this question, let us consider only strings which consist of the character x repeated arbitrary number of times. For example: <empty> x xx xxxxxxxxxxxxxxxx (Well, ...
5
votes
6answers
453 views

Finding n'th character in a Lucky String

Lucky numbers are those numbers which contain only "4" and/or "5". For example 4, 5, 44, 54,55,444 are lucky numbers while 457, 987 ,154 are not. Lucky number sequence is one in which all lucky ...
12
votes
5answers
771 views

Code Injection works in C# too!

Given the following C# program outputting False, inject a 'malicious' line of code such that the program outputs True. class Program { static void Main() { ...
3
votes
4answers
217 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 ...
-3
votes
1answer
115 views

Apples, many apples, green and red [closed]

We can eat 3 apples per hour. We must eat: 3 green apples once per 2 hours. 4 red apples once per 3 hours. We can't eat fractions of an apple. The apples are named, the 3 green (A, B, C) and the ...
3
votes
4answers
322 views

Obtaining ordering of cards [closed]

You are given a deck containing n cards. While holding the deck: Take the top card off the deck and set it on the table Take the next card off the top and put it on the bottom of the deck in your ...
-12
votes
3answers
348 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 ...
12
votes
8answers
788 views

Minimum number of Jumps

Given a sequence of numbers, find the minimum number of jumps to go from the starting position to the end and come back to the starting position again. Each element of the sequence denotes the ...
8
votes
10answers
756 views

N Doors, K Monkeys

There are N doors and K monkeys. Initially, all the doors are closed. Round 1: The 1st monkey visits every door and toggles the door (if the door is closed, it gets opened it; if it is open, it gets ...
0
votes
3answers
150 views

Permutable functions [closed]

In your favourite programming language, write two functions f and g such as f(g) gives the same (not trivial) result as g(f), but f and g are different (signifiant changes, not only trivial ...
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 ...
12
votes
1answer
577 views

When is a giraffe not a giraffe?

I hope this kind of "riddle" is ontopic in Programming Puzzles & Code Golf. Give an example of a situation where the C# method below returns false: public class Giraffe : Animal { public bool ...
3
votes
5answers
527 views

(Python) Implementing incrementation

Challenge: Implement incrementation without addition, multiplication, exponentiation, and any higher binary operators (and their opposites) in Python. Winner is the person who can do it in the least ...
6
votes
0answers
567 views

Rubik's Revenge

Everyone likes a good puzzle. After all, that's the basis for Code Golf and Code Challenge! What better puzzle exists than the famous Rubik's Cube? Well what else but her slightly larger sister, ...
-3
votes
2answers
355 views

Strings: Microsoft interview

You are given an array of strings , you have to construct a single array containing all of them so that the same array of strings can be reconstructed from the large array. The strings may contain any ...
9
votes
0answers
658 views

Build a working game of Tetris in Conway's Game of Life

Here is a theoretical question - one that doesn't afford an easy answer in any case, not even the trivial one. In Conway's Game of Life, there exist constructs such as the metapixel which allow the ...
1
vote
2answers
368 views

solve puzzle with a tweet? javascript (fun challenge)

the question is "complete this subtraction by replacing the asterisks with digits so the numbers 1-9 only appear once each" 9** -*4* ____ **1 my code tries random numbers until it works, and ...
6
votes
0answers
387 views

Shortest 2-Player Game of Halma

In Chess, it's possible for the game to end after 4 moves (2 each) with a Fool's Mate. Your goal is to find the Fool's Mate of Halma: the 2-player game of Halma that minimises the number of turns ...
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 ...
5
votes
3answers
726 views

Build a Killer Sudoku Solver

You thought regular sudoku was hard, now try Killer Sudoku! In the game of Killer Sudoku, you aren't given any numbers at all. Instead, you're given regions that are said to add up to a certain ...
10
votes
4answers
389 views

Build a readability index

The Flesch-Kincaid readability algorithm depends on the measures of word count and syllable count, neither of which is entirely objective, or easily automatable using a computer. For example, does ...
1
vote
1answer
435 views

Write the implementation to pass this test

Given the following test, implement an addOne function in C# so it passes, without any modification to the test. TIP: Yes, it is possible. [TestMethod] public void TheChallenge() { int a = 1; ...
4
votes
4answers
691 views

A programming challenge. Number Cross Puzzle

This is from a programming challenge website. The cross problem states that you can place the numbers 1 through N inside the cross such that no two adjacent cells in any direction (up, down, left ...
8
votes
4answers
872 views

m3ph1st0s's programming puzzle 3 (C): “Easy bug”

This is the 3rd of my series of C/C++ puzzles; in case you missed the first 2 they are here: (1) m3ph1st0s's programming puzzle 1 (C++) (2) m3ph1st0s's programming puzzle 2 (C++): "Call ...
3
votes
4answers
430 views

m3ph1st0s's programming puzzle 2 (C++): “Call hard!”

I am back with a brand new puzzle for C/C++ addicts. Following the feedback received on the 1st puzzle, this time I will try to make the requirements crystal clear and to provide a perfectly valid ...
2
votes
0answers
358 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
283 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
4answers
1k views

A simple Knight's problem

How many ways are there to place a black and a white knight on an N * M chessboard such that they do not attack each other? A knight can move two squares horizontally and one square vertically, or ...
1
vote
1answer
227 views

does this matrix represent some string [closed]

One of my friends asked me this.. What does this represent? Some string? A B C D A = > < > B < = < < C > > = > D < > < = the only thing I have been able ...
9
votes
1answer
601 views

What is the minimum set of characters with which you can write any valid python program?

The proof of the set of characters is that there is a translator which takes any ascii python program as input and produces a limited character set version of the program. The limited character set ...
15
votes
1answer
3k views

Solve the 15 Puzzle (the tile-sliding puzzle)

The 15 Puzzle is a famous puzzle involving sliding 15 tiles around on a 4x4 grid. Starting from a random configuration, the goal is to arrange the tiles in the correct order. Here is an example of a ...
6
votes
2answers
338 views

Generate a valid equation using user-specified numbers

This is based on a game one of my math teachers used to play in middle school. He would write 5 random one-digit numbers on the board, and then a random two-digit number. We would try to create an ...
3
votes
3answers
2k views

Code Solution for the Magic Hexagon

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 ...
-5
votes
1answer
272 views

Sort an array with values of integer

There is an array of integer values to be sorted.During the sorting process, the places of two numbers can be interchanged. Each interchange has a cost, which is the sum of the two numbers involved. ...
9
votes
0answers
702 views

Minimal Sudoku Generator [closed]

Ask questions if you need to, I'll elaborate on anything that needs clarified. My challenge is to unsolve a sudoku to a minimal state. Basically take a supplied, solved, sudoku board and unsolve it ...
7
votes
3answers
919 views

Solve the 14-Pegs puzzle

Introduction A common puzzle involves a triangular board with 15 holes for tees/pegs as shown in the image below: Starting with all the pegs in the board except for a hole at the top, the point of ...
13
votes
2answers
658 views

Code golf: Solve a Knights and Knaves logic problem by parsing English

Background There are two people, Bill and John. One of them is a knight, which always tells the truth, and the other is a knave, which always tells a lie. You don't know who is the knight and who is ...
6
votes
2answers
426 views

Which Numbers Would Crash this Function?

Which values of x and y will cause a crash with some C compilers? int f(int x, int y) { return (y==0) ? 0 : (x/y); }
82
votes
37answers
10k views

Write a program that always outputs “2012” - even if it's modified!

This idea is not mine, though I don't know where it originated. I once met it in a programming contest very long ago (1998, if I remember correctly). The task is to write a program in your favorite ...
1
vote
2answers
257 views

Construct the largest possible rectangle out of line segments of given lengths [closed]

I recently participated in a competition where I was asked this question. Given an array with lengths what is the area of the biggest rectangle that can be made using ALL the lengths. The lengths can ...
-1
votes
3answers
321 views

Programming puzzle to print all numbers from 1 to n of a random system

I have a number system with the symbols {a,b,c,d,...n} I want to print the sequence a b c . . . n aa ab ac .. nn aaa aab aac ... nnn ... and so on. A pseudocode/algorithm is what I am looking ...
2
votes
10answers
907 views

Count the number of times a function runs

This is a teaser a friend of mine sent. It seems straightforward, but I can't seem to get my head around it, probably due to my lack of sleep. You have 16 bits available. Compose a function, and ...
4
votes
3answers
916 views

Lights Out - Find the solution

(This code golf task is related to Code-Golf: Lights Off!. The same puzzle is used, but the task is different.) Introduction "Lights Out" is a puzzle in which you should switch off all lights in a ...