diff --git a/chapter_03/exercise_3.01/main.go b/chapter_03/exercise_3.01/main.go new file mode 100644 index 0000000..7d2e8ba --- /dev/null +++ b/chapter_03/exercise_3.01/main.go @@ -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") + } + +} diff --git a/chapter_03/exercise_3.02/main.go b/chapter_03/exercise_3.02/main.go new file mode 100644 index 0000000..f965fe3 --- /dev/null +++ b/chapter_03/exercise_3.02/main.go @@ -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) + +} diff --git a/chapter_03/exercise_3.03/main.go b/chapter_03/exercise_3.03/main.go new file mode 100644 index 0000000..4697ee5 --- /dev/null +++ b/chapter_03/exercise_3.03/main.go @@ -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) + } + +} diff --git a/chapter_03/exercise_3.04/main.go b/chapter_03/exercise_3.04/main.go new file mode 100644 index 0000000..8e2b9fd --- /dev/null +++ b/chapter_03/exercise_3.04/main.go @@ -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) + +}