Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [algorithm]

A puzzle related to algorithmics (a main concept in computer science).

76
votes
7answers
17k views

Why does this solution guarantee that the prince knocks on the right door to find the princess?

I found this puzzle online: On the top floor of a castle lives a princess. The floor has 17 bedrooms arranged in a row. Each bedroom has doors connecting to the adjoining bedrooms as well as to the ...
29
votes
5answers
3k views

Switch The Knights

On a small $ 4 \times 3$ chessboard, the top row is filled with black knights and the bottom row with white knights. On each move, you may move one knight (as it moves in chess) to an unoccupied ...
27
votes
7answers
2k views

23 Clones and Two Lightbulbs

Rise and shine, Mister Bond. James awoke to find himself yet again imprisoned by an evil genius. At least, that's what he presumed. He was alone in a room with a strange device: it consisted of a ...
23
votes
7answers
1k views

Wolves and sheep

All the sheep were living peacefully in the Land of Shewo. But suddenly they were struck by a danger. A few wolves dressed up as sheep entered the territory of Shewo and started killing the sheep one ...
22
votes
7answers
5k views

Hacking an electronic keypad

You are a spy trying to break into an enemy facility. The back door is protected by an electronic keypad lock. You know that this particular lock is opened by a four digit code. Any stream of button ...
21
votes
5answers
918 views

Confused Soldiers

A squad has $n$ soldiers. Their impatient commander yells at them to form a line going East to West, with everyone facing East. They quickly manage to form an East/West line, but some soldiers are ...
20
votes
4answers
1k views

Checkerboard Infection: The Aftermath

As in this previous puzzle, we are again playing with our favorite bacteria, C. Coli, whose natural habitat is an 8x8 checkers board. These are very nasty bacteria - once they are in a cell of a ...
20
votes
2answers
1k views

Desegregate the Knights

You are given a 3 by 3 chessboard with a knight on each corner, where the knights in the top row are black and in the bottom row are white. On each turn, you may move a knight of either color (the ...
19
votes
4answers
2k views

Checkerboard Infection

There is a dangerous bacteria, Checkerichia Coli, (or C. Coli for short) which lives in the squares of checkerboards. Squares with this bacteria living in their digestive systems are said to have "C-...
19
votes
1answer
1k views

Mystery operation

In a future not so far way, Earth archaeologists find on a far away planet a fragment from a long lost civilization. This fragment involves an unknown operation *|*...
18
votes
5answers
4k views

Maze Solving Robot

Archie the archeologist has discovered an Egyptian temple, and plans to send in a robot to explore it. He uncovered the ancient engineers' papyruses which explain almost everything about the temple's ...
18
votes
4answers
2k views

Consecutive Towers of Hanoi

Consider the following variant of the Towers of Hanoi puzzle. There are six pegs. One of the pegs has a stack of $n$ differently sized disks, sorted by size so the smallest disk is at the top. All ...
16
votes
5answers
4k views

Can you recreate this fractal I randomly made?

This fractal looks relatively simple, but how would you generate it? On a smaller scale: I made it using a 1D cellular automaton with a four cell neighborhood: ...
16
votes
8answers
1k views

Rigged casino that prevents pairs

This question is still active as the answer from @Sleafar has just arrived. Not yet solved. Scenario The heads of 3 top terrorist organisations are planning to play an extremely high-stake poker ...
16
votes
2answers
6k views

A general solution to the decanting problem? (aka jug-pouring, water-pouring)

Take a look at these two questions: - A Set of Water Jug Challenges - Pouring problem Now I'm asking for a generalised solution to that problem. I define the problem as follows: You are required ...
15
votes
5answers
632 views

Blindfold Bingo

Congratulations, you have been selected from among the audience to compete in the fabulous Blindfold Bingo challenge! (cue annoying, yet catchy theme music.) Here you see our perfectly ordinary Bingo ...
13
votes
4answers
345 views

20-Questions on a grid

Posted this on /r/puzzles too, none have given the right strategy as of now :) There is a square grid of width and height $m$. Three facts about the grid: Each cell has a value, and no two cells ...
12
votes
5answers
1k views

