Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Learn go basics #150

Open
wants to merge 44 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
0d85e1c
Added solution for 1 and 2
mzhou356 Mar 30, 2023
58bc9f4
Added solution for 03
mzhou356 Mar 30, 2023
f419e0d
Added solution for 04
mzhou356 Mar 30, 2023
aa55f2f
Added solution for 05
mzhou356 Mar 30, 2023
a4d117e
Added solution for 06
mzhou356 Mar 30, 2023
3563ebf
Added solution for 07
mzhou356 Mar 30, 2023
424f190
Added solution for 08
mzhou356 Mar 30, 2023
57a2105
Added solution for 09
mzhou356 Mar 30, 2023
db3e739
Added solution for 10
mzhou356 Mar 30, 2023
50e9f22
Added solutions for type-conversion.
mzhou356 Mar 30, 2023
332bdd8
Added solution for command line args.
mzhou356 Mar 30, 2023
08dc565
updated change in 06 of command line args.
mzhou356 Mar 30, 2023
00576d0
corrected conversion answer
mzhou356 Mar 30, 2023
b080927
Added exercises for strings.
mzhou356 Mar 31, 2023
04a501c
Added iota exercises.
mzhou356 Mar 31, 2023
53d20c5
Added exercises for printf.
mzhou356 Apr 1, 2023
9722bf1
Added solutions for parts of if statements.
mzhou356 Apr 2, 2023
3374618
Added solution for challenge
mzhou356 Apr 3, 2023
8eb871c
Added solution for 05-moving-rating.
mzhou356 Apr 4, 2023
eb23097
added solution for 01-richter-scale
mzhou356 Apr 11, 2023
579deed
Added solution for exercises for switch.
mzhou356 Apr 12, 2023
e2e1831
Added exercises for multiplication table
mzhou356 Apr 13, 2023
1d0520b
Added parts of solutions to exercises for for-loops.
mzhou356 Apr 14, 2023
bfded81
Added exercises for randomization game.
mzhou356 Apr 18, 2023
615c5d1
Added soluiton for labelled statement.
mzhou356 May 1, 2023
6be8b7c
completed moodly challenge.
mzhou356 May 2, 2023
9015a9c
Added solutions for exercise 1 to 7
mzhou356 May 7, 2023
58b0012
completed all exercises for arrays.
mzhou356 May 22, 2023
cc24975
Completed animating clock challenge.
mzhou356 May 22, 2023
966118d
Added simple follow up questions.
mzhou356 May 22, 2023
9977c9a
added exercise solution for go slices.
mzhou356 May 23, 2023
f8cdf56
added exercises for slices.
mzhou356 May 25, 2023
7f7a44c
Added slicing exericses for go.
mzhou356 May 26, 2023
543eefa
Added exercises for slice internals.
mzhou356 May 27, 2023
a4f0964
Added parts of the exercise solutions for advanced slice operation.
mzhou356 May 27, 2023
4887518
completed exercises for advanced slice ops exericses.
mzhou356 May 28, 2023
22e3661
rewrite solution from io utils to os.
mzhou356 May 28, 2023
c1639cf
updated the solution from io/utils to os.
mzhou356 May 28, 2023
0f3046a
changed from util/io -> os and added log.fatal.
mzhou356 May 28, 2023
d5e9090
added solution for sort a file.
mzhou356 May 28, 2023
dcda87e
Added solution for sort a file with ordinal.
mzhou356 May 28, 2023
aee6462
Added solution for print directories.
mzhou356 May 28, 2023
b624780
Added exercises for bouncing ball.
mzhou356 May 29, 2023
27e981c
Added exercises for go runes/string/bytes.
mzhou356 Jun 6, 2023
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
Prev Previous commit
Next Next commit
Added exercises for strings.
Signed-off-by: mindy <minzhou16@gmail.com>
mzhou356 committed Mar 31, 2023
commit b0809277ab0355e65c15d02ff12638595d7ed30e
Original file line number Diff line number Diff line change
@@ -30,7 +30,8 @@ func main() {
// \\ equals to backslash character
// \n equals to newline character

path := "c:\\program files\\duper super\\fun.txt\n" +
"c:\\program files\\really\\funny.png"
path :=
`c:\program files\duper super\fun.txt
c:\program files\really\funny.png`
fmt.Println(path)
}
Original file line number Diff line number Diff line change
@@ -31,14 +31,14 @@ func main() {
// \n equals to newline character
// \" equals to double-quotes character

json := "\n" +
"{\n" +
"\t\"Items\": [{\n" +
"\t\t\"Item\": {\n" +
"\t\t\t\"name\": \"Teddy Bear\"\n" +
"\t\t}\n" +
"\t}]\n" +
"}\n"
json := `
{
"Items": [{
"Item": {
"name": "Teddy Bear"
}
}]
}`

fmt.Println(json)
}
Original file line number Diff line number Diff line change
@@ -8,7 +8,10 @@

package main

import "fmt"
import (
"fmt"
"os"
)

// ---------------------------------------------------------
// EXERCISE: Raw Concat
@@ -34,12 +37,12 @@ import "fmt"

func main() {
// uncomment the code below
// name := "and get the name from the command-line"
name := os.Args[1]

// replace and concatenate the `name` variable
// after `hi ` below

msg := `hi CONCATENATE-NAME-VARIABLE-HERE!
msg := `hi ` + name + `!
how are you?`

fmt.Println(msg)
Original file line number Diff line number Diff line change
@@ -11,6 +11,7 @@ package main
import (
"fmt"
"os"
"unicode/utf8"
)

// ---------------------------------------------------------
@@ -33,6 +34,6 @@ func main() {
//
// When you run it with "İNANÇ", it should return 5 not 7.

length := len(os.Args[1])
length := utf8.RuneCountInString(os.Args[1])
fmt.Println(length)
}
Original file line number Diff line number Diff line change
@@ -12,6 +12,7 @@ import (
"fmt"
"os"
"strings"
"unicode/utf8"
)

// ---------------------------------------------------------
@@ -30,7 +31,7 @@ import (
func main() {
msg := os.Args[1]

s := msg + strings.Repeat("!", len(msg))
s := msg + strings.Repeat("!", utf8.RuneCountInString(msg))

fmt.Println(s)
}
Original file line number Diff line number Diff line change
@@ -8,6 +8,12 @@

package main

import (
"fmt"
"os"
"strings"
)

// ---------------------------------------------------------
// EXERCISE: ToLowercase
//
@@ -28,4 +34,7 @@ package main
// ---------------------------------------------------------

func main() {
first_arg := os.Args[1]

fmt.Println(strings.ToLower(first_arg))
}
Original file line number Diff line number Diff line change
@@ -10,6 +10,7 @@ package main

import (
"fmt"
"strings"
)

// ---------------------------------------------------------
@@ -35,5 +36,5 @@ I should go and play.

`

fmt.Println(msg)
fmt.Println(strings.TrimSpace(msg))
}
Original file line number Diff line number Diff line change
@@ -10,6 +10,8 @@ package main

import (
"fmt"
"strings"
"unicode/utf8"
)

// ---------------------------------------------------------
@@ -33,5 +35,6 @@ func main() {
// it should print 5

name := "inanç "
fmt.Println(len(name))
fmt.Println(utf8.RuneCountInString(strings.TrimRight(name, " ")))

}