Skip to content

Instantly share code, notes, and snippets.

@AdrianAcala
Last active January 28, 2022 19:55
Show Gist options
  • Save AdrianAcala/6e46bce376efa19a271417743bf43648 to your computer and use it in GitHub Desktop.
Save AdrianAcala/6e46bce376efa19a271417743bf43648 to your computer and use it in GitHub Desktop.
How often will a double flop be the same rank
package main
import (
"fmt"
"math/rand"
"sort"
"time"
)
func createDeck() *[52]int {
var deck [52]int
for i := 0; i < 52; i++ {
deck[i] = i
}
return &deck
}
func shuffleDeck(a *[52]int) {
rand.Seed(time.Now().UnixNano())
rand.Shuffle(len(a), func(i, j int) { a[i], a[j] = a[j], a[i] })
}
/*
For these purposes, we will rank A as 1, 2 as 2, ... K as 13.
*/
func getRankOfFlop(flop []int) []int {
// var flopRank []int
flopRank := make([]int, 3)
for i, card := range flop {
// Adding 1 so we go from 1-13 instead of 0-12.
flopRank[i] = (card % 13) + 1
}
return flopRank
}
func main() {
numOfRuns := 10000000
deck := createDeck()
numOfMatchingFlops := 0
for i := 0; i < numOfRuns; i++ {
shuffleDeck(deck)
// First three cards
firstFlop := deck[0:3]
secondFlop := deck[3:6]
firstFlopRank := getRankOfFlop(firstFlop)
secondFlopRank := getRankOfFlop(secondFlop)
sort.Ints(firstFlopRank)
sort.Ints(secondFlopRank)
matchingFlop := true
for j := 0; j < 3; j++ {
if firstFlopRank[j] != secondFlopRank[j] {
matchingFlop = false
break
}
}
if matchingFlop {
numOfMatchingFlops += 1
}
}
fmt.Println("Number of matching flops: ", numOfMatchingFlops)
fmt.Println("Percentage: ", fmt.Sprintf("%.2f", float64(numOfMatchingFlops)/float64(numOfRuns)*100), "%")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment