import tele from stream import * def telemetry(): yield 0 stream.open()
# telemetry data buffer = [] while True: read() analyze()
status = OK metrics = get() push(metrics) 0x11 0xA2
≡
Token Telemetry
import tele from stream import * def telemetry(): yield 0 stream.open()
# telemetry data buffer = [] while True: read() analyze()
status = OK metrics = get() push(metrics) 0x11 0xA2
def kk(nums): h=[-x for x in nums] heapify(h) while len(h)>1: a=-heappop(h) b=-heappop(h) heappush(h,-(a-b)) return -h[0] # karmarkar-karp # differencing # NP-hard partition() solve() balance≈0
3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 diff = a - b heap.push balance ≈ 0 ∑S₁ − ∑S₂ min |Δ| greedy.k=2
∑S₁ − ∑S₂ min |Δ| O(n log n) greedy.k=2 partition() solve() heap.pop push.diff n→n-1
while |H|>1: a,b=pop2(H) push(H,a−b) return H[0] diff.tree recombine O(n log n)
0xKK 0x4A 0x9F 0x12 0xAE 0x77 0x3B 0xC4 0x81 0x05
def rk(t,p):
n,m=len(t),len(p)
hp=hash(p)
ht=hash(t[:m])
for i in range(n-m+1):
if ht==hp:
if t[i:i+m]==p:
yield i
ht=roll(ht,t,i,m)
# rolling hash
# fingerprint
hash(p) ≡ hash(t[i..i+m]) rolling.window mod q · base b collision? verify. shift >> 1 re-hash O(n+m) avg O(nm) worst
a c a a b c pattern = abc match @ i=3 hash=0x7F1A shift >> 1 re-hash fingerprint match.found yield i
0xR4 0xB1 0x9E 0xC0 0x2D 0xFA 0x66 0x18 0xD3 0x07
substring search fingerprint = h plagiarism det. O(n+m) avg O(nm) worst window.slide hash.update verify==