kk
This commit is contained in:
@@ -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)
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
module main.go
|
||||
|
||||
go 1.24.4
|
||||
@@ -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")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
module main.go
|
||||
|
||||
go 1.24.4
|
||||
@@ -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)
|
||||
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
module main.go
|
||||
|
||||
go 1.24.4
|
||||
@@ -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)
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
module main.go
|
||||
|
||||
go 1.24.4
|
||||
@@ -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}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
module main.go
|
||||
|
||||
go 1.24.4
|
||||
@@ -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")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
module main.go
|
||||
|
||||
go 1.24.4
|
||||
@@ -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
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
module main.go
|
||||
|
||||
go 1.24.4
|
||||
@@ -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
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
module main.go
|
||||
|
||||
go 1.24.4
|
||||
@@ -0,0 +1,3 @@
|
||||
package main
|
||||
|
||||
func main() { }
|
||||
@@ -0,0 +1,3 @@
|
||||
module main.go
|
||||
|
||||
go 1.24.4
|
||||
@@ -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())
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
module main.go
|
||||
|
||||
go 1.24.4
|
||||
@@ -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()
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
module main.go
|
||||
|
||||
go 1.24.4
|
||||
@@ -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)
|
||||
}
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
package main
|
||||
|
||||
func add(a,b int) int {
|
||||
return a + b
|
||||
}
|
||||
|
||||
func Sub(a,b int) int {
|
||||
return a - b
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
module Lec20
|
||||
|
||||
go 1.24.4
|
||||
@@ -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())
|
||||
}
|
||||
@@ -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)
|
||||
}
|
||||
@@ -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)
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
module main.go
|
||||
|
||||
go 1.24.4
|
||||
@@ -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))
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
module main.go
|
||||
|
||||
go 1.24.4
|
||||
@@ -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")
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
module main.go
|
||||
|
||||
go 1.24.4
|
||||
@@ -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++
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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))
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
module main.go
|
||||
|
||||
go 1.24.4
|
||||
@@ -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)
|
||||
}
|
||||
Executable
BIN
Binary file not shown.
Executable
BIN
Binary file not shown.
@@ -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))
|
||||
}
|
||||
Executable
BIN
Binary file not shown.
@@ -0,0 +1,3 @@
|
||||
module main.go
|
||||
|
||||
go 1.24.4
|
||||
@@ -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()
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
module main.go
|
||||
|
||||
go 1.24.4
|
||||
Vendored
Reference in New Issue
Block a user