summaryrefslogtreecommitdiff
path: root/primes.py
blob: 690168aac544f86195dce1c30fecf732cca80386 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/env python
#
# Simple program to compute the biggest twin prime pair less than each
# power of 2.
#
# This is used to choose "good" sizes for the hashtable.
#
# Using a prime for "num_slot" is useful as that guarantees that the
# orbit touches every slot (which is useful to have a good
# implementation of open addressing, because this means that as long
# as you have free slots, you can add elements, no matter what their
# hash is).
#
# Using a prime for the linear offset is not actually needed, but
# avoiding composite numbers is usually a good idea, because they tend
# to show bad behavior depending on the patterns found in the input
# data.
#

def isprime(x):
    d = 2
    while d * d <= x:
        if x % d == 0:
            return False
        d = d + 1
    return True

for i in range(3, 33):
    x = 2 ** i
    while not (isprime(x) and isprime(x-2)):
        x = x - 1
    print "    %d," % x