Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
2c3a24a
Fix #34 - https://tour.golang.org/moretypes/1
AlMishbah Feb 8, 2020
ca01dcd
Fix #34 - https://tour.golang.org/moretypes/2
AlMishbah Feb 8, 2020
ae68c37
Fix #34 - https://tour.golang.org/moretypes/3
AlMishbah Feb 8, 2020
66322a3
Fix #34 - https://tour.golang.org/moretypes/4
AlMishbah Feb 8, 2020
a5dc656
Fix #34 - https://tour.golang.org/moretypes/5
AlMishbah Feb 8, 2020
12905ba
Fix #34 - https://tour.golang.org/moretypes/6
AlMishbah Feb 8, 2020
85a79ba
Fix #34 - https://tour.golang.org/moretypes/7
AlMishbah Feb 8, 2020
2d21fc4
Fix #34 - https://tour.golang.org/moretypes/8
AlMishbah Feb 8, 2020
1526cd5
Fix #34 - https://tour.golang.org/moretypes/9
AlMishbah Feb 8, 2020
d2cb8b2
Fix #34 - https://tour.golang.org/moretypes/10
AlMishbah Feb 8, 2020
7045a61
Fix #34 - https://tour.golang.org/moretypes/11
AlMishbah Feb 10, 2020
3824c13
Fix #34 - https://tour.golang.org/moretypes/12
AlMishbah Feb 10, 2020
12465cb
Fix #34 - https://tour.golang.org/moretypes/13
AlMishbah Feb 10, 2020
137feb3
Fix #34 - https://tour.golang.org/moretypes/14
AlMishbah Feb 10, 2020
a9b909a
Fix #34 - https://tour.golang.org/moretypes/15
AlMishbah Feb 10, 2020
4d26335
Fix #34 - https://tour.golang.org/moretypes/16
AlMishbah Feb 10, 2020
8f0f2dd
Fix #34 - https://tour.golang.org/moretypes/17
AlMishbah Feb 10, 2020
b022bf1
Fix #34 - https://tour.golang.org/moretypes/18
AlMishbah Feb 10, 2020
a76fcdd
Fix #34 - https://tour.golang.org/moretypes/19
AlMishbah Feb 10, 2020
0a5e305
Fix #34 - https://tour.golang.org/moretypes/20
AlMishbah Feb 10, 2020
8d93cd7
Fix #34 - https://tour.golang.org/moretypes/21
AlMishbah Feb 10, 2020
033e8b3
Fix #34 - https://tour.golang.org/moretypes/22
AlMishbah Feb 10, 2020
54aa24e
Fix #34 - https://tour.golang.org/moretypes/24
AlMishbah Feb 10, 2020
c62f2cf
Fix #34 - https://tour.golang.org/moretypes/23
AlMishbah Feb 10, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions roihan/flowcontrol_14.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ import "fmt"

func flowcontrol14() {
fmt.Println("You finished this lesson!")
fmt.Println()
}
16 changes: 16 additions & 0 deletions roihan/moretypes_1.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package roihan

import "fmt"

func moretype1() {
i, j := 42, 2701

p := &i
fmt.Println(*p)
*p = 21
fmt.Println(i)

p = &j
*p = *p / 37
fmt.Println(j)
}
16 changes: 16 additions & 0 deletions roihan/moretypes_10.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package roihan

import "fmt"

func moretype10() {
s := []int{2, 3, 5, 7, 11, 13}

s = s[1:4]
fmt.Println(s)

s = s[:2]
fmt.Println(s)

s = s[1:]
fmt.Println(s)
}
21 changes: 21 additions & 0 deletions roihan/moretypes_11.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package roihan

import "fmt"

func moretype11() {
s := []int{2, 3, 5, 7, 11, 13}
printSlice(s)

s = s[:0]
printSlice(s)

s = s[:4]
printSlice(s)

s = s[2:]
printSlice(s)
}

func printSlice(s []int) {
fmt.Printf("len=%d cap=%d %v\n", len(s), cap(s), s)
}
11 changes: 11 additions & 0 deletions roihan/moretypes_12.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package roihan

import "fmt"

func moretype12() {
var s []int
fmt.Println(s, len(s), cap(s))
if s == nil {
fmt.Println("nil!")
}
}
21 changes: 21 additions & 0 deletions roihan/moretypes_13.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package roihan

import "fmt"

func moretype13() {
a := make([]int, 5)
PrintSlice("a", a)

b := make([]int, 0, 5)
PrintSlice("b", b)

c := b[:2]
PrintSlice("c", c)

d := c[2:5]
PrintSlice("d", d)
}

func PrintSlice(s string, x []int) {
fmt.Printf("%s len=%d cap=%d %v\n", s, len(x), cap(x), x)
}
24 changes: 24 additions & 0 deletions roihan/moretypes_14.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package roihan

import (
"fmt"
"strings"
)

func moretype14() {
board := [][]string{
[]string{"_", "_", "_"},
[]string{"_", "_", "_"},
[]string{"_", "_", "_"},
}

board[0][0] = "X"
board[2][2] = "O"
board[1][2] = "X"
board[1][0] = "O"
board[0][2] = "X"

for i := 0; i < len(board); i++ {
fmt.Printf("%s\n", strings.Join(board[i], ""))
}
}
21 changes: 21 additions & 0 deletions roihan/moretypes_15.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package roihan

import "fmt"

