Skip to content

Instantly share code, notes, and snippets.

@ouzsrcm
Last active June 29, 2022 15:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ouzsrcm/9bd6ce023b78edea8cde075105d65776 to your computer and use it in GitHub Desktop.
Save ouzsrcm/9bd6ce023b78edea8cde075105d65776 to your computer and use it in GitHub Desktop.
where am i and where to go :/
package main
import (
"fmt"
"math/rand"
"reflect"
)
type Location struct {
Name string
Lat float32
Long float32
}
var favorites = []Location{
Location{
Name: "Amasya",
Lat: 40.65708300559417,
Long: 35.82698609189353,
},
Location{
Name: "Sakarya",
Lat: 40.76730300429302,
Long: 30.398113803832402,
},
Location{
Name: "İstanbul",
Lat: 41.03009409004069,
Long: 29.027576235478666,
},
}
var current Location
func main() {
current = Location{
Name: "Amasya",
Lat: 40.65708300559417,
Long: 35.82698609189353,
}
live(current)
}
func live(whereToStart Location) {
if (whereToStart == Location{}) {
panic(":/ u are amazing...")
}
for {
loc := randomLocation(whereToStart)
if isSameLocation(current, loc) {
panic(":/.....")
}
current = loc
fmt.Println(current.Lat)
}
}
func randomLocation(current Location) Location {
if (current == Location{}) {
panic("Where are u?")
}
index := rand.Intn(len(favorites))
pick := favorites[index]
return pick
}
func isSameLocation(from Location, to Location) bool {
if reflect.DeepEqual(from, to) {
return true
}
return false
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment