Skip to content

Instantly share code, notes, and snippets.

@R3DHULK
Created March 28, 2023 17:55
Show Gist options
  • Save R3DHULK/41af9a0edd2ccbe4c0a71ee10c391867 to your computer and use it in GitHub Desktop.
Save R3DHULK/41af9a0edd2ccbe4c0a71ee10c391867 to your computer and use it in GitHub Desktop.
Simon Says In Go
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