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 - 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
-
-
-
Generating ordinal values2m 34s
-
(Locked)
Centering text2m 22s
-
(Locked)
Making change2m 17s
-
(Locked)
Simulating the hailstone sequence2m 36s
-
(Locked)
Performing a perfect shuffle2m 23s
-
(Locked)
Chopping up a string2m 49s
-
(Locked)
Determining a leap year2m 35s
-
(Locked)
Shuffling a playlist2m 32s
-
(Locked)
Letting the king wander2m 20s
-
(Locked)
Rotating a matrix2m 31s
-
(Locked)
Calculating next Monday's date2m 32s
-
(Locked)
Adding commas to numeric output2m 25s
-
(Locked)
Scoring a frame in bowling2m 20s
-
(Locked)
Calculating the golden ratio2m 50s
-
(Locked)
Wrapping text2m 9s
-