Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- import sys
- import random
- import subprocess
- def main():
- n = random.randint(1, 1e6)
- sys.stderr.write(f"begin with {n=}\n")
- v = [x + 1 for x in range(n)]
- random.shuffle(v)
- idx = 0
- opt = 0
- process = subprocess.Popen(["./g2.exe"],
- stdin=subprocess.PIPE,
- stdout=subprocess.PIPE)
- process.stdin.write(bytes(f"{v[idx]}\n", "utf8")), process.stdin.flush()
- while process.poll() is None:
- sys.stdin.flush()
- line = process.stdout.readline().strip()
- #sys.stderr.write(f"read {line}\n")
- if line[0] == ord('!'):
- exp = int(line[1:])
- if exp == n:
- sys.stderr.write(f"get right ans {exp=}\n")
- return 0
- else:
- raise Exception(f"real {n=}, {exp=}\n")
- else:
- op = line[0]
- cnt = int(line[1:])
- if op == ord('+'):
- idx = (idx + cnt) % n
- else:
- assert op == ord('-'), f"{op} not '-'"
- idx = (idx - cnt) % n
- process.stdin.write(bytes(f"{v[idx]}\n",
- "utf8")), process.stdin.flush()
- opt += 1
- if opt % 100 == 0:
- sys.stderr.write(f"opt get ${opt}\n")
- if opt >= 1000:
- break
- raise Exception("Too many try")
- if __name__ == "__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement