@realazthat/

3-SUM-by-views

Python

No description

fork
loading
Files
  • main.py
  • generators.py
  • tests.py
  • three_sum_bisect.py
  • three_sum_indexed.py
  • three_sum_view.py
  • tsum_util.py
  • view.py

This Plugin Crashed!

Error: Error: must not create an existing file {"type":"CREATE_FILE","wid":"0.6318137905970813","path":"main.py","file":{"path":"main.py","content":{"asEncoding":{"base64":"CgoKaW1wb3J0IHRpbWUKaW1wb3J0IHN5cwppbXBvcnQgcmFuZG9tCmltcG9ydCB0ZXN0cwppbXBvcnQgdW5pdHRlc3QKaW1wb3J0IHRocmVlX3N1bV9iaXNlY3QKZnJvbSBnZW5lcmF0b3JzIGltcG9ydCBwYXRob2xvZ2ljYWxfZ2VuZXJhdG9yCmZyb20gdGhyZWVfc3VtX3ZpZXcgaW1wb3J0IHNvbHZlX3ZpZXdzCmZyb20gdGhyZWVfc3VtX2luZGV4ZWQgaW1wb3J0IHNvbHZlX2JydXRlCmZyb20gdmlldyBpbXBvcnQgdG9fdmlldwppbXBvcnQgdHN1bV91dGlsCmZyb20gZnVuY3Rvb2xzIGltcG9ydCBwYXJ0aWFsCgoKCgoKZGVmIG1lYXN1cmVfY29tcGxleGl0eShmLGcsbixLLHQ9Tm9uZSwgcD10c3VtX3V0aWwucHJpbnRfbnVsbCk6CiAgCiAgdGltZXMgPSBbXQogIGZvciBuIGluIHJhbmdlKDEsIDEwMDApOgogICAgCiAgICBwKCd0ZXN0aW5nIEs9JXMgdHJpYWxzIHdpdGggbj0lcycgJSAoSyxuLCkpCiAgICAKICAgIHQwID0gdGltZS50aW1lKCkKICAgIGZvciBfIGluIHJhbmdlKEspOgogICAgICBjZXJ0aWZpY2F0aW9uLCBwcm9ibGVtID0gZyhuKQogICAgICBzb2x1dGlvbiA9IGYocHJvYmxlbSkKICAgICAgaWYgdDogYXNzZXJ0IHQoc29sdXRpb24pCgogICAgCiAgICBkdCA9IHRpbWUudGltZSgpIC0gdDAKICAgIAogICAgZGR0ID0gKGR0LXRpbWVzWy0xXSkg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ogICAgICBhc3NlcnQgdHN1bV91dGlsLnJlc29sdmUoSSxKLEssIGV4cGVjdGVkX3RyaXBsZXRzKSA9PSB0c3VtX3V0aWwucmVzb2x2ZShJLEosSywgdHJpcGxldHMpCiAgICAKICAgIAogICAgaWYgY2VydGlmeToKICAgICAgYXNzZXJ0IHRyaXBsZXQgaW4gdHJpcGxldHMKICAgIAogICAgdHJpcGxldHMgPSB0c3VtX3V0aWwucmVzb2x2ZShJLEosSywgdHJpcGxldHMpCiAgICAKICAgIGZvciBpdmFsdWUsanZhbHVlLGt2YWx1ZSBpbiB0cmlwbGV0czoKICAgICAgYXNzZXJ0IGl2YWx1ZSArIGp2YWx1ZSA9PSBrdmFsdWUKICAKZGVmIGJpc2VjdF9jb21wbGV4aXR5X21haW4oKToKICByYW5kb20uc2VlZCgxKQogIAogIGhlYXZ5ID0gRmFsc2UKICBwID0gdHN1bV91dGlsLnByaW50X251bGwKICBkZWYgZihwcm9ibGVtKToKICAgIEksSixLID0gcHJvYmxlbQogICAgc29sdXRpb24gPSB0aHJlZV9zdW1fYmlzZWN0LnNvbHZlKEksSixLLHA9cCxoZWF2eT1oZWF2eSxjaG9vc2U9J2xhcmdlc3QnKQogICAgcmV0dXJuIHNvbHV0aW9uCiAgbnVtZXJpY19tYXhfYml0cyA9IDgKICBkZWYgZyhuKToKICAgIGNlcnRpZmljYXRpb24sViA9IHBhdGhvbG9naWNhbF9nZW5lcmF0b3IoCiAgICAgICAgICAgICAgICBOYml0cz1udW1lcmljX21heF9iaXRzLAogICAgICAgICAgICAgICAgbj1uLAogICAgICAgICAgICAgICAgY2VydGlmeT1yYW5kb20ucmFuZG9tKCkgPiAwLjUpCiAgICBJLEosSyA9IFYsVixWCiAgICBwcm9ibGVtID0gSSxKLEsKICAgIHJldHVybiAoY2VydGlmaWNhdGlvbixwcm9ibGVtKQogIAogIHRpbWVzID0gbWVhc3VyZV9jb21wbGV4aXR5KGYsZyxuPTEwMCxLPTEwMCxwPXByaW50KQogIHByaW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IHRyaXBsZXRzKQogICAgCiAgICBmb3IgaXZhbHVlLGp2YWx1ZSxrdmFsdWUgaW4gdHJpcGxldHM6CiAgICAgIGFzc2VydCBpdmFsdWUgKyBqdmFsdWUgPT0ga3ZhbHVlCiAgCiAgIyByYW5kb20uc2VlZCgwKQogIAogICMgTiA9IDEgPDwgMjQKICAjIE0gPSA1MAogIAogICMgSSA9IChbcmFuZG9tLnJhbmRpbnQoMSwgTikgZm9yIF8gaW4gcmFuZ2UoTSldKQogIAogICMgTl9JID0gbWF4KFt4LmJpdF9sZW5ndGgoKSBmb3IgeCBpbiBJXSkKICAKICAjIElfc3RyID0gbGlzdChtYXAobGFtYmRhIHg6IGJpbih4KVsyOl0uemZpbGwoTl9JKSwgSSkpCiAgCiAgIyBJX3N0ciA9IGxpc3QobWFwKGxhbWJkYSB4OiB4Wzo6LTFdLCBzb3J0ZWQobWFwKGxhbWJkYSB4OiB4Wzo6LTFdLCBJX3N0cikpKSkKICAKICAjIHByaW50ICgnXG4nLmpvaW4oSV9zdHIpKQogIAogIAogICMgcHJpbnQgKG51bXB5Lnplcm9zKHNoYXBlPSg1MCw1MCksIGR0eXBlPSdib29sJykpCg=="},"asBuffer":null},"loaded":true}}
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237


import time
import sys
import random
import tests
import unittest
import three_sum_bisect
from generators import pathological_generator
from three_sum_view import solve_views
from three_sum_indexed import solve_brute
from view import to_view
import tsum_util
from functools import partial





def measure_complexity(f,g,n,K,t=None, p=tsum_util.print_null):
  
  times = []
  for n in range(1, 1000):
    
    p('testing K=%s trials with n=%s' % (K,n,))
    
    t0 = time.time()
    for _ in range(K):
      certification, problem = g(n)
      solution = f(problem)
      if t: assert t(solution)

    
    dt = time.time() - t0
    
    ddt = (dt-times[-1]) if len(times) > 0 else dt
    
    p('tested K trials with n=%s, K=%s, dt=%.4fs, dt/K=%.4fs, ddt=%.4fs' % (n,K,dt,dt/K, ddt))
    times.append(dt)
  return times
  
def bisect_main():
  random.seed(1)
  
  numeric_max_bits = 8
  sample_count = 1000
  sample_length = 10
  
  samples = [
    pathological_generator(
      Nbits=numeric_max_bits,
      n=sample_length,
      certify=random.random() > 0.5)
    for _ in range(sample_count)
  ]
  
  # samples = [
    #((0, 2, 1), [29, 41, 12]),
    # (None, [37, 17, 37]),
    # ((1, 0, 2), [50, 216, 266])
    # ((1, 0, 0), [31, 0, 31])
    # ]



  outfile = open('outfile.txt', 'w')
  
  heavy = True
  fancy = True
  p = tsum_util.print_null
  p = partial(print,file=outfile)
  for sample_index,(triplet, I) in enumerate(samples):
    print ('-')
    print ('sample index:',sample_index)
    print ('triplet, I:', repr((triplet, I)))
    certify = triplet is not None
    
    I,J,K = I,I,I
  
    if certify:
      i,j,k = triplet
      ivalue, jvalue, kvalue = I[i], J[j], K[k]
      assert ivalue + jvalue == kvalue
    
    triplets = three_sum_bisect.solve(I,J,K,p=p,heavy=heavy,choose='largest')
  
    print ('I:', I)
    print ('certify:', certify)
    print ('triplet:', triplet)
    print ('triplets:', triplets)
    print ('resolve(triplets):', tsum_util.resolve(I,J,K, triplets))
    print ('len(triplets):', len(triplets))
    print ('triplets:', triplets)
    if heavy:
      expected_triplets = solve_brute(I,J,K)
      print ('expected_triplets:', expected_triplets)
      print ('resolve(expected_triplets):', tsum_util.resolve(I,J,K, expected_triplets))
      assert expected_triplets == triplets
      assert tsum_util.resolve(I,J,K, expected_triplets) == tsum_util.resolve(I,J,K, triplets)
    
    
    if certify:
      assert triplet in triplets
    
    triplets = tsum_util.resolve(I,J,K, triplets)
    
    for ivalue,jvalue,kvalue in triplets:
      assert ivalue + jvalue == kvalue
  
