Skip to content

Instantly share code, notes, and snippets.

@NicolaM94
Last active November 12, 2023 12:55
Show Gist options
  • Save NicolaM94/dd49b3b44a8938c40d0539512fd613cb to your computer and use it in GitHub Desktop.
Save NicolaM94/dd49b3b44a8938c40d0539512fd613cb to your computer and use it in GitHub Desktop.
Linear solution for the problem
package main
import (
"fmt"
"math/rand"
"time"
)
func main() {
// Creating the building
var building []int
for c := 0; c < 100000; c++ {
building = append(building, c)
}
// Generating the random targetFloor
targetFloor := rand.New(rand.NewSource(time.Now().UnixNano())).Intn(len(building))
// Actual solution
for f := range building {
if building[f] == targetFloor {
fmt.Println("Eggs start to break at floor ", f)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment