Browse Source

Add first code of chapter 03

master
T. Meissner 5 years ago
parent
commit
0a22da2218
4 changed files with 112 additions and 0 deletions
  1. +56
    -0
      chapter_03/exercise_3.01/main.go
  2. +19
    -0
      chapter_03/exercise_3.02/main.go
  3. +16
    -0
      chapter_03/exercise_3.03/main.go
  4. +21
    -0
      chapter_03/exercise_3.04/main.go

+ 56
- 0
chapter_03/exercise_3.01/main.go View File

@ -0,0 +1,56 @@
package main
import (
"fmt"
"unicode"
)
func passwordChecker(pw string) bool {
pwR := []rune(pw)
if len(pwR) < 8 || len(pwR) > 15 {
return false
}
hasUpper := false
hasLower := false
hasNumber := false
hasSymbol := false
for _, v := range pwR {
if unicode.IsUpper(v) {
hasUpper = true
}
if unicode.IsLower(v) {
hasLower = true
}
if unicode.IsNumber(v) {
hasNumber = true
}
if unicode.IsPunct(v) || unicode.IsSymbol(v) {
hasSymbol = true
}
}
return hasUpper && hasLower && hasNumber && hasSymbol
}
func main() {
if passwordChecker("") {
fmt.Println("Password good")
} else {
fmt.Println("Password bad")
}
if passwordChecker("This!I5A") {
fmt.Println("Password good")
} else {
fmt.Println("Password bad")
}
}

+ 19
- 0
chapter_03/exercise_3.02/main.go View File

@ -0,0 +1,19 @@
package main
import "fmt"
func main() {
var a int = 100
var b float32 = 100
var c float64 = 100
fmt.Println(a / 3)
fmt.Println(b / 3)
fmt.Println(c / 3)
fmt.Println((a / 3) * 3)
fmt.Println((b / 3) * 3)
fmt.Println((c / 3) * 3)
}

+ 16
- 0
chapter_03/exercise_3.03/main.go View File

@ -0,0 +1,16 @@
package main
import "fmt"
func main() {
var a int8 = 125
var b uint8 = 253
for i := 0; i < 5; i++ {
a++
b++
fmt.Println(i, ")", "int8:", a, "uint8:", b)
}
}

+ 21
- 0
chapter_03/exercise_3.04/main.go View File

@ -0,0 +1,21 @@
package main
import (
"fmt"
"math"
"math/big"
)
func main() {
intA := math.MaxInt64
intA++
bigA := big.NewInt(math.MaxInt64)
bigA.Add(bigA, big.NewInt(1))
fmt.Println("MaxInt64:", math.MaxInt64)
fmt.Println("Int: ", intA)
fmt.Println("Big Int: ", bigA)
}

Loading…
Cancel
Save