Problem 67: Designing a Card Game Class [Facebook/Meta]
Object Oriented Design, Logic, Programming
To learn more about the newsletter, check our detailed About Page + FAQs
To help me understand you better, please fill out this anonymous, 2-min survey. If you liked this post, make sure you hit the heart icon in this email.
Recommend this publication to Substack over here
Take the next step by subscribing here
How has this week been treating ya so far?
My week has been going swimmingly. Sebastian Raschka is a leading AI researcher. He has decided to become one of the cool kids in this newsletter. Make sure you go say hi. To anyone who is into AI and Machine Learning, I recommend his work heavily. You can interact with his Twitter over here. I’m also recommending his newsletter on Substack. Check it out if it grooves with you.
Problem
Assume you’re designing a card game using the traditional 52-card deck. Design a Game
class representing the game and these following functions associated with the class.
add_card(suit, value)
: Creates a new card object with a suit from one of the following strings:Hearts
,Spades
,Clubs
,Diamonds
, and a value from one of the following strings:A
,2
~10
,J
,Q
,K
. This card is represented byi
, wherei
is an integer indicating how many cards have been created before.card_string(card)
: Returns the string representation of the card represented byi
. It follows the format<value> of <suit>
. For example, a card created byadd_card("Spades", "3")
should have a string representation of3 of Spades
.card_beats(card_a, card_b)
: Check if the card represented bycard_a
beats the one represented bycard_b
. A card beats another card if and only if it has a greater value. The value of the cards are ordered fromA
toK
.
You may implement these however you like. However, preferably this should be easily expandable to accommodate new requirements.
I created Technology Made Simple using new techniques discovered through tutoring multiple people in top tech firms. The newsletter is designed to help you succeed, saving you from hours wasted on the Leetcode grind. I have a 100% satisfaction policy, so you can try it out at no risk to you. You can read the FAQs and find out more here. Subscribe to become part of the world’s most successful tech cult.
Before proceeding, if you have enjoyed this post so far, please make sure you like it (the little heart button in the email/post). I also have a special request for you.
***Special Request***
This newsletter has received a lot of love. If you haven’t already, I would really appreciate it if you could take 5 seconds to let Substack know that they should feature this publication on their pages. This will allow more people to see the newsletter.
There is a simple form in Substack that you can fill up for it. Here it is. Thank you.
https://docs.google.com/forms/d/e/1FAIpQLScs-yyToUvWUXIUuIfxz17dmZfzpNp5g7Gw7JUgzbFEhSxsvw/viewform
To get your Substack URL, follow the following steps-
Open - https://substack.com/
If you haven’t already, log in with your email.
In the top right corner, you will see your icon. Click on it. You will see the drop-down. Click on your name/profile. That will show you the link.
You will be redirected to your URL. Please put that in to the survey. Appreciate your help.
In the comments below, share what topic you want to focus on next. I’d be interested in learning and will cover them. To learn more about the newsletter, check our detailed About Page + FAQs
If you liked this post, make sure you fill out this survey. It’s anonymous and will take 2 minutes of your time. It will help me understand you better, allowing for better content.
https://forms.gle/XfTXSjnC8W2wR9qT9
I see you living the dream.
Go kill all and Stay Woke,
Devansh <3
To make sure you get the most out of these questions, make sure you’re checking in the rest of the days as well. Leverage all the techniques I have discovered through my successful tutoring to easily succeed in your interviews and save your time and energy by joining the premium subscribers down below. Get a discount (for a whole year) using the button below
Reach out to me on:
Instagram: https://www.instagram.com/iseethings404/
Message me on Twitter: https://twitter.com/Machine01776819
My LinkedIn: https://www.linkedin.com/in/devansh-devansh-516004168/
My content:
Read my articles: https://rb.gy/zn1aiu
My YouTube: https://rb.gy/88iwdd
Get a free stock on Robinhood. No risk to you, so not using the link is losing free money: https://join.robinhood.com/fnud75