{"id":2519,"date":"2017-06-01T00:01:31","date_gmt":"2017-06-01T07:01:31","guid":{"rendered":"http:\/\/c-for-dummies.com\/blog\/?p=2519"},"modified":"2017-06-10T07:38:35","modified_gmt":"2017-06-10T14:38:35","slug":"the-perfect-shuffle","status":"publish","type":"post","link":"https:\/\/c-for-dummies.com\/blog\/?p=2519","title":{"rendered":"The Perfect Shuffle"},"content":{"rendered":"<p>A perfect shuffle occurs when you shuffle a deck of cards so that all the cards from the second half of the deck are perfectly interspliced between the cards in the first half of a deck. Such a shuffle is illustrated in Figure 1.<br \/>\n<!--more--><br \/>\n<div id=\"attachment_2533\" style=\"width: 510px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-2533\" src=\"http:\/\/c-for-dummies.com\/blog\/wp-content\/uploads\/2017\/06\/06exercise-figure1.png\" alt=\"\" width=\"500\" height=\"315\" class=\"size-full wp-image-2533\" srcset=\"https:\/\/c-for-dummies.com\/blog\/wp-content\/uploads\/2017\/06\/06exercise-figure1.png 500w, https:\/\/c-for-dummies.com\/blog\/wp-content\/uploads\/2017\/06\/06exercise-figure1-300x189.png 300w, https:\/\/c-for-dummies.com\/blog\/wp-content\/uploads\/2017\/06\/06exercise-figure1-476x300.png 476w\" sizes=\"auto, (max-width: 500px) 100vw, 500px\" \/><p id=\"caption-attachment-2533\" class=\"wp-caption-text\">Figure 1. A perfect shuffle takes the second half of the deck and inserts it evenly into the first half.<\/p><\/div><\/p>\n<p>If you continue to shuffle cards in this manner, eventually the original order returns, shown in Figure 2.<\/p>\n<div id=\"attachment_2534\" style=\"width: 510px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-2534\" src=\"http:\/\/c-for-dummies.com\/blog\/wp-content\/uploads\/2017\/06\/06exercise-figure2.png\" alt=\"\" width=\"500\" height=\"454\" class=\"size-full wp-image-2534\" srcset=\"https:\/\/c-for-dummies.com\/blog\/wp-content\/uploads\/2017\/06\/06exercise-figure2.png 500w, https:\/\/c-for-dummies.com\/blog\/wp-content\/uploads\/2017\/06\/06exercise-figure2-300x272.png 300w, https:\/\/c-for-dummies.com\/blog\/wp-content\/uploads\/2017\/06\/06exercise-figure2-330x300.png 330w\" sizes=\"auto, (max-width: 500px) 100vw, 500px\" \/><p id=\"caption-attachment-2534\" class=\"wp-caption-text\">Figure 2. For an 8-card deck, only three perfect shuffles are required to restore the original order.<\/p><\/div>\n<p>Mathematically, you can determine how many perfect shuffles are required to return to the original order based on the number of cards in a deck. Surprisingly, the number of shuffles doesn&#8217;t increase proportional to the deck size. I&#8217;ll leave that quandary for the eggheads to figure out. For this month&#8217;s Exercise, your job is to implement a perfect shuffle function.<\/p>\n<p>Use your perfect shuffle function on a <em>char<\/em> array representing the 26 letters of the Latin alphabet:<\/p>\n<p><code>ABCDEFGHIJKLMNOPQRSTUVWXYZ<\/code><\/p>\n<p>Count the number of perfect shuffles it takes to restore alphabetical order to the string.<\/p>\n<p><a href=\"http:\/\/c-for-dummies.com\/blog\/?p=2537\">Click here<\/a> to view my solution, but please first try this Exercise on your own.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Calculate how many times you can perfectly shuffle a deck of cards before the original order is restored. <a href=\"https:\/\/c-for-dummies.com\/blog\/?p=2519\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-2519","post","type-post","status-publish","format-standard","hentry","category-exercise"],"_links":{"self":[{"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2519","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2519"}],"version-history":[{"count":8,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2519\/revisions"}],"predecessor-version":[{"id":2565,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2519\/revisions\/2565"}],"wp:attachment":[{"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2519"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2519"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2519"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}