-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmulti-5-cards-example.js
38 lines (35 loc) · 1008 Bytes
/
multi-5-cards-example.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/*
* Generate all different poker boards of 5 different card values. (high-card and straight boards)
*
* We could generate them, using:
*
* - (multiset) combinations of 5 elements chosen from 13 different
* values/types, with max (restricted) repetitions set to 1, for
* every value/type.
*
* - combinations of 5 elements from a single set of 13 values
*/
let log = console.log
, assert = require( 'assert' )
, Geco = require( '../' )
, k = 5
, v = 13
, r = 1
, iter = Geco.mget( k, v, r )
, cards = 'AKQJT98765432'.split( '' ).reverse()
, cnt = 0
;
// gen boards with cards
for ( let buff of iter ) {
let board = []
, blen = buff.length
, el = buff[ 0 ]
, j = 0
;
for ( ; j < blen; el = buff[ ++j ] )
while ( el-- ) board.push( cards[ j ] )
;
log( ` ${++cnt}:`, buff, board, board.join( '' ) );
}
// it's the same to count combinations without repetitions
assert.ok( cnt, Geco.cnt( v, k ) );