Skip to content

Instantly share code, notes, and snippets.

@sslotin
Created February 16, 2018 17:35
Show Gist options
  • Save sslotin/09c16773a6b1c56b53fc2ae579adc9f6 to your computer and use it in GitHub Desktop.
Save sslotin/09c16773a6b1c56b53fc2ae579adc9f6 to your computer and use it in GitHub Desktop.
from os import popen
from random import randint, choice, uniform
"""
def gen():
n = randint(2, 3)
q = randint(1, 20)
test = str(n) + ' 0 ' + str(q) + '\n'
g = [[] for _ in range(n+1)]
for _ in range(q):
while True:
t = choice('+-?')
u = randint(2, n)
v = randint(1, u-1)
if t == '+':
if u == v or u in g[v] or len(g[v]) > 1 or len(g[u]) > 1:
continue
g[u] += [v]
g[v] += [u]
if t == '-':
if u == v or u not in g[v]:
continue
g[u].remove(v)
g[v].remove(u)
test += t + ' ' + str(u) + ' ' + str(v) + '\n'
break
return test
"""
def gen():
n = randint(3, 3)
q = randint(2, 9)
test = str(n) + ' 0 ' + str(q) + '\n'
g = [[] for _ in range(n+1)]
for _ in range(q-1):
while True:
t = choice('+-')
u = randint(2, n)
v = randint(1, u-1)
if t == '+':
if u == v or u in g[v] or len(g[v]) > 1 or len(g[u]) > 1:
continue
g[u] += [v]
g[v] += [u]
if t == '-':
if u == v or u not in g[v]:
continue
g[u].remove(v)
g[v].remove(u)
test += t + ' ' + str(u) + ' ' + str(v) + '\n'
break
test += '? 1 2\n'
return test
for i in range(1000):
print i
f = open('test.txt', 'w')
test = gen()
f.write(test)
f.close()
v1 = popen('python3 stupid.py < test.txt').read()
v2 = popen('./run < test.txt').read()
if v1 != v2:
print "TEST"
print test
print "GOOD"
print v1
print "BAD"
print v2
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment