Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* You’ll be provided with some amount of cash C you may use to bet on a single hand of a card game called Vokan.
- You will be shown the house’s hand consisting of four cards (drawn from a standard deck of 52 cards).
- The hand’s strength is determined solely by the face values of the cards (suits are ignored).
- Cards with faces 2 to 10 increase the hand’s strength with their numeric value. J, Q, K and A add 11, 12, 13 and
- 14 points respectively. Then, the four cards are shuffled back into the deck. At this point you’ll have to
- decide whether you want to play or not. Continuing the game means you’ll draw four cards from the deck,
- one at a time, shuffling back each card before drawing the next; you will then calculate your cards’
- combined strength and compare it to the house’s result.
- You’ll need to figure out the ratio between the number of winning hands (hands that are stronger than the house’s)
- and the total number of all possible hands in order to find the probability of you beating the house.
- If the probability is < 50% you should quit, otherwise the game is worth the risk.
- Assume you bet your entire cash deposit C and the bank matches your bet 1:1; thus the pot’s value will be 2*C.
- Your expected winnings are calculated as (% probability of winning) * (pot amount).
- The input consist of two lines. At the first line you’ll be given some amount of cash C.
- At the second line you’ll be given the house’s hand as a sequence of four cards (faces only),
- each separated by a single whitespace.
- The output should consist of two lines. On the first line, print your decision - “FOLD” if the game isn’t worth
- the risk, or “DRAW” otherwise. On the second line, print your expected winnings rounded to two digits
- after the decimal point (you should use “.” as the decimal separator). */
- "use strict";
- function solve(args) {
- var cash = Number(args[0]);
- var houseHand = args[1].split(/\s/);
- var houseStrength = 0;
- for (var i = 0; i < houseHand.length; i += 1) {
- var card = houseHand[i];
- switch (card) {
- case 'J':
- houseStrength += 11;
- break;
- case 'Q':
- houseStrength += 12;
- break;
- case 'K':
- houseStrength += 13;
- break;
- case 'A':
- houseStrength += 14;
- break;
- default:
- houseStrength += parseInt(card);
- break;
- }
- }
- var totalHands = 0;
- var winningHands = 0;
- var c1, c2, c3, c4;
- for (c1 = 2; c1 < 15; c1 += 1) {
- for (c2 = 2; c2 < 15; c2 += 1) {
- for (c3 = 2; c3 < 15; c3 += 1) {
- for (c4 = 2; c4 < 15; c4 += 1) {
- totalHands += 1;
- if ((c1 + c2 + c3 + c4) > houseStrength) {
- winningHands += 1;
- }
- }
- }
- }
- }
- var probability = winningHands / totalHands;
- var expectedWinnings = (cash * 2 * probability).toFixed(2);
- console.log((probability < 0.5) ? 'FOLD' : 'DRAW');
- console.log(expectedWinnings);
- }
- solve(['100',
- '2 7 9 A'
- ]);
- solve(['203.03',
- 'A A K 3'
- ]);
- solve(['5',
- '8 4 Q 10'
- ]);
- solve(['150000.37',
- '10 4 4 J'
- ]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement