@anonymous/

RegalBrownDebugging

Python 2.7

No description

fork
loading
Files
  • main.py
main.py
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# https://qmemcpy.io

def hash(s):
    h = 7
    letters = "acdegilmnoprstuw"
    for c in s:
        h = h * 37 + letters.find(c)
    
    return h

def state2key(array, mask):
    for i, c in enumerate(array):
        array[i] = mask[c]

#######################################

NOTHING_YET = -1
TOO_BIG = 0
TOO_SMALL = 1

magic = 945924806726376 # promenade
mask = "acdegilmnoprstuw"

previous_attempt = NOTHING_YET
attempts = 0

state = [0] * 9

for i in range(9):
    for j in reversed(range(15)):
        attempts += 1

        tmp = state[:]
        tmp[i] = j
        state2key(tmp, mask)

        h = hash(tmp)
        if h == magic:
            print "Got it: {}, took {} attempts".format(''.join(tmp), attempts)
            exit(0)
        
        current_attempt = TOO_SMALL if h < magic else TOO_BIG
        print "{}: too {} ({})".format(''.join(tmp), "small" if current_attempt == TOO_SMALL else "big", h)

        if previous_attempt == TOO_BIG and current_attempt == TOO_SMALL:
            state[i] = j
            previous_attempt = NOTHING_YET
            break
        
        previous_attempt = current_attempt