The Wayback Machine - https://web.archive.org/web/20240828113250/https://www.geeksforgeeks.org/algorithm-to-solve-rubiks-cube/
Open In App

Algorithm to solve Rubik’s Cube

Last Updated : 30 Jul, 2023
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

A Rubik’s Cube is an interesting puzzle invented by ‘Erno Rubik’ which has 43 quintillion possible configurations. But with the use of certain algorithms, it can be solved easily. There are many variations of the Rubix cube nowadays but the most basic one is the 3x3x3 Rubik’s cube.

A 3x3x3 Rubik’s cube is made by joining 21 pieces: 1 principle piece with three axles, 8 corner pieces (corner solid shapes) with three tones, and 12 edge pieces (edge 3D squares) with two tones.

3x3x3 rubik's cube

Note-
Centerpieces are always at their original position only.

Basic Rotations Of Rubik’s Cube:

  • R: Rotate the right layer clockwise.
  • R’: Rotate the right layer anti-clockwise.
  • L: Rotate the left layer clockwise.
  • L’: Rotate the left layer anti-clockwise.
  • U: Rotate the top layer clockwise.
  • U’: Rotate the top layer anti-clockwise.
  • F: Rotate the front layer clockwise.
  • F’: Rotate the front layer anti-clockwise.

Beginners Method:
The easy solution to solve a Rubik’s cube is to follow the approach to first solve the bottom layer, then the middle layer, and then finally the top layer.

Layer's RUbik's cube

Below are the steps to solve a Rubik’s cube-
Step 1: First choose a centerpiece of any color (say white) and then make a white cross by bringing all the four edge pieces adjacent to the white center.

Step 1

Step 2:  Match colors of all four centerpieces of the lateral face with the edges of the bottom layer one by one and sending the matched pairs in opposite directions and then bringing them again to make a cross of white.

Step 2

After matching all the layers, the cube will look like this-

Matching colors

Step 3: Set corners of the bottom layer by first matching the correct corner matching its desired color. Then apply the algorithm R U R’ U’ and repeat the same algorithm till the bottom corner piece is set at its correct position as shown below

Apply RUR'U'

After setting all the corners, the cube will look like this-

Setting all the corners

Step 4: Make the second layer by matching all four edges at the lateral faces. First, match the color of the top layer edge with its center layer and observe the other part of the piece i.e top facing color.

  • Case 1: If the other part color matches with the centerpiece at the right side, then apply the algorithm  U R U’ R’ U’ F’ U F.
  • Case2:  If the other part color matches with the centerpiece at the left side, then apply the algorithm   U’ L’ U L U F U’ F’.

After applying this to all other pieces, the cube will look like this-

Result after step4

Step 5: Make the yellow cross on the top layer by applying the simple algorithm  F R U R’ U’ F’  1-3 times as shown below.

Apply FRUR'U'F'

Step 6: Now match any one edge of the top layer with the centerpiece in the middle layer, and then apply the algorithm F R U R’ U’ F’ until all the edges are matched.

Step 6

Step 7:  Now to match all the corner pieces on the top layer, first see the corner which is already being matched and keep it as the front face and towards the right. If none of the corner pieces are in the right place, you can hold the cube in any orientation with the unmatched pieces on top and apply the algorithm U R U’ L’ U R’ U’ L.

After applying this algorithm 1-3 times the cube will look like-

After Step 7

Step 8: In the final step keep yellow as the front face and start from any corner apply the algorithm U R’ U’ R until the corner arranges correctly, then rotate the top layer to bring another disarranged corner on the top right side and repeat U R’ U’ R algorithm again to arrange it, and so on. After arranging all the corner pieces, just move the yellow facing layer 1-2 times if needed to completely solve your cube.      

Rubik's cube solved

With this final step, the Rubik’s cube is finally solved.

Also Read – How to Solve a 4×4 Rubik’s Cube


Previous Article
Next Article

Similar Reads

