#!/usr/bin/env python3 import array import collections import sys MAX_SIZE = 20 RES_GOAL = "Merry Christmas!" DIST_INF = 20151224 DRS = [1, 0, -1, 0] DCS = [0, 1, 0, -1] class Solver(object): def __init__(self): self.visited = collections.defaultdict(bool) def depth_first_search(self, r0, c0, angle): self.visited[(r0, c0)] = True for _ in range(4): result = self.submit("R") while result >= DIST_INF: self.submit("F") new_angle = (angle + 1) % 4 r = r0 + DRS[new_angle] c = c0 + DCS[new_angle] if result > 0 and not self.visited[(r, c)]: self.submit("F") self.depth_first_search(r, c, new_angle) self.submit("B") @staticmethod def submit(command): print(command) sys.stdout.flush() result = input() if result == RES_GOAL: sys.exit() else: return int(result) def main(): s = Solver() s.depth_first_search(0, 0, 0) if __name__ == '__main__': main()