Radioactive Rods

You have 8 identical looking rods, 2 of which are radioactive, though you don't know which. You also have a box which can test for radioactivity, which can hold any number of rods. After the test, the ...
12
votes
7answers
3k views

Fastest way to collect an arbitrary army

I am looking for solution of this puzzle: There is a kingdom with a square shape with sides of length 1. The castle is located at the center of the square. At the castle the king lives under the ...
12
votes
2answers
363 views

Cubical Infection

You may remember the C. Coli bacteria, which infects checkerboard squares. There is a similar disease which plagues cubes, known as cubic lice. Once a cube gets infested with cubic lice, it will be ...
12
votes
1answer
669 views

What is the optimal first move in Mastermind?

For a given number of positions/holes and a given number of colors, which initial guess eliminates the most possibilities for the solution at a minimum? For 4 positions, it's AABB. What is it for 5, ...
11
votes
4answers
281 views

Rank the Fencers

There are five fencers. Each has a particular skill level, all of which are different. When two fencers duel, the one with the higher skill level always wins. How many duels do the fencers need to ...
11
votes
3answers
1k views

The Generous Taco stand

There are a group of people standing in line for a taco stand. This taco stand is special in that it's slogan is "The older you are, the more you get!". To make sure though that there isn't any funny ...
10
votes
1answer
496 views

Half-reverse operation on binary strings

Is there an algorithm that you can apply twice to an input string of $0$s and $1$s in order to reverse it? In other words, is there a function $f : \mathrm B \to \mathrm B$ on the set of binary ...
10
votes
3answers
4k views

How do I memorize parity algorithms for higher-order Rubik's cubes?

I know how to solve a Rubik $4\times4\times4$ or $5\times5\times5$ or bigger, but I have problem with a specific algorithm: the parity error. What's the shortest parity algorithm for $n\times n\times ...
10
votes
2answers
1k views

3x3x3 Rubik's Cube Illegal State

After I learned how to solve a 3x3 Rubik's Cube and a 4x4 Rubik's Revenge, I began challenging myself to solve the cubes to different states rather than the normal solid sides. For instance, I'd solve ...
10
votes
2answers
475 views

Maze Solving Robot, More Difficult Variant

You are trying to design a maze solving robot, capable of solving "valid" mazes. A valid maze is an 8 by 8 checkerboard, surrounded by walls, where Between each pair of orthogonally adjacent squares, ...
10
votes
3answers
35k views

What is the Official notation on rubik's revenge(4x4)?

When solving a 4x4 cube you have specific notation to inner and outer lines, like R = Clockwise outer right and r = Clockwise ...
10
votes
2answers
1k views

Let's deal with “Names in Boxes” Safely

I met a puzzle, which is basically well known 100 Prisoners' Names in Boxes , but... it has an algorithm, which gives prisoners 100% chance to survive! This is achieved by a small change in the ...
9
votes
1answer
226 views

Puzzles like Sokoban?

I am looking for some puzzles like Sokoban or 15-puzzle but more difficult to solve and satisfy the following requirements: The number of possible moves at each step should be limited, let's say < ...
9
votes
1answer
244 views

Scoring Oracle: Bob easily wins, but how much?

Bob meets a magician with two bags and a chest on a bridge. The magician challenges him with the following enigma: Here is a bag A, holding 5080 pebbles. Here is another bag B. Most of the pebbles ...
8
votes
2answers
215 views

How to beat “Strata”?

Recently I purchased a bunch of mobile puzzle games for my iPhone and one of them was the famous top-rated app "Strata" by Graveck. The rules are simple - you begin with an $n \times n$ board, some ...
8
votes
4answers
412 views

Ten users, three lights but it's a chatroom

This is a variant of the classic problem of m prisoners n lights. (Example may be found here but note that the requirements are not exactly the same) The goal for you, however, is different. You want ...
7
votes
2answers
487 views

Numbers on a Blackboard

You are given an empty blackboard. Once a minute, you are allowed to do one of the following: Write two $1$'s on the blackboard Erase two copies of a number, $n$, and replace them with $n-1$ and $n+...
7
votes
3answers
353 views