How To Solve 4x4 Rubik's Cube - Beginner's method
Easily Solve 4x4 Cube - Step by Step GuideSolve the center piecesPair similar edge piecesTurn only the outer layers, and solve it like a 3x3 Rubik's CubeThe 4x4 Rubik’s Cube, also known as the Rubik’s Revenge, is an interesting twisty puzzle that challenges even expert cubers. Unlike its 3x3 counterpart, the 4x4 cube introduces additional complexit
15 min read
Introduction to Rubik's Cube and how to solve them?
The Rubik's Cube is a 3-D combination Puzzle that was invented in 1974 by 'Erno Rubik’'. Rubik's Cube is a Puzzle with a six-colored cube whose faces each include nine squares, eight of which can be rotated separately. In this article, we are going to learn Rubik's cube in-depth. If you want to be an expert at Solving the Rubik's Cube, then the key
1 min read
Rubik's Cube Facts and Questions
What is a Rubik's Cube?The Rubik’s Cube is a 3-D combination Puzzle that was invented in 1974 by Hungarian sculptor and professor of architecture Ernő Rubik. Rubik’s Cube is a Puzzle with a six-coloured cube, whose faces each include nine squares, eight of which can be rotated separately. In this article, we are going to learn Rubik’s cube in-depth
5 min read
Designing algorithm to solve Ball Sort Puzzle
In Ball Sort Puzzle game, we have p balls of each colour and n different colours, for a total of p×n balls, arranged in n stacks. In addition, we have 2 empty stacks. A maximum of p balls can be in any stack at a given time. The goal of the game is to sort the balls by colour in each of the n stacks. Rules: Only the top ball of each stack can be mo
15+ min read
Minimum number of moves required to solve a Jigsaw Assembly Puzzle
Puzzle: You are given a jigsaw puzzle that contains n pieces. A "section" of the puzzle is a set of one or more pieces that have been connected to each other. A "move" consists of connecting two sections. Given that initially, all the pieces are separate, then what is the minimum number of moves in which the puzzle can be completed? Answer Let's co
2 min read
Tricks To Solve Month Based Puzzle
Importance of Month-Based problemIn banking exams such as IBPS, SBI, and RRB PO and Clerk, the Month Based problem plays an important role in the Reasoning Ability Section. Either in prelims or mains exams of IBPS, SBI, or RRB PO & clerk, you will get at least one set of 5 questions from a month-based puzzle. Aspirants should concentrate on mon
7 min read
Introduction to Crossword Puzzles and How to Solve them?
In the crossword Puzzle, there is a grid given along with Some Hint Questions, We need to find answers of those Questions and Fill in the Grid. Crossword Puzzles check the intellect, common sense, knowledge, awareness, and logic of a person about different topics related to Technology. To solve this kind of Puzzle, you must be aware of information
2 min read
Puzzle | Solve Quick
Statement : If you think that you are good in maths, then solve the mathematical equation : ( Q + U + I + C + K) ^ 3 = QUICK Solution : Q = 1 U = 9 I = 6 C = 8 K = 3 Acc. to problem : ( Q + U + I + C + K) ^ 3 = QUICK (1 + 9 + 8 + 6 + 3) ^ 3 = 19683 27 ^ 3 = 19683 19683 = 19683
1 min read
How To Fix HTTP 408 Request Timeout Error: Solve 408 Error in Steps
When one is browsing, the HTTP 408 error message that is feared by many can be very frustrating. It indicates a "Request Timeout,” which means that there has been a breakdown in communication between your browser and the server you are trying to reach. In this event, while trying to open a page on your web browser, the server fails to receive your
11 min read
What are Mathematical Puzzles and How to solve them?
A mathematical puzzle is a type of problem or game that involves using mathematical concepts, logic, and reasoning to find a solution. These puzzles often require creative thinking and a deep understanding of mathematical principles to solve. They can range from simple arithmetic puzzles to complex problems that require advanced mathematical knowle
3 min read
Introduction to Sudoku Puzzles and How to Solve them?
What is Sudoku Puzzle?Sudoku is a logic-based number-placement puzzle that is asked in interviews these days very frequently. In this article, we are going to learn sudoku in-depth. How to Solve Sudoku Puzzle?The objective of the puzzle is to populate a 9x9 grid with numbers in such a way that each column, each row, and each of the nine 3x3 subgrid
2 min read
What are Logical Puzzles And How to Solve them?
A Logical Puzzle is a type of intellectual challenge or problem-solving exercise that requires a person to use his brain, deductive reasoning, and logical analysis to arrive at a solution or conclusion. These puzzles often involve a set of rules or constraints that must be followed to reach the correct answer, and they can come in various forms and
4 min read
Puzzle | Cut Blue Painted Cube
A solid, n-inch cube of wood is coated with blue paint on all six sides. Then the cube is cut into smaller one-inch cubes. These new one-inch cubes will have either Three blue sides, Two blue sides, One blue side, or No blue sides. How many of each type 1 - inch cube will there be? Solution: This puzzle can be solved logically or mathematically. Af
2 min read
Puzzle | Six colored cube
Given six distinct colors, in how many unique ways can a six faced cube be painted such that no two faces have the same color? Note: Mixing of colors is not allowed. Answer: 30 ways Explanation: To avoid repetitions, let us fix the color of the top face. Hence, the bottom face can be painted in 5 ways. Now, what remains is the circular arrangement
1 min read
Puzzle| 53 bricks of size 1x1x4 in 6x6x6 sized cube
Question: Is it possible to fit 53 bricks of size 1×1×4 into a 6×6×6 box? Why or why not? Solution: If we look at the total volume of the larger cube, 53 cubes have a volume of 212 which is smaller than the box's volume of 216. So we might be thinking, that the answer to this problem is yes. Yet, we can show that it is not, i.e. it is impossible to
2 min read
RC4 Encryption Algorithm
RC4 is a stream cipher and variable-length key algorithm. This algorithm encrypts one byte at a time (or larger units at a time). A key input is a pseudorandom bit generator that produces a stream 8-bit number that is unpredictable without knowledge of input key, The output of the generator is called key-stream, is combined one byte at a time with
5 min read
Facebook News Feed Algorithm
Ever noticed how the news feeds of the multitude social networking sites and applications differ drastically from one person to another? Each feed seems to have been tailored to an individual to deliver content that has been predicted in order to provide the ideal platform for users. Predicted being the key word here makes one infer that there is p
4 min read
10 Project Ideas That Use Prim's Algorithm
Prim's algorithm is a greedy algorithm used to find the minimum spanning tree (MST) of a weighted undirected graph. A spanning tree of a graph is a tree that spans all the vertices of the graph, i.e., it is a subgraph that includes all the vertices and is also a tree. A minimum spanning tree is a spanning tree with the minimum total weight among al
9 min read
Detecting top nodes on a Social Network - The VoteRank Algorithm
Detecting important nodes in a Social Network is an interesting problem. It can be used to find the most influential nodes on the network y using various metrics such as their location in the network, their topological characteristics, like their degree and edge weights. One of the most famous algorithms for this is the Google's PageRank. This algo
3 min read
Crossword Puzzle Of The Week #14 (for Divide and Conquer Algorithm)
In this issue of Crossword Puzzle of the Week, we will dive into the topics of Divide and Conquer Algorithms The solution to the crossword puzzle is provided at the end. HINTS: Down: 1. _____ is defined as a sorting algorithm that works by dividing an array into smaller subarrays, sorting each subarray, and then merging the sorted subarrays back to
2 min read
EdgeRank Algorithm - Algo behind Facebook News Feed
Every time you open your Facebook account, the first thing you see is your newsfeeds. All likes, comments, tags, status updates, shares and many more such things by your friends. Ever wondered how you get these feeds in the way that you find it interesting and not like any random order? The answer is that Facebook employs a machine learning algorit
3 min read
Peterson's Algorithm for Mutual Exclusion | Set 1 (Basic C implementation)
Problem: Given 2 processes i and j, you need to write a program that can guarantee mutual exclusion between the two without any additional hardware support. Solution: There can be multiple ways to solve this problem, but most of them require additional hardware support. The simplest and the most popular way to do this is by using Peterson's Algorit
11 min read
Peterson's Algorithm for Mutual Exclusion | Set 2 (CPU Cycles and Memory Fence)
Problem: Given 2 process i and j, you need to write a program that can guarantee mutual exclusion between the two without any additional hardware support. We strongly recommend to refer below basic solution discussed in previous article. Peterson's Algorithm for Mutual Exclusion | Set 1We would be resolving 2 issues in the previous algorithm.  Wast
11 min read
Offline Data Structure and Algorithm (DSA) Classes in Pune
Learning about Data Structures and Algorithms (DSA) is super important for doing well in tech interviews and getting good jobs in fields like web development and data science. GeeksforGeeks has a special offline DSA course for Interview Preparation in your hometown Pune, making it even easier for you to understand. Whether you're searching for DSA
5 min read
Data Structure and Algorithm Training in Bangalore
Suppose you want to learn the DSA for the interview in Bangalore. Then you came across the right post we are excited to announce that GeeksforGeeks has launched its Offline DSA Course in Banglore for the interview preparation right in your Hometown, making learning even more accessible. As we all know, Data Structures and Algorithms (DSA) are cruci
4 min read
Puzzles
What is a Puzzle?A puzzle is a game, problem, or piece of information about any facts, clues, etc., that tests a person's ingenuity or knowledge. A person is required to put pieces or the given information together in a logical way to arrive at the answer.Puzzles check the intellect, common sense, knowledge, awareness, logic and reasoning ability o
5 min read
Top 100 Puzzles Asked In Interviews
Puzzles are asked in Interviews to check our problem-solving skills. Here we are providing you with the top 100 puzzles that are asked in Interviews. The main aim of puzzles is entertainment. Puzzles can be of many types:- picture puzzles, logical puzzles, mathematical puzzles, etc. It is very helpful for the development of young minds and growth.
4 min read
25 Basic Linux Commands For Beginners
While performing a task, we all need shortcuts. Shortcuts help us to complete a task quickly. Linux comes with such commands which are one to two words, using that commands, you can perform several operations in no time. As a beginner, you must be aware of those basic Linux commands to complete an operation in a short time in the Linux-based operat
13 min read
Top 50 Java Project Ideas For Beginners & Advanced
Java is one of the most popular and widely used programming language and a platform that was developed by James Gosling in the year 1982. It is based on the concept of Object-oriented Programming. A platform is an environment in that develops and runs programs written in any programming language. Java is a high-level, object-oriented, secure, robus
15+ min read
Top 10 Projects For Beginners To Practice HTML and CSS Skills
Learning to code is always exciting and fun for everyone and when it comes to stepping into the programming world most of the people start with the easiest thing HTML and CSS . Every beginner's coding journey in frontend starts with these two basic building blocks and you need to be creative when it comes to designing a beautiful application. Initi
8 min read
Practice Tags :