Created
March 28, 2023 17:55
-
-
Save R3DHULK/41af9a0edd2ccbe4c0a71ee10c391867 to your computer and use it in GitHub Desktop.
Simon Says In Go
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() { | |
rand.Seed(time.Now().UnixNano()) | |
fmt.Println("Welcome to Simon Says!") | |
fmt.Println("Watch carefully and repeat the sequence.") | |
sequence := generateSequence(5) | |
fmt.Println("Simon says:", sequence) | |
for i := 0; i < len(sequence); i++ { | |
var input int | |
fmt.Scanln(&input) | |
if input != sequence[i] { | |
fmt.Println("Game over!") | |
return | |
} | |
} | |
fmt.Println("Congratulations! You won!") | |
} | |
func generateSequence(length int) []int { | |
sequence := make([]int, length) | |
for i := 0; i < length; i++ { | |
sequence[i] = rand.Intn(4) + 1 | |
} | |
return sequence | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment