figured out how to compress all 479,001,600 permutations of a sequence of 12 cards into an integer!!
hi!! ok so for demon's dozen the game @plum and i designed last fall, you play with 12 cards, ace through queen. ive been thinking about how you'd go about writing a bot to play it, and i decided i want to be fucking unhinged and build a lookup table for every possible game state which means i have to losslessly compress the shit outta everything, including the order of the cards in play
here's the algorithm i ended up writing for it but if ur curious about the algorithm itself here's more:
i tried a whole bunch of techniques for just compressing binary numbers into a single integer but with 12 cards it always required more than the 32 bits i had to work with. BUT!! 12 cards means 479,001,600 unique arrangements which is LESS than the 4,294,967,295 possible values you've got to work with for 32 bits. so it's just a matter of finding an algorithm that lists each permutation, taking that algorithm apart and putting it back together again in a way that lets you get the permutation's index from an order, and then an order from the permutation!
i came across this video which showed how to find each permutation of a string, and didn't make it through the whole video cause i was sleepy but it did inspire me to write out a 4 character sequence and try to find the pattern, which i ended up figuring out after scribbling in my notebook for a few hours, taking my usual math-by-vibes based approach. really is just a buncha factorials and modifying temporary lists
also pumpkin helped he was my moral support while i dealt with algebra (derogatory)
