Skip to main content

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
107 votes
7 answers
27k views

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 ...
WendiKidd's user avatar
  • 2,553
34 votes
9 answers
7k views

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 ...
wanderer's user avatar
  • 1,198
32 votes
5 answers
10k views

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 ...
Mike Earnest's user avatar
30 votes
12 answers
15k views

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 ...
EmilyR's user avatar
  • 577
28 votes
7 answers
2k views

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 ...
Mike Earnest's user avatar
27 votes
6 answers
5k views

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 ...
Mike Earnest's user avatar
26 votes
2 answers
2k views

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 ...
Mike Earnest's user avatar
26 votes
1 answer
4k views

A good nonogram puzzle has a unique solution. However, some nonograms do not. For example, this puzzle: ...
Xwtek's user avatar
  • 594
25 votes
4 answers
5k views

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 &...
Mike Earnest's user avatar
24 votes
7 answers
8k views

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 ...
Mike Earnest's user avatar
24 votes
3 answers
11k views

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 ...
A E's user avatar
  • 8,820
23 votes
5 answers
1k views

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 ...
Mike Earnest's user avatar
23 votes
4 answers
2k views

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 ...
Milo Brandt's user avatar
  • 8,091
19 votes
1 answer
1k views

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 *|*...
Smart's user avatar
  • 4,528
18 votes
8 answers
2k views

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 ...
ghosts_in_the_code's user avatar
18 votes
5 answers
1k views

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 ...
Bass's user avatar
  • 85.5k
18 votes
4 answers
2k views

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 ...
Mike Earnest's user avatar
17 votes
17 answers
2k views

A group of (possibly over-polite) people have just finished their meal at a restaurant. One of them asks, "Does anyone want dessert?" The table goes quiet. Some of the people might want ...
Mark Green's user avatar
17 votes
4 answers
3k views

Let me start with a formulation of the problem for people who aren't familiar with Magic: the Gathering. You have a stack of distinct cards face-down. You can apply the following actions arbitrarily ...
A. P.'s user avatar
  • 6,160
16 votes
5 answers
5k views

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: ...
Yuriy S's user avatar
  • 1,017
16 votes
1 answer
932 views

On an infinite square grid, some of the squares are occupied by little creatures called blobs. Cute as they are, it is your mission to exterminate all of them! You only have two methods at your ...
Mike Earnest's user avatar
16 votes
2 answers
800 views

There are 100 full water tanks and 100 empty ones. You are given a hose that can connect any two of them in order to equilibrate the water level between them. All the tanks are cubical in shape, of ...
Tobias Fritz's user avatar
14 votes
6 answers
2k views

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 ...
Mike Earnest's user avatar
14 votes
4 answers
2k views

Driven by a silly conversation at work, here's the puzzle. Slack allows users to send emoji as a reaction to a message. Emoji are listed left to right in chronological order of reaction, and 'stacks' ...
sjwarner's user avatar
  • 247
14 votes
1 answer
688 views

First time posting here and I'm really, really hoping this is the community I've been looking for. I'm developing a game, right now I'm in the middle of designing levels as the core mechanics have ...
Davide's user avatar
  • 143
13 votes
12 answers
2k views

Alice and Beth both receive a random integer from 1 through 10, inclusive. They only know the number that they are given. The two of them want to come up with an algorithm to check that their ...
Nahmid's user avatar
  • 608
13 votes
2 answers
2k views

There is a castle with rooms arranged in a 4x4 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 in the ...
Dmitry Kamenetsky's user avatar
13 votes
7 answers
3k views

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 ...
klm123's user avatar
  • 16.6k
13 votes
4 answers
9k views

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 ...
MCCCS's user avatar
  • 725
13 votes
1 answer
1k views

There are four pegs in a row; let's call them A, B, C, and D from left to right. Peg A has a stack of $n$ differently sized disks, sorted in size so the smallest disk is at the top. All other pegs are ...
Bubbler's user avatar
  • 17.8k
13 votes
4 answers
553 views

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 have ...
fletcher-reede's user avatar
13 votes
1 answer
3k views

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, ...
Magnus Bakke's user avatar
13 votes
2 answers
1k views

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 ...
klm123's user avatar
  • 16.6k
12 votes
3 answers
3k views

An element of an integer sequence is called a local maximum if it is not smaller than all its neighbors. E.g., all local maximums of the following sequence are bolded. 3, * 4 *, 2, 1, * 3 *, 2, * 8 *, ...
Alexander S. Kulikov's user avatar
12 votes
1 answer
861 views

Each square of an 8x8 chessboard is marked with a positive integer. The integers can be changed according to the following two rules: (1) all integers in a row are doubled (2) all integers in a column ...
ThomasL's user avatar
  • 13.2k
12 votes
3 answers
1k views

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 ...
user475680's user avatar
12 votes
3 answers
44k views

When solving a 4x4 cube you have specific notation to inner and outer lines, like R = Clockwise outer right and r = Clockwise ...
user avatar
12 votes
2 answers
840 views

A card shuffling machine always rearranges cards in the same way relative to the order in which they are given to it. The thirteen spades arranged in the order A, 2, 3, 4, 5, 6, 7, 8, 9, 10, J, Q, K ...
Will.Octagon.Gibson's user avatar
12 votes
2 answers
754 views

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, ...
Mike Earnest's user avatar
12 votes
2 answers
554 views

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 ...
Mike Earnest's user avatar
12 votes
1 answer
462 views

There are 2020 people in a room. One person has COVID. After each minute, each person $\mathrm{P}$ is paired with some other person $\mathrm{Q}$ who was never paired with $\mathrm{P}$ before, and they ...
PoissonSummation's user avatar
12 votes
1 answer
757 views

A postage stamp collector, once, bought a, supposedly complete, rare set of original postage stamps laid out 5x6. Each item in the set features a unique, rather peculiar, 5x6 pixel artwork. One day ...
FirstName LastName's user avatar
11 votes
2 answers
2k views

Standoff Let's say we have two cannons aimed directly at one another ( as my horrible attempt shown in the image ). The Angles The cannon on top is aiming down towards the one on bottom right, and ...
John S.'s user avatar
  • 2,171
11 votes
4 answers
335 views

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 ...
Mike Earnest's user avatar
11 votes
1 answer
2k views

If you apply the same algorithm over and over again the cube will be solved. I want to know what algorithm is the worst one (the one with the longest cycle) I have found RU (cycle of 60 times) I have ...
pgp1's user avatar
  • 311
11 votes
1 answer
940 views

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 < ...
Math-fort's user avatar
  • 113
11 votes
1 answer
510 views

A box containing identical dice that were arranged to have same orientation has a missing die at the center (see figure). The dice moves to the free space for they can change orientation and ...
TSLF's user avatar
  • 6,788
10 votes
1 answer
563 views

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 ...
lynn's user avatar
  • 2,515
10 votes
2 answers
937 views

You have probably played the classic game of Mastermind with 4 pegs and 6 colours. It turns out that the codebreaker can always find the pattern in 5 moves or fewer. Now consider the 2D version of the ...
Dmitry Kamenetsky's user avatar
9 votes
5 answers
355 views

Here is a $10$-sided polygon which area is $23$ (i.e. it contains exactly 23 unit squares). Can you draw a polygon with: $6$ sides and area $6$? $8$ sides and area $8$? $12$ sides and area $12$? ...
melfnt's user avatar
  • 5,170