Questions tagged [algorithm]

A puzzle related to algorithms (a main concept in computer science). Puzzles may ask for an algorithm as an answer or require the analysis of a given algorithm.

Filter by
Sorted by
Tagged with
24 votes
3 answers
9k 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 ...
  • 8,722
93 votes
7 answers
23k 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 ...
  • 2,375
22 votes
4 answers
4k 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 &...
  • 31.5k
34 votes
9 answers
6k 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 ...
  • 1,198
28 votes
7 answers
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 ...
  • 31.5k
13 votes
7 answers
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 ...
  • 15.9k
20 votes
5 answers
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 ...
  • 31.5k
31 votes
5 answers
5k 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 ...
  • 31.5k
22 votes
2 answers
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 ...
  • 31.5k
26 votes
12 answers
11k views

What's the optimal strategy for Wordle?

Wordle is a game by Josh Wardle in which you try to guess a 5-letter word in at most six attempts. After each guess, the letters which are not in the word are highlighted in grey, the letters which ...
12 votes
2 answers
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 ...
  • 15.9k
2 votes
1 answer
4k views

A robot visiting every edge of a 3x3 grid

A robot is placed on the top-left vertex of a 3x3 grid. At each move the robot can take one step (up, down, left or right) along the edge of the grid to the adjacent vertex, but he cannot go outside ...
7 votes
4 answers
345 views

Savage Road Signs (Part 2)

Please read part 1 or this might be confusing Since part 1, you have replaced the stolen stickers and your daughter has forgiven you. The highway ended up being a full 700km long, so you are happy ...
  • 3,532
11 votes
4 answers
7k 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 ...
  • 665
8 votes
4 answers
2k 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: ...
  • 181
24 votes
7 answers
7k 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 ...
  • 31.5k
3 votes
1 answer
2k views

A robot visiting every edge of a 4x4 grid

This is a harder version of this puzzle: A robot visiting every edge of a 3x3 grid A robot is placed on the top-left vertex of a 4x4 grid. At each move the robot can take one step (up, down, left or ...
12 votes
2 answers
432 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 ...
  • 31.5k
5 votes
1 answer
398 views

Two knights searching for a princess in a castle

There is a castle with rooms arranged in a 3x3 square grid. The princess living in the castle sleeps in a different room each night, but always one adjacent to the one in which she slept on the ...
2 votes
1 answer
223 views

Based on 9-trains puzzle

Based on this problem, we have got some algorithms that can sort the 9 train cars in a given specific arrangement. But say if the 9 train cars are given in any-arrangement? Say ABC ABC ABC ...
-4 votes
10 answers
989 views

SafeCracker #3 - We've Been Blocked [closed]

Our Last Safe To Conquer Ok, team, this one might give us a little trouble. Nothing we can't handle though... let's go... This safe model is "The NevaCrak 9000" - the most secure safe there ...
  • 2,105
5 votes
1 answer
17k views

Programmatically solving a math puzzle with four unknowns and four equations

I have this puzzle and I want to solve by code. I wrote simple code trying to brute force but it fail in one condition https://dotnetfiddle.net/cJyu3w How can I solve such problems?
  • 53
5 votes
4 answers
442 views

Algorithm to make two scrambled Rubik's cubes be exactly the same on all faces

There are millions of Rubik's cube combinations possible. If I have two 3×3 Rubik's cubes and both are scrambled, I want to make one scrambled cube exactly the same as the other without solving them. ...
4 votes
2 answers
1k views

Counting triangle algorithm

There is a type of puzzle where one needs to count triangles in a figure, generally a large triangle full of lines which create smaller ones. One example Is there, or can someone develop ;), an ...
  • 1,280
2 votes
1 answer
317 views

A robot moving on a grid

In the spirit the question I propose the puzzle: A robot is placed on a vertex of a grid. At each move the robot must take three steps along the edge of the grid. After each step the robot must turn ...
  • 1,691
1 vote
1 answer
2k views

The swap puzzle

The swap puzzle Place small coins heads up on the squares marked H and tails up on the squares marked T. Swap the positions of the Heads for the Tails in as few moves as possible. There are two ways ...
  • 11