RegEx Project: Dollar Bill Poker

Regular Expression Project: Dollar Bill Poker

You are to construct a java program (with plenty of regular expressions inside) that can deduce the "best" poker hand from an 8-digit serial number from a dollar bill. Here are the rules (which vary slightly from real poker):

  • Zeros in the serial number cannot be used as any part of the hand;
  • Exactly 5-digits have to be used from the 8-digit serial number;
  • You may reorder the digits (for example, to make a "straight";
  • While each 8-digit serial number can produce multiple hands, your program must print out the "best" possible hand based on the hand ranks below.

Possible Poker Hands in Highest to Lowest Order

  1. Five of a kind
  2. Four of a kind
  3. Full House (Three of one kind, two of another)
  4. Straight (5 consecutive digits such as 56789)
  5. Three of a kind
  6. Two pair
  7. One pair
  8. High Digit

Test Data

Example Inputs:

  • 14912276
  • 99027737
  • 39217860
  • 59977643
  • 58276501
  • 77437751
  • 03999299
  • 12145671
  • 12340076
  • 98764115
  • 11223344

For each test case, your program should output one line containing the serieal number and the best hand achieved in the following format. The best hand should be displayed in all caps. I the event that the best hand is a high digit, print the digit.

[serial number] = [BEST HAND]

Example Outputs

  • 14912276 = TWO PAIR
  • 99027737 = FULL HOUSE
  • 39217860 = 9
  • 59977643 = STRAIGHT
  • 58276501 = PAIR
  • 77437751 = FOUR OF A KIND
  • 03999299 = FIVE OF A KIND
  • 12145671 = THREE OF A KIND
  • 12340076 = 7
  • 98764115 = STRAIGHT
  • 11223344 = TWO PAIR