FunctionRacerProblemsRace

Cutting and Riffling a Deck

EasyClassesPython, JavaScript, TypeScript, Java, C++

Implement a class CardDeck for a face-down stack of numbered cards. Write these methods:

The tests call the methods in sequence and compare every return value. The expected list holds null for the constructor.

Example 1

CardDeck(5)
riffle()
list_cards() returns [1,4,2,5,3]
cut(2) returns 2
draw() returns 2
put_bottom(9) returns 5
list_cards() returns [5,3,1,4,9]

With five cards the top half is 1 2 3 and the bottom half is 4 5, so the riffle gives 1 4 2 5 3. Cutting two cards moves 1 4 under the rest, and the drawn 2 is replaced at the bottom by 9.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Classes problems