Playing Card Order and Shuffle

Asked at Apple· Onsite

Reported by the problem's creator, not verified

Import another question

A playing card is a string Suit-Rank, such as Hearts-10 or Spades-A. There are four suits (Clubs, Diamonds, Hearts, Spades) and thirteen ranks (3, 4, 5, 6, 7, 8, 9, 10, J, Q, K, A, 2), giving a standard 52-card deck.

Implement a class Deck representing one such deck. Each test gives a sequence of operations and checks what each returns.

Examples

  1. Example 1

    Input: init = [], operations = [["order",[]]]

    Output: [["Clubs-3","Diamonds-3","Hearts-3","Spades-3","Clubs-4","Diamonds-4","Hearts-4","Spades-4","Clubs-5","Diamonds-5","Hearts-5","Spades-5","Clubs-6","Diamonds-6","Hearts-6","Spades-6","Clubs-7","Diamonds-7","Hearts-7","Spades-7","Clubs-8","Diamonds-8","Hearts-8","Spades-8","Clubs-9","Diamonds-9","Hearts-9","Spades-9","Clubs-10","Diamonds-10","Hearts-10","Spades-10","Clubs-J","Diamonds-J","Hearts-J","Spades-J","Clubs-Q","Diamonds-Q","Hearts-Q","Spades-Q","Clubs-K","Diamonds-K","Hearts-K","Spades-K","Clubs-A","Diamonds-A","Hearts-A","Spades-A","Clubs-2","Diamonds-2","Hearts-2","Spades-2"]]

    Explanation: Cards are sorted by rank first and suit second. Ranks run 3, 4, ..., 10, J, Q, K, A and then 2, so the deck starts with the four 3s (Clubs, Diamonds, Hearts, Spades) and ends with the four 2s.

Import your own questions
Paste a question you were asked and get a full problem: statement, tests and a checked solution.
Import a question

Code

Loading editor…

Ln 1, Col 1

Start an attempt to use Coach.