Thanks for using Compiler Explorer
Sponsors
Jakt
C++
Ada
Analysis
Android Java
Android Kotlin
Assembly
C
C3
Carbon
C++ (Circle)
CIRCT
Clean
CMake
CMakeScript
COBOL
C++ for OpenCL
MLIR
Cppx
Cppx-Blue
Cppx-Gold
Cpp2-cppfront
Crystal
C#
CUDA C++
D
Dart
Elixir
Erlang
Fortran
F#
GLSL
Go
Haskell
HLSL
Hook
Hylo
IL
ispc
Java
Julia
Kotlin
LLVM IR
LLVM MIR
Modula-2
Nim
Objective-C
Objective-C++
OCaml
OpenCL C
Pascal
Pony
Python
Racket
Ruby
Rust
Snowball
Scala
Solidity
Spice
SPIR-V
Swift
LLVM TableGen
Toit
TypeScript Native
V
Vala
Visual Basic
WASM
Zig
Javascript
GIMPLE
Ygen
python source #1
Output
Compile to binary object
Link to binary
Execute the code
Intel asm syntax
Demangle identifiers
Verbose demangling
Filters
Unused labels
Library functions
Directives
Comments
Horizontal whitespace
Debug intrinsics
Compiler
PyPy 3.10
PyPy 3.9
Python 3.10
Python 3.11
Python 3.12
Python 3.13
Python 3.5
Python 3.6
Python 3.7
Python 3.8
Python 3.9
Pythran 0.15
Options
Source code
def binary_search(left, right, is_green): assert left <= right if left == right: # 0 length interval; return one past the end. return left + 1 if not is_green(left): # Entire interval is red, return the first red (left). return left if is_green(right): # Entire interval is green, pretend one past the end is red. return right + 1 while left + 1 < right: middle = (left + right) // 2 if is_green(middle): left = middle else: right = middle return right def is_exp_green(n): return (2 ** n) <= 1_000_000 n = binary_search(0, 100, is_exp_green) print("First red: ", n) print("Value: ", 2**n)
Become a Patron
Sponsor on GitHub
Donate via PayPal
Source on GitHub
Mailing list
Installed libraries
Wiki
Report an issue
How it works
Contact the author
CE on Mastodon
About the author
Statistics
Changelog
Version tree