Last active
June 29, 2026 12:26
-
-
Save goofballLogic/bcb9451362a0c9dc68adf3106facf6a0 to your computer and use it in GitHub Desktop.
not entirely sure i got the math spot on, and I'm fairly sure I can do this with a logarithm if I thought hard enough but...
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
| function meanBits(n) { | |
| let bits = 1, counted = 0, sum = 0; | |
| while(counted < n) { | |
| const depth = Math.pow(2, Math.max(1, bits - 1)); | |
| const count = Math.min(n - counted, depth); | |
| sum += count * bits; | |
| counted += count; | |
| bits++; | |
| } | |
| return Math.round(sum / n); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment