Many card players will be familiar with the game of Clock Solitaire. Briefly, the player sets up by creating thirteen piles of four face-down cards at random, each associated with one of the ranks ace through king. Beginning with the top card in the king's pile, the player places the drawn card face up beneath its home pile, and draws a new card from the top of that same pile. Play continues until the fourth king is drawn. If all cards are face up in their home piles at this time, the game is a winner.
Since clock solitaire is a purely deterministic game, a computer can easily be programmed to play. For this problem, you will write a function that takes a deck and reports whether or not it is a winning configuration. More specifically, the input will be some permutation of the integers 1:52, where 1:13 represent the ace through king of clubs, 14:26 the ace through king of diamonds, 27:39 the hearts, and 40:52 the spades. Assume that the cards are formed into 13 piles by taking the first four cards as the ace pile, next four as the deuce pile, etc. Output is a single scalar boolean indicating whether the game will be won using this deck.
Armed with this function, one can determine empirically what the win rate is for randomly shuffled decks. See if you can find out!
MATLAB and Simulink resources for Arduino, LEGO, and Raspberry PiLearn more
Opportunities for recent engineering grads.Apply Today
New to MATLAB?Learn MATLAB today!
Play games and win prizes!Learn more