add: new tictactoe game
add: testing to tictactoe rename: tictactoe add: tictactoe steps refactor: tictactoe const names refactor: tictactoe loop add: tictactoe bad switch example (fallthrough) refactor: tictactoe loop skin remove: tictactoe changable skin refactor: tictactoe all remove: tictactoe unnecessary base dir add: tictactoe slices add: tictactoe slices remove: tictactoe fallthrough rename: tictactoe slices 10 -> 09 update: loops skin tictactoe add: tictactoe randomization add: tictactoe infinite loop and labeled break refactor: tictactoe rand and infinite loop add: tictactoe buggy winning algo add: tictactoe more tests rename: tictactoe wrongPlay to wrongMove add: tictactoe even more tests fix: tictactoe rename: tictactoe waitForInput to wait add: tictactoe os.args gameSpeed remove: tictactoe unnecessary files rename: tictactoe game messages refactor: tictactoe main loop add: types and arrays
This commit is contained in:
51
x-tba/foundations/02-variables/types/main.go
Normal file
51
x-tba/foundations/02-variables/types/main.go
Normal file
@@ -0,0 +1,51 @@
|
||||
// For more tutorials: https://blog.learngoprogramming.com
|
||||
//
|
||||
// Copyright © 2018 Inanc Gumus
|
||||
// Learn Go Programming Course
|
||||
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
|
||||
//
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math"
|
||||
"os"
|
||||
"runtime"
|
||||
"time"
|
||||
)
|
||||
|
||||
func main() {
|
||||
// int, float64, bool, string
|
||||
var (
|
||||
cpus int
|
||||
path, dir string
|
||||
max float64
|
||||
)
|
||||
|
||||
cpus = runtime.NumCPU()
|
||||
path = os.Getenv("PATH")
|
||||
max = math.Max(1.5, 2.5)
|
||||
dir, _ = os.Getwd()
|
||||
now := time.Now()
|
||||
|
||||
// cpus := runtime.NumCPU()
|
||||
// path := os.Getenv("PATH")
|
||||
// max := math.Max(1.5, 2.5)
|
||||
// dir, _ := os.Getwd()
|
||||
|
||||
// dir = `"` + dir + `"`
|
||||
// dir = strconv.Quote(dir)
|
||||
// cpus++
|
||||
// cpus *= 2.5
|
||||
// max++
|
||||
// max /= 2.5
|
||||
// paths = strings.Split(path, ":")
|
||||
// path = paths[0]
|
||||
|
||||
fmt.Printf("# of CPUS : %d\n", cpus)
|
||||
fmt.Printf("Path : %s\n", path)
|
||||
fmt.Printf("max(1.5, 2.5) : %g\n", max)
|
||||
fmt.Printf("Current Directory: %s\n", dir)
|
||||
fmt.Printf("Current Time : %s\n", now)
|
||||
}
|
@@ -36,12 +36,12 @@ main:
|
||||
|
||||
switch {
|
||||
// prime
|
||||
case n == 2 || n == 3:
|
||||
case n == 2, n == 3:
|
||||
fmt.Print(n, " ")
|
||||
continue
|
||||
|
||||
// not a prime
|
||||
case n <= 1 || n%2 == 0 || n%3 == 0:
|
||||
case n <= 1, n%2 == 0, n%3 == 0:
|
||||
continue
|
||||
}
|
||||
|
||||
|
@@ -1,3 +1,10 @@
|
||||
// For more tutorials: https://blog.learngoprogramming.com
|
||||
//
|
||||
// Copyright © 2018 Inanc Gumus
|
||||
// Learn Go Programming Course
|
||||
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
|
||||
//
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
@@ -7,6 +14,26 @@ import (
|
||||
)
|
||||
|
||||
func main() {
|
||||
// 1.
|
||||
// var a int
|
||||
// var b int
|
||||
|
||||
// 2.
|
||||
// var (
|
||||
// a int
|
||||
// b int
|
||||
// )
|
||||
|
||||
// 3.
|
||||
// var a, b int
|
||||
|
||||
// 1.
|
||||
// fmt.Println(a, "+", b, "=", a+b)
|
||||
|
||||
// 2.
|
||||
// fmt.Printf("%v + %v = %v\n", a, b, a+b)
|
||||
|
||||
// ----
|
||||
// lesson: multi-return funcs, %v, and _
|
||||
|
||||
a, _ := strconv.Atoi(os.Args[1])
|
||||
|
@@ -7,7 +7,7 @@ import (
|
||||
)
|
||||
|
||||
func main() {
|
||||
// lesson: floats encompass integers too
|
||||
// lesson: len(), floats encompass integers too
|
||||
|
||||
if len(os.Args) != 3 {
|
||||
fmt.Println("Usage: calc <number1> <number2>")
|
||||
|
@@ -26,5 +26,12 @@ func main() {
|
||||
return
|
||||
}
|
||||
|
||||
// err1 := ...
|
||||
// err2 := ...
|
||||
// if err1 != nil || err2 != nil {
|
||||
// fmt.Println("Please provide a valid number")
|
||||
// return
|
||||
// }
|
||||
|
||||
fmt.Printf("%v + %v = %v\n", a, b, a+b)
|
||||
}
|
||||
|
@@ -26,7 +26,9 @@ func main() {
|
||||
return
|
||||
}
|
||||
|
||||
// multiple declare
|
||||
var (
|
||||
// declare & assign
|
||||
op = os.Args[2]
|
||||
res float64
|
||||
)
|
||||
|
70
x-tba/foundations/lookup/main.go
Normal file
70
x-tba/foundations/lookup/main.go
Normal file
@@ -0,0 +1,70 @@
|
||||
// For more tutorials: https://blog.learngoprogramming.com
|
||||
//
|
||||
// Copyright © 2018 Inanc Gumus
|
||||
// Learn Go Programming Course
|
||||
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
|
||||
//
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const (
|
||||
missingHost = "Please provide at least one domain. --help for more information."
|
||||
|
||||
help = `
|
||||
Host to IP Lookup:
|
||||
------------------
|
||||
|
||||
It finds the ip addresses of the given hosts. You can provide hosts by separating them with spaces.
|
||||
|
||||
Example:
|
||||
|
||||
host google.com
|
||||
host google.com uber.com`
|
||||
)
|
||||
|
||||
func main() {
|
||||
// url := "google.com"
|
||||
var message string
|
||||
|
||||
args := os.Args
|
||||
switch l := len(args); {
|
||||
// case len(args) == 1:
|
||||
case l == 1:
|
||||
message = missingHost
|
||||
case l == 2 && args[1] == "--help":
|
||||
message = strings.TrimSpace(help)
|
||||
}
|
||||
|
||||
if message != "" {
|
||||
fmt.Println(message)
|
||||
return
|
||||
}
|
||||
|
||||
// for i := 0; i < len(args); i++ {}
|
||||
// for i, url := range args {
|
||||
for _, url := range args[1:] {
|
||||
// if i == 0 {
|
||||
// continue
|
||||
// }
|
||||
|
||||
ips, err := net.LookupIP(url)
|
||||
if err != nil {
|
||||
fmt.Printf("%-20s => %s\n", url, err)
|
||||
// break
|
||||
continue
|
||||
}
|
||||
|
||||
for _, ip := range ips {
|
||||
if ip = ip.To4(); ip != nil {
|
||||
fmt.Printf("%-20s => %s\n", url, ip)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user