/*
A standard deck of 52 playing cards consists of four suits:
spades (♠), hearts (♥), diamonds (♦), and clubs (♣).
Each suit contains 13 ranks:
Ace, 2, 3, 4, 5, 6, 7, 8, 9, 10, Jack, Queen, King.
Cards of spades and clubs are black, while hearts and diamonds are red.
Color is informational only — it does not affect shuffling or random selection.
*/
/*
This program performs multiple draws of 5 random cards from a 52‑card deck
WITHOUT duplicates across draws.
It uses:
- List[String] for the deck
- scala.util.Random.shuffle for efficient randomization (Fisher–Yates internally)
- functions for clean structure
Algorithm:
1. Build a full deck (52 cards)
2. For each draw:
a. Shuffle the remaining deck
b. Draw 5 cards
c. Remove them from the deck
*/
import scala.util.Random
object CardDraws:
def buildDeck(): List[String] =
val ranks = List("2","3","4","5","6","7","8","9","10","J","Q","K","A")
val suits = List("Clubs", "Diamonds", "Hearts", "Spades")
for
suit <- suits
rank <- ranks
yield s"$rank of $suit"
def drawFive(deck: List[String], drawNumber: Int): List[String] =
// Shuffle the remaining deck before this draw
val shuffled = Random.shuffle(deck)
println(s"Draw #$drawNumber:")
shuffled.take(5).foreach(card => println(s" $card"))
println()
// Remove drawn cards
shuffled.drop(5)
def main(args: Array[String]): Unit =
val numberOfDraws = 3
var deck = buildDeck()
// Perform multiple draws (no duplicates)
for drawIndex <- 1 to numberOfDraws do
if deck.length < 5 then
println(s"Not enough cards left for draw #$drawIndex.")
// break naturally by ending the loop
else
deck = drawFive(deck, drawIndex)
/*
run:
Draw #1:
9 of Clubs
J of Hearts
J of Diamonds
8 of Clubs
K of Diamonds
Draw #2:
Q of Diamonds
K of Spades
Q of Clubs
7 of Clubs
Q of Spades
Draw #3:
7 of Diamonds
2 of Diamonds
A of Diamonds
7 of Hearts
2 of Clubs
*/