A problem of inequalities

The puzzle Given a set of numbers $\{1,2,\ldots,n\}$ and an expression of inequalities, e.g., $ x_1 > x_2 < \cdots > x_n$. Prove that there always exists a solution such that $x_i \in \{1,2,\...
7
votes
2answers
2k views

Figure out this algorithm by analyzing the sequence of numbers generated

You are given a function f that, using an algorithm (that uses an old method), performs a calculation on four distinct values _ and generates a sequence of ten numbers. Now, your task is to figure ...
7
votes
2answers
1k views

Is there a simple algorithm for solving Kami 2 puzzles?

I'm finding my life has been consumed by Kami 2, partly because I seem to have achieved some "insight" and am able to solve the puzzles reliably, almost always on the first try. The rules are simple: ...
7
votes
1answer
162 views

It's getting harder and harder for my friends to like me

What is the next number in this sequence? 2, 3, 6, 7, 9, 18, 25, 27, 54, 73, 97, 129, 171, 231, 313, 327, 649, 703, ... ? Hint 1 Hint 2 This is my first puzzle and I'm new to PSE, so feedback is ...
7
votes
3answers
104 views

Creating a maze that is traversed by a pair of compasses

Normal mazes require you to move a point-like object from the entrance of the maze to the exit. I am wondering whether a different kind of maze would work as a puzzle: Imagine a maze printed on a ...
7
votes
4answers
1k views

Minimum cells to fill grid without consecutive neighbours

Imagine you have a m x n grid which is initially colored white. you can fill in a cell with black color if and only if there are no immediately neighboring black cells (no black cells to the left/...
6
votes
4answers
651 views

Lining Up Recruits

The good soldier Schweik had been ordered to line up a band of new recruits before their officer gave them a speech. The desired line sought to minimize the average difference in height of adjacent ...
6
votes
1answer
294 views

Avoiding Incest and Intergenerational Mating

On the planet of Caturn, God created $m$ male cats and $f$ female cats, each with zero stripes. At any time, two cats of opposite genders can mate, giving birth to a cat with a gender of the parents' ...
6
votes
1answer
174 views

A couples therapy mixer situation

During couples-group-therapy, where two therapist and multiple couples consisting of two people each are present and we all sit on chairs forming a circle in the middle of the room. We often discuss ...
6
votes
1answer
257 views

Placing markers in grid and minimize similarity of rows

Imagine a game on a grid of $m$ rows and $n$ columns. Player One will place a fixed number $r$ of markers in each row. Player Two will select the two rows which maximize the number of columns having ...
5
votes
2answers
156 views

Find the result of this dual key cipher

I came up with a neat little cipher that I'm calling the dual key cipher. The basic premise is that there are two cipher keys that, when used together can decode the cipher text against a given ...
5
votes
2answers
221 views

Patriotic Solitaire

You are given a $3\times n$ checkerboard, covered with $n$ red, $n$ white, and $n$ blue checkers. Call a board patriotic if every column has a red, white and blue checker. You want to make the given ...
5
votes
3answers
208 views

Fill $N$ by $M$ grid with numbers in such a way that any given cells' neighbors are different

Create an $N$ by $M$ grid with numbers in such a way that satisfies following conditions: numbers should be integers that range from $1$ to $r$. for any cell $C$, all its adjacent neighbors (i.e. ...
5
votes
1answer
107 views

Shortest path for delivering packages [duplicate]

A version of the Travelling Salesman Problem, but with certain points. We are talking about a town where 8 canals run from the middle boathouse into the city. You can only travel one way on the green ...
5
votes
2answers
4k views

Is there an algorithm for the Rubik's 360?

Is there an algorithm to help me solve the Rubik's 360? Usually I just do it at random, but I rarely succeed.
5
votes
3answers
373 views

Place 16 queens in a $16\times 16$ board peacefully, also in subboards!

What is the smallest number, $n$ in which $n$ queens can live in a $n\times n$ board peacefully? Of course not more than 8. ☺ (read about the eight queen puzzle) But this was not the question. ...