Your nostalgia for Blorkemon™️ cards is showing no sign of slowing down, you even started collecting them again, and you are getting your friends to join you.
In this exercise, a card collection is represented by Set(String), since duplicate cards are not important when your goal is to get all existing cards.
You really want your friends to join your Blorkemon™️ madness, and the best way is to kickstart their collection by giving them one card.
Implement new_collection, which transforms a card into a collection.
new_collection("Newthree")
// -> set.from_list(["Newthree"])Once you have a collection, it takes a life of its own and must grow.
Implement add_card, which takes a card and a collection, and returns a tuple with two values: a Bool that indicates if the card was already in the collection, and the collection with the card added.
add_card(set.from_list(["Newthree"]), "Scientuna")
// -> #(False, set.from_list(["Newthree", "Scientuna"]))Now that your friends are Blorkemon™️ crazy again, you can use this to grow your own collection by trading cards.
Not every trade is worth doing, or can be done at all. You cannot trade a card you don't have, and you shouldn't trade a card for one that you already have.
Implement trade_card, that takes two cards to trade (yours and theirs) and your current collection.
The return value is a tuple of two values: a Bool stating if the trade is possible and worth doing, and the collection you would end up with if you did the trade (even if it's not actually possible).
trade_card("Scientuna", "Newthree", set.from_list(["Scientuna"]))
// -> #(True, set.from_list(["Newthree"]))You and your Blorkemon™️ enthusiast friends gather and wonder which cards are the most common.
Implement boring_cards, which takes a list of collections and returns a list of sorted cards that all collections have.
boring_cards([set.from_list(["Scientuna"]), set.from_list(["Newthree", "Scientuna"])])
// -> ["Scientuna"]Do you and your friends collectively own all of the Blorkemon™️ cards?
Implement total_cards, which takes a list of collections and returns the total number of different cards in all of the collections.
total_cards([set.from_list(["Scientuna"]), set.from_list(["Newthree", "Scientuna"])])
// -> 2Your nephew is coming to visit you soon, and you feel like impressing him. Kids like shiny things right? Blorkemon™️ cards can be shiny!
Implement shiny_cards, which takes a collection and returns a set containing all the cards that start with "Shiny ".
shiny_cards(set.from_list(["Newthree", "Scientuna", "Shiny Scientuna"]))
// -> set.from_list(["Shiny Scientuna"])Your nostalgia for Blorkemon™️ cards is showing no sign of slowing down, you even started collecting them again, and you are getting your friends to join you.
In this exercise, a card collection is represented by Set(String), since duplicate cards are not important when your goal is to get all existing cards.
You really want your friends to join your Blorkemon™️ madness, and the best way is to kickstart their collection by giving them one card.
Implement new_collection, which transforms a card into a collection.
new_collection("Newthree")
// -> set.from_list(["Newthree"])Once you have a collection, it takes a life of its own and must grow.
Implement add_card, which takes a card and a collection, and returns a tuple with two values: a Bool that indicates if the card was already in the collection, and the collection with the card added.
add_card(set.from_list(["Newthree"]), "Scientuna")
// -> #(False, set.from_list(["Newthree", "Scientuna"]))Now that your friends are Blorkemon™️ crazy again, you can use this to grow your own collection by trading cards.
Not every trade is worth doing, or can be done at all. You cannot trade a card you don't have, and you shouldn't trade a card for one that you already have.
Implement trade_card, that takes two cards to trade (yours and theirs) and your current collection.
The return value is a tuple of two values: a Bool stating if the trade is possible and worth doing, and the collection you would end up with if you did the trade (even if it's not actually possible).
trade_card("Scientuna", "Newthree", set.from_list(["Scientuna"]))
// -> #(True, set.from_list(["Newthree"]))You and your Blorkemon™️ enthusiast friends gather and wonder which cards are the most common.
Implement boring_cards, which takes a list of collections and returns a list of sorted cards that all collections have.
boring_cards([set.from_list(["Scientuna"]), set.from_list(["Newthree", "Scientuna"])])
// -> ["Scientuna"]Do you and your friends collectively own all of the Blorkemon™️ cards?
Implement total_cards, which takes a list of collections and returns the total number of different cards in all of the collections.
total_cards([set.from_list(["Scientuna"]), set.from_list(["Newthree", "Scientuna"])])
// -> 2Your nephew is coming to visit you soon, and you feel like impressing him. Kids like shiny things right? Blorkemon™️ cards can be shiny!
Implement shiny_cards, which takes a collection and returns a set containing all the cards that start with "Shiny ".
shiny_cards(set.from_list(["Newthree", "Scientuna", "Shiny Scientuna"]))
// -> set.from_list(["Shiny Scientuna"])