Created
September 2, 2021 15:19
-
-
Save JosephTLyons/53ff51de671409a19a8c512cd7613809 to your computer and use it in GitHub Desktop.
Simulates the trick of picking 2 random cards and then seeing if those two cards end up next to each other in a shuffled deck
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import random | |
| def main(): | |
| runs = 100_000 | |
| successes = 0 | |
| cards = list(range(13)) * 4 | |
| for _ in range(runs): | |
| random.shuffle(cards) | |
| random_sorted_pair = sorted(random.sample(cards, 2)) | |
| random.shuffle(cards) | |
| if any(random_sorted_pair == sorted(adjacent_pair) for adjacent_pair in zip(cards, cards[1:])): | |
| successes += 1 | |
| print(f"{successes} / {runs} = {successes / runs}") | |
| if __name__ == "__main__": | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment