Advertisement
Valleri

Straight Flush - Java Basics - 22 June 2014

Jul 26th, 2014
316
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function Solve(args) {
  2.     var dealtCards = args.split(", ");
  3.  
  4.     var ranks = ['2', '3', '4', '5', '6', '7', '8', '9', "10", 'J', 'Q', 'K', 'A'];
  5.     var suites = ['S', 'H', 'D', 'C'];
  6.  
  7.     var allCards = [];
  8.     for(var i = 0; i < suites.length; i++) {
  9.         for(var j = 0; j < ranks.length; j++) {
  10.             allCards.push(ranks[j] + suites[i]);
  11.         }
  12.     }
  13.  
  14.     var isPrinted = false;
  15.  
  16.     for (var i = 0; i < allCards.length-4; i++) {
  17.         if((dealtCards.indexOf(allCards[i]) != -1) &&
  18.             (dealtCards.indexOf(allCards[i+1]) != -1) &&
  19.             (dealtCards.indexOf(allCards[i+2]) != -1) &&
  20.             (dealtCards.indexOf(allCards[i+3]) != -1) &&
  21.             (dealtCards.indexOf(allCards[i+4]) != -1) &&
  22.             (allCards[i].charAt(allCards[i].length-1) ==
  23.                 (allCards[i+1].charAt(allCards[i+1].length-1)) &&
  24.                 (allCards[i+1].charAt(allCards[i+1].length-1) ==
  25.                  allCards[i+2].charAt(allCards[i+2].length-1)) &&
  26.                 (allCards[i+2].charAt(allCards[i+2].length-1) ==
  27.                 allCards[i+3].charAt(allCards[i+3].length-1)) &&
  28.                 (allCards[i+3].charAt(allCards[i+3].length-1) ==
  29.                 allCards[i+4].charAt(allCards[i+4].length-1)))) {
  30.                  console.log("[" + allCards[i] + ", " +
  31.                             allCards[i+1] + ", " +
  32.                             allCards[i+2] + ", " +
  33.                             allCards[i+3] + ", " +
  34.                             allCards[i+4] + "]");
  35.                 isPrinted = true;
  36.         }
  37.     }
  38.     if(!isPrinted) {
  39.         console.log("No Straight Flushes");
  40.     }
  41. }
  42.  
  43. Solve("9D, 2S, 10D, AD, 10H, JD, QD, KD");
  44. Solve("AS, KH, 10C");
  45. Solve("2S, 2C, 2D, 2H, AS, KH, 10C");
  46. Solve("5H, AS, 10C, 8H, KS, KH, KD, 9H, JH, QS, 3H, QD, 4H, QH, 8S, 10D, 6H, 10S, 10H, 7C, JD, JS, 2H, 7S, 7D");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement