Question

A has invented a new card game to play with B. A made a deck of...

A has invented a new card game to play with B. A made a deck of cards with random values between 1 and 52. B picks 5 cards. Then, he has to rearrange the cards so that by utilizing the operations plus, minus, or times, the value of the cards reach A's favorite number, 42. More precisely, find operations such that ((((val1 op1 val2) op2 val3) op3 val4) op4 val5) = 42.

Print  "YES" if it is possible to reach the value 42 according to the rules of the game, or "NO" otherwise.


How to solve this problem in any coding language?

Homework Answers

Answer #1

Code :

from random import sample
import itertools

#creates a deck of cards having numbers from 1 to 52
deck_cards = []
for i in range(1,53):
deck_cards.append(i)
  
#randomly selects 5 numbers from the created deck of cards   
nums = sample(deck_cards,5)

print(nums)

#operands list
ops = ['+','-','*']

a = []

for p in itertools.permutations(nums,len(nums)):
for op1 in ops:
for op2 in ops:
for op3 in ops:
for op4 in ops:
expr = 'p[0]'+op1+'p[1]'+op2+'p[2]'+op3+'p[3]'+op4+'p[4]'
result = eval(expr)
a.append(result)

#if 42 is produced and stored then prints YES else NO
if 42 in a:
print("YES")
else:
print("NO")

Screenshot of Code :

Screenshot of OUTPUT :

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
You pay $20 to play a game. You choose a card from a standard deck of...
You pay $20 to play a game. You choose a card from a standard deck of cards plus two jokers (total of 54 cards) at random. If you pick a joker you get $200; if you pick an ace you get $50; if you get a face card you get $25. Otherwise you receive nothing. Calculate the expected value of this game.
6. Your favorite statistics instructor invites you to play a card game. He uses a standard...
6. Your favorite statistics instructor invites you to play a card game. He uses a standard deck of 52 cards. The deck itself is shuffled several times before the game starts. The game is simple: You draw one card (and then replace it randomly in the deck). If it is a face card, the instructor will give you $30. If not, you must pay him $2. a. How many face cards should we find in the deck? b. What is...
Consider this simple game. Pick a card from a regular deck with 52 cards. If you...
Consider this simple game. Pick a card from a regular deck with 52 cards. If you get a heart, you will win $2, otherwise, you will lose $1. a) Play this game for one time, what is the probability that you can win. b)Play this game twice, what is the probability that you can win. c) Play this game 100 times. Find the probability that you can win.
A card is drawn from a standard​ 52-card deck. Calculate the expected value for the game....
A card is drawn from a standard​ 52-card deck. Calculate the expected value for the game. A player must pay $7 to play the game, which must be subtracted from the winnings. If a diamond is drawn, the player wins $17, otherwise they lose $7. Calculate the price that would make the game fair.
Your group is required to develop a simple Android BlackJack card game. Part B (35 Marks)...
Your group is required to develop a simple Android BlackJack card game. Part B – Group Submission (Do it on android studio) i need the full working code in android studio The program shall fulfil the following requirements: 1) There are total of 4 main features : User authentication/login, game setting, playing game and view history. User Login 2) Allow the player to register new user account or login using the existing account to play the game. Each user account...
Delta airlines case study Global strategy. Describe the current global strategy and provide evidence about how...
Delta airlines case study Global strategy. Describe the current global strategy and provide evidence about how the firms resources incompetencies support the given pressures regarding costs and local responsiveness. Describe entry modes have they usually used, and whether they are appropriate for the given strategy. Any key issues in their global strategy? casestudy: Atlanta, June 17, 2014. Sea of Delta employees and their families swarmed between food trucks, amusement park booths, and entertainment venues that were scattered throughout what would...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT