This commit is contained in:
a.pivkin
2025-07-16 08:15:26 +03:00
parent cebbf27b3a
commit 0635aaa5ae
53 changed files with 76 additions and 4 deletions
+17
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
View File
@@ -0,0 +1,3 @@
module main.go
go 1.24.4
+37
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
View File
@@ -0,0 +1,3 @@
module main.go
go 1.24.4
+22
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
View File
@@ -0,0 +1,3 @@
module main.go
go 1.24.4
+19
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
View File
@@ -0,0 +1,3 @@
module main.go
go 1.24.4
+18
View File
@@ -0,0 +1,18 @@
package main
import "fmt"
func main() {
command := "addition"
res := retFunc(command)
fmt.Println("Result is ",res(10,30))
fmt.Println("Type is %T",res)
}
func retFunc (a string) func(a,b int) int {
if a == "addition" {
return func(a,b int) int {return a + b}
} else {
return func(a,b int) int {return a - b}
}
}
+3
View File
@@ -0,0 +1,3 @@
module main.go
go 1.24.4
+27
View File
@@ -0,0 +1,27 @@
package main
import (
"fmt"
"strconv"
)
const (
A = 10
B = 11
)
func main() {
var constInt8 int8 = A
var constString string = strconv.Itoa(A)
fmt.Println("constInt8 is ",constInt8)
fmt.Println("constString is ",constString)
}
func checkConst() {
if A == 10 {
fmt.Printf("a is 10\n")
}
}
+3
View File
@@ -0,0 +1,3 @@
module main.go
go 1.24.4
+41
View File
@@ -0,0 +1,41 @@
package main
import "fmt"
func main() {
// var variable int = 30
// var pointer *int = &variable
// fmt.Printf("Type of pointer %T\n",pointer)
// fmt.Printf("Value of pointer %v\n",pointer)
// secondPtr := &pointer
// fmt.Println("Pointer to pointer",secondPtr)
// zeroPtr := new(int)
// *zeroPtr += 40
// fmt.Println("Address is ",*zeroPtr)
// a := 10
// c := a
// b := &a
// *b += 2
// c++
// fmt.Printf("Val of A is %d and val of C is %d\n",a, c)
// fmt.Printf("Val of A after changing ref is %d",a)
sample := 1
// samplePtr := &sample
fmt.Println("Sample val is",sample)
kek(sample)
fmt.Println("Sample val is",sample)
}
func kek(val int) {
fmt.Println("Val of val is",val)
val += 100
}
+3
View File
@@ -0,0 +1,3 @@
module main.go
go 1.24.4
+15
View File
@@ -0,0 +1,15 @@
package main
import "fmt"
func main() {
arr := [3]int{1,2,3}
fmt.Println("Initial array is ", arr)
mutation(&arr)
fmt.Println("Modified array is ", arr)
}
func mutation(arr *[3]int) {
(*arr)[0] = 900
(*arr)[2] = 1000
}
+3
View File
@@ -0,0 +1,3 @@
module main.go
go 1.24.4
+3
View File
@@ -0,0 +1,3 @@
package main
func main() { }
+3
View File
@@ -0,0 +1,3 @@
module main.go
go 1.24.4
+26
View File
@@ -0,0 +1,26 @@
package main
import (
"fmt"
"math"
)
type Cicle struct {
radius int
}
type Rectangle struct {
lenght,width int
}
func (circle Cicle) Perim() float64 {
return float64(circle.radius) * math.Pi
}
func main() {
c := Cicle{
radius: 3,
}
fmt.Println(c.Perim())
}
+3
View File
@@ -0,0 +1,3 @@
module main.go
go 1.24.4
+27
View File
@@ -0,0 +1,27 @@
package main
import "fmt"
type Employee struct {
name string
position string
salary int
currency string
}
func (e Employee) DisplayInfo() {
fmt.Println("Name: ", e.name)
fmt.Println("Position: ",e.position)
fmt.Printf("Salary: %d %s\n",e.salary,e.currency)
}
func main(){
emp := Employee {
name: "Bob",
position: "senior",
salary: 10000,
currency: "RUB",
}
emp.DisplayInfo()
}
+3
View File
@@ -0,0 +1,3 @@
module main.go
go 1.24.4
+37
View File
@@ -0,0 +1,37 @@
package main
import "fmt"
type Student struct {
name string
age int
}
type Desriber interface {
Describe()
}
func (std Student) Describe(){
fmt.Printf("%s and %d y.o",std.name,std.age)
}
func TypeDescriber(i interface{}){
switch v := i.(type){
case string:
fmt.Println("I am string")
case int:
fmt.Println("I am int")
case Desriber:
fmt.Println("I am describer!")
v.Describe()
default:
fmt.Println("Unknown type but I still work!")
}
}
func main() {
TypeDescriber(9)
std := Student{"Alex", 19}
TypeDescriber(std)
}
+16
View File
@@ -0,0 +1,16 @@
package main
import "fmt"
func main() {
var (
word1,word2,word3,word4 string = "имя","твоё","мне","знакомо"
// word2 string = "твоё"
// word3 string = "мне"
// word4 string = "знакомо"
)
fmt.Println(word4,word3,word2,word1)
fmt.Println(word3,word1,word4,word2)
fmt.Println(word2,word4,word3,word1)
}
+9
View File
@@ -0,0 +1,9 @@
package main
func add(a,b int) int {
return a + b
}
func Sub(a,b int) int {
return a - b
}
+3
View File
@@ -0,0 +1,3 @@
module Lec20
go 1.24.4
+14
View File
@@ -0,0 +1,14 @@
package main
import (
"Lec20/rectangle"
"fmt"
)
func main() {
// res := add(2,5)
// fmt.Println("Addition equals to ",res)
r := rectangle.New(10, 20, "green")
fmt.Println("Perimeter: ", r.Perimeter())
}
+14
View File
@@ -0,0 +1,14 @@
package rectangle
type Rect struct {
A,B int
color string
}
func New(newA int, newB int, newColor string) *Rect {
return &Rect{newA,newB,newColor}
}
func (r *Rect) Perimeter() int {
return 2 * (r.A + r.B)
}
+14
View File
@@ -0,0 +1,14 @@
package main
import "fmt"
func main() {
var (
age int
name string
)
fmt.Scan(&age, &name)
fmt.Printf("Name is %s, Age is %d",name,age)
}
+3
View File
@@ -0,0 +1,3 @@
module main.go
go 1.24.4
+15
View File
@@ -0,0 +1,15 @@
package main
import (
"fmt"
"unicode/utf8"
"unsafe"
)
func main() {
var kek string = "Федя"
fmt.Printf("Length of %s is: %d\n",kek,len(kek))
fmt.Printf("Length in chars: %d\n",utf8.RuneCountInString(kek))
fmt.Printf("Type %T size of %d bytes\n",kek,unsafe.Sizeof(kek))
}
+3
View File
@@ -0,0 +1,3 @@
module main.go
go 1.24.4
+17
View File
@@ -0,0 +1,17 @@
package main
import (
"fmt"
"strings"
)
func main() {
var word1 string
fmt.Scan(&word1)
if strings.Contains(word1,"чат") {
fmt.Println("THIS IS BOT")
return
}
fmt.Println("This is not a bot")
}
+3
View File
@@ -0,0 +1,3 @@
module main.go
go 1.24.4
+13
View File
@@ -0,0 +1,13 @@
package main
import "fmt"
func main() {
var loop_var int = 10
for loop_var <= 20 {
fmt.Printf("Current is %d\n",loop_var)
loop_var++
}
}
+8
View File
@@ -0,0 +1,8 @@
package main
import "fmt"
func main() {
arr := [...]int{10,20,30,40}
fmt.Println("Arr with [...]: ",arr, "Length is: ", len(arr))
}
+3
View File
@@ -0,0 +1,3 @@
module main.go
go 1.24.4
+20
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)
}
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
+26
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
View File
Binary file not shown.
+3
View File
@@ -0,0 +1,3 @@
module main.go
go 1.24.4
+20
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()
}
+3
View File
@@ -0,0 +1,3 @@
module main.go
go 1.24.4
View File