Exercise 3: Finding the Exact One-Byte-Jump Crossover — Possible Solution ==================================================================== THE SEARCH ------------------------------ def one_byte_compiles(filler_count): prog = [ VarStmt('i', Literal(0.0), line=1), WhileStmt( Binary(Variable('i'), '<', Literal(3.0)), BlockStmt(build_big_loop_body(filler_count)), ), ] try: CompilerOneByte().compile_program(prog) return True except ValueError: return False # exponential search to find an upper bound, then binary search lo, hi = 0, 1 while one_byte_compiles(hi): lo = hi hi *= 2 while hi - lo > 1: mid = (lo + hi) // 2 if one_byte_compiles(mid): lo = mid else: hi = mid RESULT ------------------------------ Largest filler_count that still compiles (1-byte encoding): 79 Smallest filler_count that fails: 80 Direct confirmation: one_byte_compiles(79) -> True one_byte_compiles(80) -> False For reference, the real 2-byte Compiler handles filler_count=80 at 264 total code bytes without any problem at all. WHY THIS WORKS AS AN ANSWER ------------------------------ 79 filler statements plus the loop's own condition check, increment, and jump instructions land just under the one-byte ceiling of 255; the 80th filler statement's own two bytes (each filler is a one-line expression statement compiling to OP_CONSTANT + index + OP_POP, 3 bytes) push the total forward-jump distance for OP_JUMP_IF_FALSE past 255, and the one-byte patch_jump can no longer represent it -- raising the identical ValueError this course has now seen for the constant pool (Chapter 2), the local-slot count (Chapter 4), and now jump distance. The binary-search technique itself is worth noting too: it's the same halve-the-search-space approach this course used to pin down recursion-depth ceilings in Chapter 1, applied here to a completely different kind of boundary -- a reminder that "find the exact breaking point by binary search" is a generally reusable debugging technique, not something specific to any one of these three limits.