-
Notifications
You must be signed in to change notification settings - Fork 458
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implementing the main.go files at the same level as the readme for th…
…e exercise
- Loading branch information
Showing
38 changed files
with
534 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
) | ||
|
||
func main() { | ||
root := &TreeNode{Data: "4"} | ||
BTreeInsertData(root, "1") | ||
BTreeInsertData(root, "7") | ||
BTreeInsertData(root, "5") | ||
node := BTreeSearchItem(root, "4") | ||
fmt.Println("Before delete:") | ||
BTreeApplyInorder(root, fmt.Println) | ||
root = BTreeDeleteNode(root, node) | ||
fmt.Println("After delete:") | ||
BTreeApplyInorder(root, fmt.Println) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
) | ||
|
||
func main() { | ||
fmt.Println(ByeByeFirst([]string{})) | ||
fmt.Println(ByeByeFirst([]string{"one arg"})) | ||
fmt.Println(ByeByeFirst([]string{"first", "second"})) | ||
fmt.Println(ByeByeFirst([]string{"", "abcd", "efg"})) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
) | ||
|
||
func main() { | ||
fmt.Println(CamelToSnakeCase("HelloWorld")) | ||
fmt.Println(CamelToSnakeCase("helloWorld")) | ||
fmt.Println(CamelToSnakeCase("camelCase")) | ||
fmt.Println(CamelToSnakeCase("CAMELtoSnackCASE")) | ||
fmt.Println(CamelToSnakeCase("camelToSnakeCase")) | ||
fmt.Println(CamelToSnakeCase("hey2")) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package main | ||
|
||
import "fmt" | ||
|
||
func main() { | ||
fmt.Println(Capitalize("Hello! How are you? How+are+things+4you?")) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
) | ||
|
||
func main() { | ||
fmt.Println(Capitalize("Hello! How are you? How+are+things+4you?")) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
) | ||
|
||
func main() { | ||
fmt.Println(CheckNumber("Hello")) | ||
fmt.Println(CheckNumber("Hello1")) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package main | ||
|
||
func main() { | ||
Chunk([]int{}, 10) | ||
Chunk([]int{0, 1, 2, 3, 4, 5, 6, 7}, 0) | ||
Chunk([]int{0, 1, 2, 3, 4, 5, 6, 7}, 3) | ||
Chunk([]int{0, 1, 2, 3, 4, 5, 6, 7}, 5) | ||
Chunk([]int{0, 1, 2, 3, 4, 5, 6, 7}, 4) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package main | ||
|
||
import "fmt" | ||
|
||
func main() { | ||
fmt.Println(Compare("Hello!", "Hello!")) | ||
fmt.Println(Compare("Salut!", "lut!")) | ||
fmt.Println(Compare("Ola!", "Ol")) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
) | ||
|
||
func main() { | ||
fmt.Println(Compare("Hello!", "Hello!")) | ||
fmt.Println(Compare("Salut!", "lut!")) | ||
fmt.Println(Compare("Ola!", "Ol")) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
) | ||
|
||
func main() { | ||
fmt.Println(ConcatAlternate([]int{1, 2, 3}, []int{4, 5, 6})) | ||
fmt.Println(ConcatAlternate([]int{2, 4, 6, 8, 10}, []int{1, 3, 5, 7, 9, 11})) | ||
fmt.Println(ConcatAlternate([]int{1, 2, 3}, []int{4, 5, 6, 7, 8, 9})) | ||
fmt.Println(ConcatAlternate([]int{1, 2, 3}, []int{})) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
) | ||
|
||
func main() { | ||
fmt.Println(CountAlpha("Hello world")) | ||
fmt.Println(CountAlpha("H e l l o")) | ||
fmt.Println(CountAlpha("H1e2l3l4o")) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
) | ||
|
||
func main() { | ||
fmt.Println(CountChar("Hello World", 'l')) | ||
fmt.Println(CountChar("5 balloons", 5)) | ||
fmt.Println(CountChar(" ", ' ')) | ||
fmt.Println(CountChar("The 7 deadly sins", '7')) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
) | ||
|
||
func main() { | ||
fmt.Println(DigitLen(100, 10)) | ||
fmt.Println(DigitLen(100, 2)) | ||
fmt.Println(DigitLen(-100, 16)) | ||
fmt.Println(DigitLen(100, -1)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package main | ||
|
||
import "fmt" | ||
|
||
func main() { | ||
fmt.Println(FindPrevPrime(5)) | ||
fmt.Println(FindPrevPrime(4)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package main | ||
|
||
import "fmt" | ||
|
||
func main() { | ||
table := []int{1, 2, 3} | ||
ac := 93 | ||
FoldInt(Add, table, ac) | ||
FoldInt(Mul, table, ac) | ||
FoldInt(Sub, table, ac) | ||
fmt.Println() | ||
|
||
table = []int{0} | ||
FoldInt(Add, table, ac) | ||
FoldInt(Mul, table, ac) | ||
FoldInt(Sub, table, ac) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
) | ||
|
||
func main() { | ||
fmt.Println(HalfSlice([]int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10})) | ||
fmt.Println(HalfSlice([]int{1, 2, 3})) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
) | ||
|
||
func main() { | ||
fmt.Println(HashCode("A")) | ||
fmt.Println(HashCode("AB")) | ||
fmt.Println(HashCode("BAC")) | ||
fmt.Println(HashCode("Hello World")) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
) | ||
|
||
func main() { | ||
fmt.Println(IsCapitalized("Hello! How are you?")) | ||
fmt.Println(IsCapitalized("Hello How Are You")) | ||
fmt.Println(IsCapitalized("Whats 4this 100K?")) | ||
fmt.Println(IsCapitalized("Whatsthis4")) | ||
fmt.Println(IsCapitalized("!!!!Whatsthis4")) | ||
fmt.Println(IsCapitalized("")) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
) | ||
|
||
func main() { | ||
a1 := []int{0, 1, 2, 3, 4, 5} | ||
a2 := []int{0, 2, 1, 3} | ||
|
||
result1 := IsSorted(f, a1) | ||
result2 := IsSorted(f, a2) | ||
|
||
fmt.Println(result1) | ||
fmt.Println(result2) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package main | ||
|
||
import "fmt" | ||
|
||
func PrintList(l *List) { | ||
it := l.Head | ||
for it != nil { | ||
fmt.Print(it.Data, " -> ") | ||
it = it.Next | ||
} | ||
|
||
fmt.Print(nil, "\n") | ||
} | ||
|
||
func main() { | ||
link := &List{} | ||
link2 := &List{} | ||
|
||
fmt.Println("----normal state----") | ||
ListPushBack(link2, 1) | ||
PrintList(link2) | ||
ListRemoveIf(link2, 1) | ||
fmt.Println("------answer-----") | ||
PrintList(link2) | ||
fmt.Println() | ||
|
||
fmt.Println("----normal state----") | ||
ListPushBack(link, 1) | ||
ListPushBack(link, "Hello") | ||
ListPushBack(link, 1) | ||
ListPushBack(link, "There") | ||
ListPushBack(link, 1) | ||
ListPushBack(link, 1) | ||
ListPushBack(link, "How") | ||
ListPushBack(link, 1) | ||
ListPushBack(link, "are") | ||
ListPushBack(link, "you") | ||
ListPushBack(link, 1) | ||
PrintList(link) | ||
|
||
ListRemoveIf(link, 1) | ||
fmt.Println("------answer-----") | ||
PrintList(link) | ||
} | ||
|
||
func ListPushBack(l *List, data interface{}) { | ||
n := &NodeL{Data: data} | ||
if l.Head == nil { | ||
l.Head = n | ||
l.Tail = n | ||
} else { | ||
l.Tail.Next = n | ||
l.Tail = n | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package main | ||
|
||
import "fmt" | ||
|
||
func PrintList(l *List) { | ||
it := l.Head | ||
for it != nil { | ||
fmt.Print(it.Data, " -> ") | ||
it = it.Next | ||
} | ||
|
||
fmt.Print(nil, "\n") | ||
} | ||
|
||
func main() { | ||
link := &List{} | ||
link2 := &List{} | ||
|
||
fmt.Println("----normal state----") | ||
ListPushBack(link2, 1) | ||
PrintList(link2) | ||
ListRemoveIf(link2, 1) | ||
fmt.Println("------answer-----") | ||
PrintList(link2) | ||
fmt.Println() | ||
|
||
fmt.Println("----normal state----") | ||
ListPushBack(link, 1) | ||
ListPushBack(link, "Hello") | ||
ListPushBack(link, 1) | ||
ListPushBack(link, "There") | ||
ListPushBack(link, 1) | ||
ListPushBack(link, 1) | ||
ListPushBack(link, "How") | ||
ListPushBack(link, 1) | ||
ListPushBack(link, "are") | ||
ListPushBack(link, "you") | ||
ListPushBack(link, 1) | ||
PrintList(link) | ||
|
||
ListRemoveIf(link, 1) | ||
fmt.Println("------answer-----") | ||
PrintList(link) | ||
} | ||
|
||
func ListPushBack(l *List, data interface{}) { | ||
n := &NodeL{Data: data} | ||
if l.Head == nil { | ||
l.Head = n | ||
l.Tail = n | ||
} else { | ||
l.Tail.Next = n | ||
l.Tail = n | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
) | ||
|
||
func main() { | ||
fmt.Print(NotDecimal("0.1")) | ||
fmt.Print(NotDecimal("174.2")) | ||
fmt.Print(NotDecimal("0.1255")) | ||
fmt.Print(NotDecimal("1.20525856")) | ||
fmt.Print(NotDecimal("-0.0f00d00")) | ||
fmt.Print(NotDecimal("")) | ||
fmt.Print(NotDecimal("-19.525856")) | ||
fmt.Print(NotDecimal("1952")) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
) | ||
|
||
func main() { | ||
fmt.Print(PrintIf("abcdefz")) | ||
fmt.Print(PrintIf("abc")) | ||
fmt.Print(PrintIf("")) | ||
fmt.Print(PrintIf("14")) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
) | ||
|
||
func main() { | ||
fmt.Print(PrintIfNot("abcdefz")) | ||
fmt.Print(PrintIfNot("abc")) | ||
fmt.Print(PrintIfNot("")) | ||
fmt.Print(PrintIfNot("14")) | ||
} |
Oops, something went wrong.