From the course: Level Up: C

Unlock this course with a free trial

Join today to access over 25,600 courses taught by industry experts.

Performing a perfect shuffle

Performing a perfect shuffle - C Tutorial

From the course: Level Up: C

Performing a perfect shuffle

(retro video game music) - [Instructor] Can you perform the perfect card shuffle with C? A perfect shuffle occurs when the second half of a deck of cards is evenly interspliced with the first half, but it doesn't stop there. You can continue the process taking the second half of the deck and evenly intersplicing it with the first. According to the brainiacs, this process eventually returns the deck to its original order. Your challenge is to code a perfect shuffle routine. Rather than simulate a deck of cards shuffle a character array of 26 uppercase letters of the alphabet. Your code then outputs the number of perfect shuffles required to restore the array back to its original order. Pause the video now to try this challenge on your own, resume when you're ready to compare your code with what I've concocted. (retro video game music) Here is one solution to the problem which relies upon two extra arrays, deck and…

Contents