-
-
Save NicolaM94/dd49b3b44a8938c40d0539512fd613cb to your computer and use it in GitHub Desktop.
Linear solution for the problem
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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