refactor: lucky number exercises
* guess < 0 doesn't check for definitive positivity * n := rand.Intn(guess + 1) may pick 0, a non positive integer * remove: redundant parentheses from the loop in 06-dynamic-difficulty
This commit is contained in:
@@ -45,13 +45,13 @@ func main() {
|
||||
return
|
||||
}
|
||||
|
||||
if guess < 0 {
|
||||
if guess <= 0 {
|
||||
fmt.Println("Please pick a positive number.")
|
||||
return
|
||||
}
|
||||
|
||||
for turn := (maxTurns + guess/4); turn > 0; turn-- {
|
||||
n := rand.Intn(guess + 1)
|
||||
for turn := maxTurns + guess/4; turn > 0; turn-- {
|
||||
n := rand.Intn(guess) + 1
|
||||
|
||||
if n == guess {
|
||||
fmt.Println("🎉 YOU WIN!")
|
||||
|
Reference in New Issue
Block a user