def bisect_complexity_main():
  random.seed(1)
  
  heavy = False
  p = tsum_util.print_null
  def f(problem):
    I,J,K = problem
    solution = three_sum_bisect.solve(I,J,K,p=p,heavy=heavy,choose='largest')
    return solution
  numeric_max_bits = 8
  def g(n):
    certification,V = pathological_generator(
                Nbits=numeric_max_bits,
                n=n,
                certify=random.random() > 0.5)
    I,J,K = V,V,V
    problem = I,J,K
    return (certification,problem)
  
  times = measure_complexity(f,g,n=100,K=100,p=print)
  print (times)
  
# bisect_main()
bisect_complexity_main()

def views_main():
  random.seed(1)
  
  numeric_max_bits = 64
  sample_count = 1
  sample_length = 100
  
  samples = [
    pathological_generator(
      Nbits=numeric_max_bits,
      n=sample_length,
      certify=random.random() > 0.5)
    for _ in range(sample_count)
  ]
  # samples = [
  #   (
  #     (2, 4, 3),
  #     [4079209076, 3965891272, 3648514451, 7266853563, 3618339112]
  #   ),
    # (None, [8, 3, 25, 24, 19]),
  #   ((1, 0, 2), [2, 18, 20, 29, 7]),
  #   ((0, 8, 6), [7912, 46315, 7913, 1191, 38166, 47604, 28381, 20061, 20469, 7911])
    # ((4, 6, 8), [35632, 33120, 113244, 113242, 8549, 113243, 13162, 51739, 21711, 57736])
    # ((0, 2, 3), [6, 12, 22, 28]),
    # ((0, 0, 1), [14, 28, 15, 14]),
    # ((4, 7, 6), [22, 0, 69, 72, 226, 174, 296, 70]),
  # ]
  
  
  # unittest.main(module='tests')
  
  outfile = open('outfile.txt', 'w')
  
  heavy = True
  fancy = True
  p = tsum_util.print_null
  p = partial(print,file=outfile)
  for sample_index,(triplet, I) in enumerate(samples):
    print ('-')
    print ('sample index:',sample_index)
    print ('triplet, I:', repr((triplet, I)))
    certify = triplet is not None
    
    I,J,K = I,I,I
  
    if certify:
      i,j,k = triplet
      ivalue, jvalue, kvalue = I[i], J[j], K[k]
      assert ivalue + jvalue == kvalue
    
    # print (to_view(I,heavy=heavy).all_str())
    # break;
    
    print ('I:',I)
    print ('to_view(I).collect():',to_view(I,heavy=heavy).collect())
    print ('index(I):',tsum_util.index(I))
    assert (to_view(I,heavy=heavy).collect() == tsum_util.index(I))
    triplets = solve_views(to_view(I,heavy=heavy),
                           to_view(J,heavy=heavy),
                           to_view(K,heavy=heavy),
                           heavy=heavy, p=p, expected_case='mmm',
                           fancy=fancy)
  
    print ('I:', I)
    print ('certify:', certify)
    print ('triplet:', triplet)
    print ('resolve(triplet):', tsum_util.resolve(I,J,K, triplets))
    print ('len(triplets):', len(triplets))
    print ('triplets:', triplets)
    if heavy:
      expected_triplets = solve_brute(I,J,K)
      print ('resolve(expected_triplets):', tsum_util.resolve(I,J,K, expected_triplets))
      assert expected_triplets == triplets
      assert tsum_util.resolve(I,J,K, expected_triplets) == tsum_util.resolve(I,J,K, triplets)
    
    
    if certify:
      assert triplet in triplets
    
    triplets = tsum_util.resolve(I,J,K, triplets)
    
    for ivalue,jvalue,kvalue in triplets:
      assert ivalue + jvalue == kvalue
  
  # random.seed(0)
  
  # N = 1 << 24
  # M = 50
  
  # I = ([random.randint(1, N) for _ in range(M)])
  
  # N_I = max([x.bit_length() for x in I])
  
  # I_str = list(map(lambda x: bin(x)[2:].zfill(N_I), I))
  
  # I_str = list(map(lambda x: x[::-1], sorted(map(lambda x: x[::-1], I_str))))
  
  # print ('\n'.join(I_str))
  
  
  # print (numpy.zeros(shape=(50,50), dtype='bool'))