This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
fast_perm_check [2023/03/21 19:06] harshec created |
fast_perm_check [2023/04/19 14:30] (current) harshec |
||
---|---|---|---|
Line 1: | Line 1: | ||
====Fast-Perm-Check==== | ====Fast-Perm-Check==== | ||
- | This algorithm was created by Landon Kryger to solve the problem of testing if a set of dice is permutation fair. If you have //n// players and //s// sides, the standard approach would require you to test every roll and would run in O(// | + | This algorithm was created by Landon Kryger to solve the problem of testing if a set of dice is permutation fair. If you have //n// players and //s// sides, the standard approach would require you to test every roll and would run in O(// |
This algorithm also works with dice with different number of sides. | This algorithm also works with dice with different number of sides. | ||
- | Python Code | + | ===Python Code=== |
< | < | ||
1 s = " | 1 s = " | ||
Line 14: | Line 14: | ||
7 count[k2] = count.get(k2, | 7 count[k2] = count.get(k2, | ||
</ | </ | ||
- | s is just the input dice set | ||
- | count will contain how many ways each substring can occur. We initialize it to say that from the get-go, there is only one way to have the empty string. | ||
- | We step through every number in the die step. Each step will depend on the previous step. | ||
- | We need to look at all substrings. The real magic happens on line 7 | ||
- | We don't need to look at strings like ' | ||
- | k2 is the new string concatenated with the current die/number we're processing. | ||
- | The simplest way to explain this is with an example. Let's say the current letter is a c. The number of ways to make ' | ||
- | | + | * s is just the input dice set |
+ | * count will contain how many ways each substring can occur. We initialize it to say that from the get-go, there is only one way to have the empty string. | ||
+ | * We step through every number in the die step. Each step will depend on the previous step. | ||
+ | * We need to look at all substrings. The real magic happens on line 7 | ||
+ | * We don't need to look at strings like ' | ||
+ | * k2 is the new string concatenated with the current die/number we're processing. | ||
+ | * The simplest way to explain this is with an example. Let's say the current letter is a c. The number of ways to make ' | ||
+ | |||
+ | [[http:// |