Hey Kotlin folks,
So about a week ago my mom jokingly asked me if I wanted to solve her 2×2 Rubik’s Cube. She is able to solve pretty much any size except for the 2×2 and also knows that I have never solved a Rubik’s Cube in my life.
However, looking at the cube I had a random epiphany and realized the cube could be solved by representing the solution as a path of states which are connected by different cube transitions. When I realized this I thought it would be kind of cool to try making a BFS algorithm to solve it (using Kotlin of course).
Well long story short, standard BFS was way too slow and unable to solve a 2×2 Rubik’s Cube. However, a Bidirectional BFS algorithm was able to solve any configuration almost instantly. I was kind of surprised at the speed up on that.
Anyways, the code is entirely in Kotlin and can be found here . If you have any questions about the algorithm I’d be happy to discuss it in the comments below!