func moretype15() {
var s []int
Printslice(s)

s = append(s, 0)
Printslice(s)

s = append(s, 1)
Printslice(s)

s = append(s, 2, 3, 4)
Printslice(s)
}

func Printslice(s []int) {
fmt.Printf("len=%d cap=%d %v\n", len(s), cap(s), s)
}
11 changes: 11 additions & 0 deletions roihan/moretypes_16.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package roihan

import "fmt"

var pos = []int{1, 2, 4, 8, 16, 32, 64, 128}

func moretype16() {
for i, v := range pos {
fmt.Printf("2**%d = %d\n", i, v)
}
}
13 changes: 13 additions & 0 deletions roihan/moretypes_17.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package roihan

import "fmt"

func moretype17() {
por := make([]int, 10)
for i := range por {
por[i] = 1 << uint(i)
}
for _, value := range por {
fmt.Printf("%d\n", value)
}
}
17 changes: 17 additions & 0 deletions roihan/moretypes_19.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package roihan

import "fmt"

type vertex struct {
Lat, Long float64
}

var m map[string]vertex

func moretype19() {
m = make(map[string]vertex)
m["Bell Labs"] = vertex{
40.648433, -74.39967,
}
fmt.Println(m["Bell Labs"])
}
12 changes: 12 additions & 0 deletions roihan/moretypes_2.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package roihan

import "fmt"

type Vertex struct {
X int
Y int
}

func moretype2() {
fmt.Println(Vertex{1, 20})
}
20 changes: 20 additions & 0 deletions roihan/moretypes_20.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package roihan

import "fmt"

type Verte struct {
Lat, Long float64
}

var ma = map[string]Verte{
"Bell Labs": Verte{
40.648433, -74.39967,
},
"Google": Verte{
37.42202, -122.08408,
},
}

func moretype20() {
fmt.Println(ma)
}
16 changes: 16 additions & 0 deletions roihan/moretypes_21.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package roihan

import "fmt"

type literals struct {
Lat, Long float64
}

var mp = map[string]literals{
"Bell Labs": {40.68433, -74.39967},
"Google": {37.42202, -122.08408},
}

func moretype21() {
fmt.Println(mp)
}
19 changes: 19 additions & 0 deletions roihan/moretypes_22.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package roihan

import "fmt"

func moretype22() {
m := make(map[string]int)

m["Answer"] = 42
fmt.Println("The value:", m["Answer"])

m["Answer"] = 48
fmt.Println("The value:", m["Answer"])

delete(m, "Answer")
fmt.Println("The value:", m["Answer"])

v, ok := m["Answer"]
fmt.Println("The value:", v, "Present?", ok)
}
11 changes: 11 additions & 0 deletions roihan/moretypes_23.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package roihan

import "golang.org/x/tour/wc"

func WordCount(s string) map[string]int {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ini logic.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return map[string]int{"x": 1}
}

func moretype23() {
wc.Test(WordCount)
}
20 changes: 20 additions & 0 deletions roihan/moretypes_24.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package roihan

import (
"fmt"
"math"
)

func compute(fn func(float64, float64) float64) float64 {
return fn(3, 4)
}

func moretype24() {
hypot := func(x, y float64) float64 {
return math.Sqrt(x*x + y*y)
}
fmt.Println(hypot(5, 12))

fmt.Println(compute(hypot))
fmt.Println(compute(math.Pow))
}
14 changes: 14 additions & 0 deletions roihan/moretypes_3.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package roihan

import "fmt"

type moretype struct {
X int
Y int
}

func moretype3() {
v := Vertex{1, 2}
v.X = 4
fmt.Println(v.X)
}
15 changes: 15 additions & 0 deletions roihan/moretypes_4.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package roihan

import "fmt"

type Moretype struct {
X int
Y int
}

func moretype4() {
v := Moretype{1, 2}
p := &v
p.X = 1e9
fmt.Println(v)
}
18 changes: 18 additions & 0 deletions roihan/moretypes_5.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package roihan

import "fmt"

type MoretypeVertex struct {
X, Y int
}

var (
v1 = MoretypeVertex{1, 2} //Has type vertex
v2 = MoretypeVertex{X: 1} //Y:0 is implicit
v3 = MoretypeVertex{} //X:0 and Y:0
p = &MoretypeVertex{1, 2} //Has type *Vertex
)

func moretype5() {
fmt.Println(v1, p, v2, v3)
}
14 changes: 14 additions & 0 deletions roihan/moretypes_6.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package roihan

import "fmt"

func moretype6() {
var a [2]string
a[0] = "Hello"
a[1] = "World"
fmt.Println(a[0], a[1])
fmt.Println(a)

primes := [6]int{2, 3, 5, 11, 13}
fmt.Println(primes)
}
10 changes: 10 additions & 0 deletions roihan/moretypes_7.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package roihan

import "fmt"

func moretype7() {
primes := [6]int{2, 3, 5, 7, 11, 13}

var s []int = primes[1:4]
fmt.Println(s)
}
21 changes: 21 additions & 0 deletions roihan/moretypes_8.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package roihan

import "fmt"

func moretype8() {
names := [3]string{
"Roihan",
"Mishbahul",
"Anam",
}

fmt.Println(names)

a := names[0:2]
b := names[1:3]
fmt.Println(a, b)

b[0] = "XXX"
fmt.Println(a, b)
fmt.Println(names)
}
Loading