DEV Community

Cover image for Random Rubik's cube solve
Stevan Kostoski
Stevan Kostoski

Posted on

Random Rubik's cube solve


I'm sure that all of you have heard about the infinite monkey theorem states that a monkey hitting keys at random on a typewriter keyboard for an infinite amount of time will almost surely type any given text, such as the complete works of William Shakespeare.


In this direction I was wondering what if a monkey finds an unsolved Rubiks cube and starts rotating it for an infinite number of times, will it eventually solve it? I have the algorithm for solving the Rubik's cube, I wrote it for my last project, now I can use it in a different way, I can simulate random rotation for an infinite number of times and apply them to unsolved Rubik's cube and calculate the percentage of completion. According to the theorem, it will solve it one day, the chance of it occurring during a period of time hundreds of thousands of orders of magnitude longer than the age of the universe is extremely low (but technically not zero).

Please note that I'm not using any learning algorithm, it's just a random rotation, that's the basic idea, so the maximum completion level is increasing/decreasing all the time.


In order to start the experiment, I've got a solved cube and apply several random rotations in order to get a randomized cube. After randomization, it was 14.58% completed.


After one day of running, in other words, after 1,808,200,376 (~2 billion) rotations, it gets to 66.67% completion.


Here is a sample of the random rotation moves.

Next steps

I'll keep monitoring the progress and if it gets above the current maximum completion, I will post an update.

I hope this was interesting to you and also inspire you to do some fun with your old code or project. In days of isolation brilliant ideas can come to your mind, please use them in a good way and share them with the community.

Top comments (4)

koski84 profile image

Interesting experiment.

The monkey has a hard work to improve the current completion percentage.

stevcooo profile image
Stevan Kostoski

He is trying his best but is not concentrated :)

mateuszjarzyna profile image
Mateusz Jarzyna

You should create a chart - time/% of completion

stevcooo profile image
Stevan Kostoski

I'm collecting data to create the chart, as soon as I have something I will update the post.