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 soluiton for labelled statement.
Signed-off-by: mindy <[email protected]>
mzhou356 committed May 1, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 615c5d121e5b273918668a8a275a291e3baf5105
Original file line number Diff line number Diff line change
@@ -8,6 +8,12 @@

package main

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

// ---------------------------------------------------------
// EXERCISE: Case Insensitive Search
//
@@ -24,5 +30,29 @@ package main
// the "lazy" keyword.
// ---------------------------------------------------------

const corpus = "lazy cat jumps again and again and again"

func main() {
if len(os.Args) < 2 {
fmt.Println("It needs a keyword input.")
return
}
queries := os.Args[1:]

scan:
for _, query := range queries {
query = strings.ToLower(query)
check:
for i, word := range strings.Fields(corpus) {
switch word {
case "and", "or", "the":
break check
}
if query == word {
fmt.Printf("#%-2d: %q\n", i+1, word)
continue scan
}
}
}

}
Original file line number Diff line number Diff line change
@@ -8,6 +8,13 @@

package main

import (
"fmt"
"os"
"path/filepath"
"strings"
)

// ---------------------------------------------------------
// EXERCISE: Path Searcher
//
@@ -80,4 +87,24 @@ package main
// ---------------------------------------------------------

func main() {
corpus, okay := os.LookupEnv("Path")
if okay == false {
fmt.Println("No value set for Path or PATH.")
return
}

words := filepath.SplitList(corpus)

searches := os.Args[1:]

for _, search := range searches {
search = strings.ToLower(search)
for i, word := range words {
if strings.Contains(strings.ToLower(word), search) {
fmt.Printf("#%-2d: %q\n", i+1, word)
}
}

}

}
42 changes: 42 additions & 0 deletions 13-loops/exercises/10-crunch-the-primes/main.go
Original file line number Diff line number Diff line change
@@ -8,6 +8,12 @@

package main

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

// ---------------------------------------------------------
// EXERCISE: Crunch the primes
//
@@ -33,5 +39,41 @@ package main
// 2 3 5 7
// ---------------------------------------------------------

func isprime(x int) bool {
switch x {
case 2, 3:
return true
}
if x%2 == 0 || x%3 == 0 {
return false
}
i := 5
w := 2

for i*i <= x {
if x%i == 0 {
return false
}

i += w
w = 6 - w
}
return true

}

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

for _, number := range numbers {
number, err := strconv.Atoi(number)
if err != nil {
continue
}
if isprime(number) {
fmt.Printf("%d ", number)
}
}
fmt.Println()

}