-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsplit.py
More file actions
62 lines (54 loc) · 1.51 KB
/
Copy pathsplit.py
File metadata and controls
62 lines (54 loc) · 1.51 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
from random import randint
def get_init_split(s):
return [0,len(s)]
def divide(split):
assert(len(split) > 1)
r = randint(1,len(split) - 1)
if split[r - 1] < split[r] - 1:
# Copy because insert modifies object.
split = list(split)
rr = randint(split[r-1] + 1, split[r] - 1)
split.insert(r,rr)
return split
def join(split):
assert(len(split) > 2)
r = randint(1, len(split) - 2)
# Copy because pop modifies object.
split = list(split)
split.pop(r)
return split
def move(split):
assert(len(split) > 2)
r = randint(1, len(split) - 2)
d = randint(0,1)
if d:
if split[r - 1] < split[r] - 1:
# Copy because we modify object.
split = list(split)
split[r] -= 1
else:
if split[r] < split[r+1] - 1:
# Copy because we modify object.
split = list(split)
split[r] += 1
return split
def sample_next(split,max_splits):
r = randint(0,2)
if r == 0 and len(split) - 1 < max_splits:
split = divide(split)
elif r == 1:
if (len(split) > 2):
split = join(split)
else:
if (len(split) > 2):
split = move(split)
return split
def sample_nth(n,split,max_splits):
for i in range(n):
split = sample_next(split,max_splits)
return split
def get_str(i,split,wf):
# assert(i < len(split) - 1)
if i >= len(split) - 1:
return ""
return wf[split[i]:split[i+1]]