Skip to content

Instantly share code, notes, and snippets.

@atoponce
Last active February 19, 2021 21:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save atoponce/880505c684fdd8fd480636bddec49f05 to your computer and use it in GitHub Desktop.
Save atoponce/880505c684fdd8fd480636bddec49f05 to your computer and use it in GitHub Desktop.
function factorial(n) {
let result = BigInt(1)
while (n > 0) {
result *= BigInt(n)
n--
}
return result
}
var deck = []
for (let i = 1; i <= 52; i++) deck.push(i)
var outstanding = 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffn
var counter = 51
var multipliers = []
var result = []
while (counter > 0) {
var divisor = outstanding / factorial(counter)
outstanding %= factorial(counter)
multipliers.push(deck[divisor])
deck.splice(parseInt(divisor), 1)
counter--
}
deck = {
1:'AC', 2:'2C', 3:'3C', 4:'4C', 5:'5C', 6:'6C', 7:'7C', 8:'8C', 9:'9C', 10:'TC', 11:'JC', 12:'QC', 13:'KC',
14:'AD', 15:'2D', 16:'3D', 17:'4D', 18:'5D', 19:'6D', 20:'7D', 21:'8D', 22:'9D', 23:'TD', 24:'JD', 25:'QD', 26:'KD',
27:'AH', 28:'2H', 29:'3H', 30:'4H', 31:'5H', 32:'6H', 33:'7H', 34:'8H', 35:'9H', 36:'TH', 37:'JH', 38:'QH', 39:'KH',
40:'AS', 41:'2S', 42:'3S', 43:'4S', 44:'5S', 45:'6S', 46:'7S', 47:'8S', 48:'9S', 49:'TS', 50:'JS', 51:'QS', 52:'KS'
}
for (let i = 0; i < multipliers.length; i++) result.push(deck[multipliers[i]])
console.log(result.join(','))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment