tag:b.chrishunt.co,2014:/feed Chris Hunt 2014-02-05T12:50:37-08:00 Chris Hunt http://b.chrishunt.co Svbtle.com tag:b.chrishunt.co,2014:Post/how-many-positions-on-a-rubiks-cube 2014-02-05T12:50:37-08:00 2014-02-05T12:50:37-08:00 How Many Positions on a Rubik's Cube? <h2 id="a-fun-lesson-in-permutations_2">A fun lesson in permutations. <a class="head_anchor" href="#a-fun-lesson-in-permutations_2">#</a> </h2> <p>The Rubik’s Cube is a challenging puzzle to solve, largely because there are so many positions. Wouldn’t it be fun to know exactly how many positions there are? Wouldn’t it be even <em>more</em> fun to know how to calculate that number for yourself?</p> <h1 id="back-to-the-basics_1">Back To The Basics <a class="head_anchor" href="#back-to-the-basics_1">#</a> </h1> <p>Imagine we have three marbles and each marble is a different color. One is red, another is green, and the third is blue. If we were to place the marbles in a row on the table in front of us, how would we arrange them?</p> <p><a href="https://svbtleusercontent.com/m1h89fwdupk1a.png"><img src="https://svbtleusercontent.com/m1h89fwdupk1a_small.png" alt="01-marbles.png"></a></p> <p>The ordering that we’ve selected is just one possible position of many. We might have chosen to put green first instead of red. Each of these positions is a <a href="http://en.wikipedia.org/wiki/Permutation"><em>permutation</em></a> of our marbles. If we were to rearrange the marbles, then we would find another permutation.</p> <blockquote class="short"> <p>“A <strong>permutation</strong> of a set of objects is an arrangement of those objects into a particular order." - wikipedia</p> </blockquote> <p>In order to count how many positions we have for the Rubik’s Cube, we will first learn how to count permutations for our set of marbles.</p> <h2 id="counting-permutations_2">Counting Permutations <a class="head_anchor" href="#counting-permutations_2">#</a> </h2> <p>We intuitively know that our set of three marbles has several different permutations, but exactly how many are there? One way to count is to rearrange the marbles on a table until we’ve found each permutation. Doing this, we can see that we have <strong>six permutations</strong>.</p> <p><a href="https://svbtleusercontent.com/dwxeb8d4xfcc4g.png"><img src="https://svbtleusercontent.com/dwxeb8d4xfcc4g_small.png" alt="02-marbles.png"></a></p> <h2 id="when-we39ve-lost-our-marbles_2">When We’ve Lost Our Marbles <a class="head_anchor" href="#when-we39ve-lost-our-marbles_2">#</a> </h2> <p>Visualizing each permutation works well when we only have three marbles, but what if we wanted to count permutations for a bag of 500 marbles? We’ll need a different strategy.</p> <p>There’s a nice mathematical trick we can use for counting permutations called the <a href="http://en.wikipedia.org/wiki/Factorial"><em>factorial</em></a>. Given <em>n</em> items, the factorial of <em>n</em> is equal to the number of permutations of <em>n</em>.</p> <blockquote class="short"> <p>"The <strong>factorial</strong> of a non-negative integer n, denoted by n!, is the product of all positive integers less than or equal to n." - wikipedia</p> </blockquote> <p>Since we have three marbles, we can calculate the total number of permutations by calculating <strong>three factorial</strong>.</p> <p><a href="https://svbtleusercontent.com/6akljtu8szh3g.png"><img src="https://svbtleusercontent.com/6akljtu8szh3g_small.png" alt="03-three-factorial.png"></a></p> <hr> <h1 id="getting-oriented_1">Getting Oriented <a class="head_anchor" href="#getting-oriented_1">#</a> </h1> <p>A marble does not have an orientation. It cannot be flipped or rotated. It always appears the same no matter how it’s placed on the table. When we counted the the number of positions for our marbles, all we cared about was their permutation.</p> <p>What if we wanted to calculate the total number of positions for a set of <strong>three playing cards</strong>?</p> <p>Initially, the problem looks the same. We have three cards and know that they can be arranged in <strong>three factorial</strong> different permutations, just like the marbles.</p> <p><a href="https://svbtleusercontent.com/zjj7aooizhwehq.png"><img src="https://svbtleusercontent.com/zjj7aooizhwehq_small.png" alt="04-cards.png"></a></p> <p>Playing cards, however, <em>do</em> have an orientation. We can flip any of the three cards and we’ll end up with a <em>different</em> position. In order to calculate the total number of positions, we’ll need to factor in <strong>both the permutation and orientation</strong> of each card.</p> <p><a href="https://svbtleusercontent.com/wxtbgbb0fa5uvw.png"><img src="https://svbtleusercontent.com/wxtbgbb0fa5uvw_small.png" alt="05-cards.png"></a></p> <p>We’ve already learned how to calculate the total number of permutations as <strong>three factorial</strong>. Next, we’ll see how to calculate the total number of orientations for each position.</p> <p>We have <strong>three playing cards</strong> and each card has <strong>two possible orientations</strong>, face <em>up</em> or face <em>down</em>. For each of our <strong>three factorial permutations</strong>, we are able to reach all of these orientations.</p> <p><a href="https://svbtleusercontent.com/f82qff73bqzatw.png"><img src="https://svbtleusercontent.com/f82qff73bqzatw_small.png" alt="06-all-card-permutations.png"></a></p> <p>How many total orientations are there for one permutation of our set of three cards? We could count them using the image above, but it’s faster to calculate.</p> <p>We have <strong>three playing cards</strong> and each card has <strong>two orientations</strong>. The total number of orientations for one permutation of the cards can be calculated as the <strong>third power of two</strong>.</p> <p><a href="https://svbtleusercontent.com/7vqqrgkecweka.png"><img src="https://svbtleusercontent.com/7vqqrgkecweka_small.png" alt="07-third-power-of-two.png"></a></p> <h2 id="total-positions-for-three-cards_2">Total Positions for Three Cards <a class="head_anchor" href="#total-positions-for-three-cards_2">#</a> </h2> <p>We’ve determined the total number of permutations for our cards is <strong>three factorial</strong> and the total number of orientations for each of those permutations is the <strong>third power of two</strong>. Calculating the number of positions is done by multiplying the number of permutations by the number of orientations.</p> <p><a href="https://svbtleusercontent.com/pqz7dxg9lg6wa.png"><img src="https://svbtleusercontent.com/pqz7dxg9lg6wa_small.png" alt="08-card-total-permutations.png"></a></p> <p>A set of three playing cards has 48 possible positions when all permutations and orientations are considered.</p> <hr> <h1 id="understanding-the-rubik39s-cube_1">Understanding the Rubik’s Cube <a class="head_anchor" href="#understanding-the-rubik39s-cube_1">#</a> </h1> <p>We now have all the knowledge we need to calculate the total number of positions for the Rubik’s Cube. We know that, given a set of <em>n</em> items with <em>p</em> orientations, the total number of positions for that set of items can be calculated.</p> <p><a href="https://svbtleusercontent.com/mdvpysojodz6ka.png"><img src="https://svbtleusercontent.com/mdvpysojodz6ka_small.png" alt="09-equation-total-perms.png"></a></p> <p>Once we understand how the Rubik’s Cube is built, we can apply this formula and calculate the total number of positions.</p> <h2 id="anatomy-of-a-rubik39s-cube_2">Anatomy of a Rubik’s Cube <a class="head_anchor" href="#anatomy-of-a-rubik39s-cube_2">#</a> </h2> <p>The Rubik’s Cube has six sides and each side has nine squares, but this is not a good way to think about the cube when trying to count the number of positions. Instead, we need to understand <a href="https://www.youtube.com/watch?v=1p0qN1_qWoA">how the cube is built</a>, what types of pieces there are, and how each piece moves around the puzzle.</p> <p><a href="https://www.youtube.com/watch?v=1p0qN1_qWoA"><img src="https://svbtleusercontent.com/vfkaqlvfuvwzbg_small.png" alt="10-how-cube-works.png"></a></p> <p>It’s important to understand that the Rubik’s Cube has <strong>three types of pieces</strong>. Each behaves differently as we turn the sides of the cube. We’ll keep this in mind as we do our calculations.</p> <hr> <h1 id="calculating-positions_1">Calculating Positions <a class="head_anchor" href="#calculating-positions_1">#</a> </h1> <p>The total number of positions for the Rubik’s Cube can be calculated by looking at each of the three types of pieces separately.</p> <h2 id="center-positions_2">Center Positions <a class="head_anchor" href="#center-positions_2">#</a> </h2> <p>There are six center pieces and they are located at the center of each face of the Rubik’s Cube. <a href="https://www.youtube.com/watch?v=1p0qN1_qWoA">As we learned</a>, the center pieces are part of a fixed axle that does not move. All the other pieces move <em>around</em> the center pieces. This means that the center pieces have <strong>one permutation</strong> and <strong>one orientation</strong>.</p> <p>Intuitively we know that something with <em>one</em> permutations and <em>one</em> orientation has a <strong>single position</strong>, but we can verify by plugging these numbers into our equation.</p> <p><a href="https://svbtleusercontent.com/55tzbpl0cgaauw.png"><img src="https://svbtleusercontent.com/55tzbpl0cgaauw_small.png" alt="11-center-permutations.png"></a><br> <a href="https://svbtleusercontent.com/4j5xjke8vkn0gq.png"><img src="https://svbtleusercontent.com/4j5xjke8vkn0gq_small.png" alt="12-centers.png"></a></p> <h2 id="corner-positions_2">Corner Positions <a class="head_anchor" href="#corner-positions_2">#</a> </h2> <p>Every three dimensional cube has <strong>eight corners</strong> and the Rubik’s Cube is no exception. Unlike the centers, each corner piece can be moved and rotated. Since we have eight corners, our total number of permutations for these pieces is <strong>eight factorial</strong>.</p> <p>To figure out the number of orientations for a single piece, we need to count the number of stickers. A corner pieces has three stickers, so it must have <strong>three orientations</strong>. As we learned, this means the total number of orientations for each position of the corners is the <strong>eighth power of three</strong>.</p> <p>With these numbers, we can calculate the total number of positions for the corner pieces.</p> <p><a href="https://svbtleusercontent.com/dg15curynbgew.png"><img src="https://svbtleusercontent.com/dg15curynbgew_small.png" alt="13-corner-perms.png"></a><br> <a href="https://svbtleusercontent.com/3p458nwmxiyr5w.png"><img src="https://svbtleusercontent.com/3p458nwmxiyr5w_small.png" alt="14-corners.png"></a></p> <h2 id="edge-positions_2">Edge Positions <a class="head_anchor" href="#edge-positions_2">#</a> </h2> <p>A Rubik’s Cube has <strong>twelve edge pieces</strong> and each piece may be moved or flipped. We can calculate the total number of permutations for these pieces as <strong>twelve factorial</strong>.</p> <p>We can use the same method as we did for the corners to determine the number of orientations for a single edge piece. An edge piece has two stickers, so it must have <strong>two orientations</strong>. This means the total number of orientations for each position of the edges is the <strong>twelfth power of two</strong>.</p> <p>With these numbers, we can calculate the total number of positions for the edge pieces.</p> <p><a href="https://svbtleusercontent.com/myltudgc4d7qfg.png"><img src="https://svbtleusercontent.com/myltudgc4d7qfg_small.png" alt="15-edge-perms.png"></a><br> <a href="https://svbtleusercontent.com/oqgjl53l0tmhsg.png"><img src="https://svbtleusercontent.com/oqgjl53l0tmhsg_small.png" alt="16-edges.png"></a></p> <h2 id="putting-it-all-together_2">Putting It All Together <a class="head_anchor" href="#putting-it-all-together_2">#</a> </h2> <p>We’ve calculated the number of positions for the center pieces, the corner pieces, and the edge pieces. The final step to finding the total positions for the entire Rubik’s Cube is multiplying these numbers together.</p> <p><a href="https://svbtleusercontent.com/evkjq166zx52ha.png"><img src="https://svbtleusercontent.com/evkjq166zx52ha_small.png" alt="17-total-cube-perms.png"></a></p> <h2 id="but-wait-there39s-more_2">But Wait, There’s More <a class="head_anchor" href="#but-wait-there39s-more_2">#</a> </h2> <p>We have successfully calculated the number of positions, but we made one fatal assumption; our calculations assume that we can take the cube apart. This is <em>cheating</em>. Not every position of the Rubik’s Cube is possible if we limit ourselves to turning the sides.</p> <blockquote class="short"> <p>"there is no sequence of moves that will swap a single pair of pieces or rotate a single corner or edge cube" - wikipedia</p> </blockquote> <p>Because of the limitations of the Rubik’s Cube, only <a href="http://en.wikipedia.org/wiki/Rubiks_Cube"><strong>1 in 12</strong></a> of every position is reachable by turning the sides of the cube. We can factor this in to our equation and settle on the total number of <em>legal</em> positions of the Rubik’s Cube.</p> <p><a href="https://svbtleusercontent.com/c88bk9pt5voctw.png"><img src="https://svbtleusercontent.com/c88bk9pt5voctw_small.png" alt="18-total-legal-cube-perms.png"></a></p> <hr> <h1 id="how-large-is-that_1">How Large Is That? <a class="head_anchor" href="#how-large-is-that_1">#</a> </h1> <p>There are over 43 quintillion legal positions of the Rubik’s Cube.</p> <p><a href="https://svbtleusercontent.com/yc2gedgtjumscg.png"><img src="https://svbtleusercontent.com/yc2gedgtjumscg_small.png" alt="19-big-number.png"></a></p> <ul> <li>It would take <strong>thirteen hundred million years</strong> to see every position if you were able to view one thousand per second.</li> <li>If we stacked 43 quintillion pennies, the stack would be tall enough to reach the sun and return to the earth over <strong>two hundred and nineteen thousand times</strong>.</li> </ul>