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.
192 questions
107
votes
7
answers
27k
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 ...
34
votes
9
answers
7k
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 ...
32
votes
5
answers
10k
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 ...
30
votes
12
answers
15k
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 ...
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 ...
27
votes
6
answers
5k
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 ...
26
votes
2
answers
2k
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 ...
26
votes
1
answer
4k
views
Is there an algorithm to decide that the nonogram puzzle is unique
A good nonogram puzzle has a unique solution. However, some nonograms do not. For example, this puzzle:
...
25
votes
4
answers
5k
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 &...
24
votes
7
answers
8k
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 ...
24
votes
3
answers
11k
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 ...
23
votes
5
answers
1k
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 ...
23
votes
4
answers
2k
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 ...
19
votes
1
answer
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
8
answers
2k
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 ...
18
votes
5
answers
1k
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 ...
18
votes
4
answers
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 ...
17
votes
17
answers
2k
views
The dessert problem (blind ballot remaining blind if non-unanimous) [closed]
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 ...
17
votes
4
answers
3k
views
Magic: the Gathering – Scry-sort
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 ...
16
votes
5
answers
5k
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
1
answer
932
views
Exterminating blobs on a grid
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 ...
16
votes
2
answers
800
views
Moving water by repeated equilibration
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 ...
14
votes
6
answers
2k
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 ...
14
votes
4
answers
2k
views
Emoji primes - what's the smallest positive integer this doesn't work for?
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' ...
14
votes
1
answer
688
views
GameDev: stuck with first puzzle design, would love resources to study from or algorithm suggestions!
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 ...
13
votes
12
answers
2k
views
2 Person Same Number Verification
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 ...
13
votes
2
answers
2k
views
Three knights searching for a princess in a castle
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 ...
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 ...
13
votes
4
answers
9k
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 ...
13
votes
1
answer
1k
views
1+3 Towers of Hanoi
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 ...
13
votes
4
answers
553
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 have ...
13
votes
1
answer
3k
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, ...
13
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 ...
12
votes
3
answers
3k
views
Find Local Maximum in an Integer Sequence
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 *, ...
12
votes
1
answer
861
views
Transform each square of a chessboard to zero
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 ...
12
votes
3
answers
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 ...
12
votes
3
answers
44k
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 ...
12
votes
2
answers
840
views
Cards are shuffled twice. What was the order of the cards after the first shuffle?
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
...
12
votes
2
answers
754
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, ...
12
votes
2
answers
554
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
1
answer
462
views
Infection (Information Dissemination) Puzzle
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 ...
12
votes
1
answer
757
views
Missing postage stamp collectors' item.
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 ...
11
votes
2
answers
2k
views
Two Cannons - A Beginner's Physics Puzzle
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 ...
11
votes
4
answers
335
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
1
answer
2k
views
Worst way to solve Rubik's in one algorithm
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 ...
11
votes
1
answer
940
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 < ...
11
votes
1
answer
510
views
Rolling dice in a box
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 ...
10
votes
1
answer
563
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
2
answers
937
views
Two dimensional Mastermind
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 ...
9
votes
5
answers
355
views
An $n$-sided polygon with area $n$
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$?
...