Skip to content

Commit

Permalink
implementing the main.go files at the same level as the readme for th…
Browse files Browse the repository at this point in the history
…e exercise
  • Loading branch information
MSilva95 committed Nov 3, 2023
1 parent dd64f9c commit 9d80904
Show file tree
Hide file tree
Showing 38 changed files with 534 additions and 0 deletions.
18 changes: 18 additions & 0 deletions subjects/btreedeletenode/main.go
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)
}
12 changes: 12 additions & 0 deletions subjects/byebyefirst/main.go
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"}))
}
14 changes: 14 additions & 0 deletions subjects/cameltosnakecase/main.go
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"))
}
7 changes: 7 additions & 0 deletions subjects/capitalize-exam/main.go
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?"))
}
9 changes: 9 additions & 0 deletions subjects/capitalize/main.go
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?"))
}
10 changes: 10 additions & 0 deletions subjects/checknumber/main.go
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"))
}
9 changes: 9 additions & 0 deletions subjects/chunk/main.go
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)
}
9 changes: 9 additions & 0 deletions subjects/compare-exam/main.go
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"))
}
11 changes: 11 additions & 0 deletions subjects/compare/main.go
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"))
}
12 changes: 12 additions & 0 deletions subjects/concatalternate/main.go
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{}))
}
11 changes: 11 additions & 0 deletions subjects/countalpha/main.go
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"))
}
12 changes: 12 additions & 0 deletions subjects/countcharacter/main.go
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'))
}
12 changes: 12 additions & 0 deletions subjects/digitlen/main.go
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))
}
8 changes: 8 additions & 0 deletions subjects/findprevprime/main.go
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))
}
17 changes: 17 additions & 0 deletions subjects/foldint/main.go
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)
}
10 changes: 10 additions & 0 deletions subjects/halfslice/main.go
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}))
}
12 changes: 12 additions & 0 deletions subjects/hashcode/main.go
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"))
}
14 changes: 14 additions & 0 deletions subjects/iscapitalized/main.go
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(""))
}
16 changes: 16 additions & 0 deletions subjects/issorted/main.go
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)
}
55 changes: 55 additions & 0 deletions subjects/listremoveif-exam/main.go
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
}
}
55 changes: 55 additions & 0 deletions subjects/listremoveif/main.go
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
}
}
16 changes: 16 additions & 0 deletions subjects/notdecimal/main.go
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"))
}
12 changes: 12 additions & 0 deletions subjects/printif/main.go
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"))
}
12 changes: 12 additions & 0 deletions subjects/printifnot/main.go
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"))
}
Loading

0 comments on commit 9d80904

Please sign in to comment.