#P1303. Byte Me!
Byte Me!
Description
You are a dealer at The One, the first all-binary casino in Las Vegas. What makes The One special is that its blackjack tables don't use cards; they use bytes (an 8-bit sequence representing a number from 0 to 255) and nibbles (a 4-bit sequence representing a number from 0 to 15).
All day long, you play the house's hand against individual opponents. Of course, the casino owners know their statistics, and they have devised a strategy for you that gives gamblers just less than even odds.
Here are the rules of binary blackjack:
<li>The goal of the game is to be the player closest to 510 points without going over.</li>
<li>Each player is dealt two bytes, one face up and one face down.</li>
<li>The players then have the opportunity to take more bytes (by saying, "Byte Me!") or more nibbles (by saying, "Nibble Me!") until he reaches his limit of 4 hits or has more than 510 points showing.</li>
<li>All hits are played face up.</li>
<li>If a player goes over 510, he immediately busts and loses the hand.</li>
<li>The dealer hits last.</li>
<li>The dealer wins any ties (this includes a tie where everyone busts).</li>
The rules for the dealer are (in order of precedence, where lower numbered rules override higher numbered ones):
<li>Never hit when it is certain that you've won by simply looking at your hand and what is showing of other people's hands.</li>
<li>If your total is strictly less than 382 take a byte hit.</li>
<li>If your total is less than or equal to 500 take a nibble hit.</li>
<li>Take no hits</li>
Input
Input to this problem will consist of a (non-empty) series of up to 100 data sets. Each data set will be formatted according to the following description, and there will be no blank lines separating data sets.
A single data set has 6 components:
<li>Start line : A single line, "START N", where N is the number of players playing this hand (not including the dealer). There will never be more than 10 non-dealer players, and the dealer never plays by himself.</li>
<li>Dealer Line : A single line containing 2 binary strings of exactly eight digits separated by exactly one space. These two strings represent the two cards in the dealer's hand.</li>
<li>Player Line : A single line containing N 8-digit binary strings, each separated from the others by a single space. These represent the face-up cards of all of the non-dealer players.</li>
<li>Byte Line : A single line containing 4 8-digit binary strings, each separated from the others by a single space. These represent the next 4 bytes in the byte deck, in the order they will be drawn.</li>
<li>Nibble Line : A single line containing 4 4-digit binary strings, each separated from the others by a single space. These represent the next 4 nibbles in the nibble deck, in the order they will be drawn.</li>
<li>End line : A single line, "END".</li>
Following the final data set will be a single line, "ENDOFINPUT".
Here are some other useful facts:
<li>Oddly enough, each non-dealer player is always dealt a face-down card 11111111, value 255, but the dealer has no knowledge of this.</li>
<li>Players other than the dealer never hit (they aren't too bright).</li>
Output
Calculate the actions taken by the dealer and how the dealer fares with the resulting hand.
For each data set, there will be exactly one output set, consisting of the following components:
<li>Hand Line : A single line, "HAND N", where N is the number of players playing this hand (not including the dealer).</li>
<li>Dealer Hit List : A single line will be printed for each hit the dealer takes on his turn. For a byte hit, print a line "Byte me!", and for a nibble hit print, "Nibble me!"</li>
<li>Outcome Line : A single line containing "Win!" if the dealer wins, "Bust!" if the dealer loses by busting, and "Lose!" if the dealer loses without busting.</li>
START 1
11111111 11111111
00000001
10101010 01010101 11110000 00001111
1010 0101 1100 0011
END
START 1
10111110 10111111
11111110
00010010 10101010 01010101 11110000
0001 1010 1100 0011
END
START 8
11111111 00001000
00000000 00000001 00000010 00000011 00000100 00000101 00000110 00000111
00010010 10101010 01010101 11110000
0001 1010 1100 0011
END
ENDOFINPUT
HAND 1
Win!
HAND 1
Byte me!
Nibble me!
Nibble me!
Nibble me!
Lose!
HAND 8
Win!
Source
South Central USA 2002