id/email
password
forgot password | create account
about | help | code help+videos | done | prefs
CodingBat code practice

 

peter@norvig.com numbers > number_perfect_shuffles
prev  |  next  |  chance

Every day I'm shuffling! A trained magician can perform several perfect shuffles in a row. It was reading about the fact that 8 perfect shuffles puts a 52-card deck back in the original order that convinced Persi Diaconis, who ran away from home to practice magic as a teenager, to take up math (eventually becoming a Stanford math professor). Define the function number_perfect_shuffles(n) that returns the number of perfect shuffles it would take to restore a deck of n cards to their original order. (You can assume that n is even and that it won't take more than n shuffles.)


number_perfect_shuffles(52) → 8
number_perfect_shuffles(2) → 1
number_perfect_shuffles(4) → 2

...Save, Compile, Run (ctrl-enter)

def number_perfect_shuffles(n):

Editor font size %:
Shorter output


Forget It! -- delete my code for this problem

Progress graphs:
 Your progress graph for this problem
 Random user progress graph for this problem
 Random Epic Progress Graph

Python Help

Difficulty: 221 Post-solution available

Copyright Nick Parlante 2017 - privacy