This commit is contained in:
a.pivkin 2025-07-10 21:09:32 +03:00
parent 2874926fcc
commit 31515dba8d
13 changed files with 176 additions and 0 deletions

17
Lec10/buf/main.go Normal file
View File

@ -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)
}

3
Lec10/go.mod Normal file
View File

@ -0,0 +1,3 @@
module main.go
go 1.24.4

37
Lec10/main.go Normal file
View File

@ -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")
}
}

3
Lec11/go.mod Normal file
View File

@ -0,0 +1,3 @@
module main.go
go 1.24.4

22
Lec11/main.go Normal file
View File

@ -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)
}

3
Lec12/go.mod Normal file
View File

@ -0,0 +1,3 @@
module main.go
go 1.24.4

19
Lec12/main.go Normal file
View File

@ -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)
}

3
Lec9/go.mod Normal file
View File

@ -0,0 +1,3 @@
module main.go
go 1.24.4

20
Lec9/main.go Normal file
View File

@ -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)
}

26
count_arr/main.go Normal file
View File

@ -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))
}

BIN
for_perf/endless Executable file

Binary file not shown.

3
for_perf/go.mod Normal file
View File

@ -0,0 +1,3 @@
module main.go
go 1.24.4

20
for_perf/main.go Normal file
View File

@ -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()
}