#!/usr/bin/env python3 # -*- coding: utf-8 -*- import array import collections import sys MAX_D = 10 Status = collections.namedtuple("Status", "digits, status") def submit_guess(guess_sequence): def array_to_int(sequence): tens = (10 ** k for k in range(MAX_D)[::-1]) return sum(x * y for x, y in zip(sequence, tens)) print("{:0=10d}".format(array_to_int(guess_sequence))) sys.stdout.flush() d, s = input().split() return Status(int(d), s == "unlocked") def main(): guess_sequence = array.array("B", (0 for _ in range(MAX_D))) prev_digits, prev_status = submit_guess(guess_sequence) digits, status = prev_digits, prev_status if status: return for place in range(MAX_D)[::-1]: for digit in range(10): guess_sequence[place] = digit digits, status = submit_guess(guess_sequence) if status: return elif prev_digits < digits: prev_digits = digits break elif prev_digits > digits: guess_sequence[place] = max(digit - 1, 0) digits = prev_digits break else: continue if __name__ == '__main__': main()