Skip to content

Instantly share code, notes, and snippets.

@ceth-x86
Created November 15, 2020 10:20
Show Gist options
  • Save ceth-x86/bd80a8e04f3ad66bb3dc9ca9aef8c057 to your computer and use it in GitHub Desktop.
Save ceth-x86/bd80a8e04f3ad66bb3dc9ca9aef8c057 to your computer and use it in GitHub Desktop.
func main() {
a := []int{1, 3, 6, 10, 15, 21, 28, 36, 45, 55}
x := 6
i := sort.Search(len(a), func(i int) bool { return a[i] >= x })
if i < len(a) && a[i] == x {
fmt.Printf("found %d at index %d in %v\n", x, i, a)
} else {
fmt.Printf("%d not found in %v\n", x, a)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment