def example_io(t_pre: Place, t_post: Place = Result()) -> bool: Terminates(True) TerminationMeasure(2) return IOExists3(Place, bool, bool)(lambda t2, success1, success2: (write_char_io(t_pre, stdout, 'h', success1, t2) and write_char_io(t2, stdout, 'i', success2, t_post)))
def yes_io(t_pre: Place) -> bool: Terminates(False) return IOExists4( Place, Place, bool, bool)(lambda t2, t3, success1, success2: (write_char_io(t_pre, stdout, 'y', success1, t2) and write_char_io(t2, stdout, '\n', success2, t3) and yes_io(t3)))
def matching_brackets_helper(t_pre: Place, t_post: Place = Result()) -> bool: return IOExists5( bool, bool, Place, Place, Place)(lambda success1, success2, t_open, t_center, t_close: (write_char_io(t_pre, stdout, '(', success1, t_open) and matching_brackets(t_open, t_center) and write_char_io( t_center, stdout, ')', success2, t_close ) and matching_brackets(t_close, t_post)))
def print_unary_io(t_pre: Place, number: int, t_end: Place = Result()) -> bool: Terminates(True) TerminationMeasure(number + 2 if number >= 1 else 2) return IOExists2(Place, bool)(lambda t2, success: ( (write_char_io(t_pre, stdout, '1', success, t2) and print_unary_io( t2, number - 1, t_end)) if number >= 1 else (no_op_io(t_pre, t_end))))
def main(t1: Place) -> Place: IOExists8(str, Place, str, bool, Place, Place, bool, bool)( lambda read_ahead, t_read_ahead, read_last, valid, t_brackets_end, t_end, success1, success2: ( Requires( token(t1) and read_char_io(t1, stdin, read_ahead, success1, t_read_ahead) and brackets_io(t_read_ahead, read_ahead, read_last, valid, t_brackets_end) and read_last is None and write_char_io(t_brackets_end, stdout, ('1' if valid else '0'), success2, t_end) ), Ensures( token(t_end) and t_end == Result() ), ) ) m = Matcher() m.c, success, t2 = getchar(t1) t3, match = m.brackets(t2) if match: success, t4 = putchar('1', t3) else: success, t4 = putchar('0', t3) return t4
def main(t1: Place) -> Place: IOExists4(Place, Place, bool, bool)( lambda t2, t3, success1, success2: ( Requires( token(t1, 2) and write_char_io(t1, stdout, 'h', success1, t2) and write_char_io(t2, stdout, 'i', success2, t3) and MustTerminate(2) ), Ensures( token(t3) and t3 == Result() ) )) success, t2 = putchar('h', t1) success, t3 = putchar('i', t2) return t3
def infinite_counter_io(t_pre: Place, number: int) -> bool: return IOExists3(Place, Place, bool)( lambda t2, t3, success: (print_unary_io( t_pre, number, t2) and write_char_io(t2, stdout, '\n', success, t3) and infinite_counter_io(t3, number + 1)))
def output_anything(t_pre: Place, t_post: Place = Result()) -> bool: Terminates(True) TerminationMeasure(2) return IOExists3(str, Place, bool)(lambda c, t2, success: (set_var_io( t_pre, c, t2) and write_char_io(t2, stdout, c, success, t_post)))