Skip to content

Instantly share code, notes, and snippets.

@dilakv
Created October 28, 2021 01:04
Show Gist options
  • Save dilakv/4f4767db72f83a75b1cd87b80f786cda to your computer and use it in GitHub Desktop.
Save dilakv/4f4767db72f83a75b1cd87b80f786cda to your computer and use it in GitHub Desktop.
Búsqueda binaria de un número entre el mínimo y el máximo
func busqueda_binaria(min uint64, max uint64, item uint64) uint64 {
var intentos uint64 = 0;
if(item < min || item > max){
return 0
}
for min <= max {
intentos++
var medio uint64 = (min + max) / 2
var seraestenumero = medio
if seraestenumero == item {
fmt.Printf("Se logro en %v intentos, el número es %v", intentos, seraestenumero)
return seraestenumero
}
if seraestenumero > item {
max = medio - 1
}else{
min = medio + 1
}
}
return 0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment