diff --git a/Lec10/buf/main.go b/Lec10/buf/main.go new file mode 100644 index 0000000..d1531be --- /dev/null +++ b/Lec10/buf/main.go @@ -0,0 +1,17 @@ +package main + +import ( + "bufio" + "fmt" + "os" +) + +func main() { + var name string + input := bufio.NewScanner(os.Stdin) + if input.Scan() { //Capture input and save into buffer. Captures until \n + name = input.Text() + } + + fmt.Println(name) +} diff --git a/Lec10/go.mod b/Lec10/go.mod new file mode 100644 index 0000000..a692304 --- /dev/null +++ b/Lec10/go.mod @@ -0,0 +1,3 @@ +module main.go + +go 1.24.4 diff --git a/Lec10/main.go b/Lec10/main.go new file mode 100644 index 0000000..b4ef496 --- /dev/null +++ b/Lec10/main.go @@ -0,0 +1,37 @@ +package main + +import "fmt" + +func main() { + name := "Привет" + fmt.Printf("String is %s\n",name) + + fmt.Printf("Runes: ") + for i:=0; i < len(name); i++ { + fmt.Printf("%x ", name[i]) + } + fmt.Println() + + fmt.Printf("Bytes: ") + for i:=0; i < len(name); i++ { + fmt.Printf("%c ", name[i]) + } + + fmt.Println("RUnes") + + runeSlice := []rune(name) + fmt.Printf("Runes: ") + for i:=0; i < len(runeSlice); i++ { + fmt.Printf("%c ", runeSlice[i]) + } + fmt.Println("Bytes to runes") + for id,runeVal := range name { + fmt.Printf("%c start at position %d\n", runeVal, id) + } + + word1 := "Vasya" + word2 := "Petya" + if word1 != word2 { + fmt.Println("Not equal") + } +} diff --git a/Lec11/go.mod b/Lec11/go.mod new file mode 100644 index 0000000..a692304 --- /dev/null +++ b/Lec11/go.mod @@ -0,0 +1,3 @@ +module main.go + +go 1.24.4 diff --git a/Lec11/main.go b/Lec11/main.go new file mode 100644 index 0000000..40d4be3 --- /dev/null +++ b/Lec11/main.go @@ -0,0 +1,22 @@ +package main + +import "fmt" + +func main() { + mapper := make(map[string]int) + fmt.Println("Empty map: ",mapper) + + mapper["Alice"] = 24 + mapper["Bob"] = 14 + + fmt.Println("After updating mapper: ", mapper) + + Mapper := map[string]int{ + "Alice": 1000, + "Bob": 50, + } + Mapper["Jo"] = 3000 + + fmt.Println("Initialized map: ",Mapper) + +} diff --git a/Lec12/go.mod b/Lec12/go.mod new file mode 100644 index 0000000..a692304 --- /dev/null +++ b/Lec12/go.mod @@ -0,0 +1,3 @@ +module main.go + +go 1.24.4 diff --git a/Lec12/main.go b/Lec12/main.go new file mode 100644 index 0000000..c589002 --- /dev/null +++ b/Lec12/main.go @@ -0,0 +1,19 @@ +package main + +import "fmt" + +func main() { + words("lol","kek","azaza") + wordSlice := []string{"буль","пук","ам"} + words(wordSlice...) +} + +// Именованный возврат значений +func words(wordd...string) { + var result string + for _, val := range wordd { + result += val + result += " " + } + fmt.Println(result) +} \ No newline at end of file diff --git a/Lec9/go.mod b/Lec9/go.mod new file mode 100644 index 0000000..a692304 --- /dev/null +++ b/Lec9/go.mod @@ -0,0 +1,3 @@ +module main.go + +go 1.24.4 diff --git a/Lec9/main.go b/Lec9/main.go new file mode 100644 index 0000000..1ad6ff8 --- /dev/null +++ b/Lec9/main.go @@ -0,0 +1,20 @@ +package main + +import "fmt" + +func main() { + myWords := make([]string,0,20) + myWords = append(myWords, "one","two","three") + fmt.Println(myWords) + anotherWords := []string{"1","2","3"} + myWords = append(myWords, anotherWords...) + fmt.Println(myWords) + + mSlice := [][]int{ + {1,2,3}, + {2,3}, + {1,1,1}, + {2,2}, + } + fmt.Println(mSlice) +} diff --git a/count_arr/main.go b/count_arr/main.go new file mode 100644 index 0000000..25d82d4 --- /dev/null +++ b/count_arr/main.go @@ -0,0 +1,26 @@ +package main + +import "fmt" + +func main() { + +initArr := []int{1,2,3,4,1,1,4,2,5} +fmt.Println(initArr) + +CountStrg := make(map[int]int) + +for _,val := range initArr { + // fmt.Printf("Key is %d and val is %d\n",key, val) + if _,ok := CountStrg[val]; !ok { + CountStrg[val] = 1 + continue + } + CountStrg[val]++ +} +fmt.Println(CountStrg) +fmt.Print("==========================\n") +fmt.Println("Len of slice is: ",len(initArr)," and capacity is ",cap(initArr)) +initArr = append(initArr, 10) +fmt.Print("==========================\n") +fmt.Println("New len of slice is: ",len(initArr)," and new capacity is ",cap(initArr)) +} \ No newline at end of file diff --git a/for_perf/endless b/for_perf/endless new file mode 100755 index 0000000..13e92af Binary files /dev/null and b/for_perf/endless differ diff --git a/for_perf/go.mod b/for_perf/go.mod new file mode 100644 index 0000000..a692304 --- /dev/null +++ b/for_perf/go.mod @@ -0,0 +1,3 @@ +module main.go + +go 1.24.4 diff --git a/for_perf/main.go b/for_perf/main.go new file mode 100644 index 0000000..103ecdd --- /dev/null +++ b/for_perf/main.go @@ -0,0 +1,20 @@ +package main + +import ( + "fmt" + "time" +) + +func busyWork() { + for { + for i := 0; i < 1_000_000; i++ { + _ = i * i + } + fmt.Println("Working...") + time.Sleep(100 * time.Millisecond) + } +} + +func main() { + busyWork() +}