fork download
  1. // upper limit (55555)_6
  2. const limit = [5, 5, 5, 5, 5].reduce((acc, cur) => acc * 6 + cur);
  3. const result = {
  4. five_card: 0,
  5. four_card: 0,
  6. straight: 0,
  7. fullhouse: 0,
  8. three_card: 0,
  9. two_pair: 0,
  10. one_pair: 0,
  11. garbage: 0,
  12. };
  13.  
  14. // polyfill
  15. String.prototype.padStart = function (n, c = ' ') { return this.length < n ? c.repeat(n - this.length) + this : this; }
  16. String.prototype.padEnd = function (n, c = ' ') { return this.length < n ? this + c.repeat(n - this.length) : this; }
  17.  
  18. const sorter = i => i.toString(6).padStart(5, '0').split('').sort().join('');
  19.  
  20. for (let i = 0; i <= limit; i++) {
  21. const str = sorter(i);
  22. if (str.match(/^(\d)\1{4}$/)) {
  23. result.five_card++;
  24. continue;
  25. }
  26. if (str.match(/(\d)\1{3}/)) {
  27. result.four_card++;
  28. continue;
  29. }
  30. if (str.match(/^0?12345?$/)) {
  31. result.straight++;
  32. continue;
  33. }
  34. if (str.match(/^(\d)\1{1,2}(\d)\2{1,2}$/)) {
  35. result.fullhouse++;
  36. continue;
  37. }
  38. if (str.match(/(\d)\1{2}/)) {
  39. result.three_card++;
  40. continue;
  41. }
  42. if (str.match(/(\d)\1\d?(\d)\2/)) {
  43. result.two_pair++;
  44. continue;
  45. }
  46. if (str.match(/(\d)\1/)) {
  47. result.one_pair++;
  48. continue;
  49. }
  50.  
  51. result.garbage++;
  52. }
  53.  
  54. for (const e in result) {
  55. console.log(
  56. `${e.padEnd(10)}: ${result[e].toString().padStart(4)}/${limit + 1} (${((result[e] / (limit + 1)) * 100).toFixed(2)}%)`
  57. );
  58. }
  59.  
Success #stdin #stdout 0.07s 343616KB
stdin
Standard input is empty
stdout
five_card :    6/7776 (0.08%)
four_card :  150/7776 (1.93%)
straight  :  240/7776 (3.09%)
fullhouse :  300/7776 (3.86%)
three_card: 1200/7776 (15.43%)
two_pair  : 1800/7776 (23.15%)
one_pair  : 3600/7776 (46.30%)
garbage   :  480/7776 (6.17%)