-
-
Save rbehrends/113d2759d36a1e7bb6c8 to your computer and use it in GitHub Desktop.
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 mersenne, times | |
| const | |
| N = 8 | |
| M = 8 | |
| iters = 1000 | |
| type | |
| SVec = array[0..N+M-1, int] | |
| FVec = array[0..N-1, int] | |
| var | |
| rngState = newMersenneTwister(int(cpuTime()*1000)) | |
| proc isZero(v: FVec): bool = | |
| for x in v: | |
| if x != 0: | |
| return false | |
| return true | |
| proc initVecRand(v: var FVec) = | |
| var rnd = rngState.getNum() | |
| for i in 0 .. <len(v): | |
| let m = rnd and 3 | |
| rnd = rnd shr 2 | |
| v[i] = if m <= 2: m-1 else: 0 | |
| if isZero(v): | |
| initVecRand(v) | |
| proc convolve(s: SVec, f: FVec, offset: int): int = | |
| for i in 0 .. <len(f): | |
| let a = s[i+offset] | |
| let b = f[i] | |
| result += a * b | |
| proc advance(v: var SVec) = | |
| for i in 0 .. <len(v): | |
| if v[i] == -1: | |
| v[i] = 1 | |
| return | |
| v[i] = -1 | |
| proc main = | |
| const numS = 1 shl (N+M-1) | |
| var | |
| s: SVec | |
| f: FVec | |
| leadingZeros: array[0..M-1, int] | |
| for k in 0 .. <len(s): | |
| s[k] = -1 | |
| for i in 1..numS: | |
| for j in 1..iters: | |
| initVecRand(f) | |
| if convolve(s, f, 0) == 0: | |
| leadingZeros[0] += 1 | |
| for k in 1 .. <M: | |
| if convolve(s, f, k) == 0: | |
| leadingZeros[k] += 1 | |
| else: | |
| break | |
| s.advance | |
| echo "leading zeros: ", @leadingZeros | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment