Browse Source

implementing the main.go files at the same level as the readme for the exercise

pull/2276/head
miguel 1 year ago committed by MSilva95
parent
commit
9d80904eed
  1. 18
      subjects/btreedeletenode/main.go
  2. 12
      subjects/byebyefirst/main.go
  3. 14
      subjects/cameltosnakecase/main.go
  4. 7
      subjects/capitalize-exam/main.go
  5. 9
      subjects/capitalize/main.go
  6. 10
      subjects/checknumber/main.go
  7. 9
      subjects/chunk/main.go
  8. 9
      subjects/compare-exam/main.go
  9. 11
      subjects/compare/main.go
  10. 12
      subjects/concatalternate/main.go
  11. 11
      subjects/countalpha/main.go
  12. 12
      subjects/countcharacter/main.go
  13. 12
      subjects/digitlen/main.go
  14. 8
      subjects/findprevprime/main.go
  15. 17
      subjects/foldint/main.go
  16. 10
      subjects/halfslice/main.go
  17. 12
      subjects/hashcode/main.go
  18. 14
      subjects/iscapitalized/main.go
  19. 16
      subjects/issorted/main.go
  20. 55
      subjects/listremoveif-exam/main.go
  21. 55
      subjects/listremoveif/main.go
  22. 16
      subjects/notdecimal/main.go
  23. 12
      subjects/printif/main.go
  24. 12
      subjects/printifnot/main.go
  25. 11
      subjects/rectperimeter/main.go
  26. 17
      subjects/reduceint/main.go
  27. 11
      subjects/removeduplicate/main.go
  28. 11
      subjects/reversesecondhalf/main.go
  29. 13
      subjects/setspace/main.go
  30. 10
      subjects/sliceadd/main.go
  31. 12
      subjects/sliceremove/main.go
  32. 9
      subjects/sortwordarr-exam/main.go
  33. 11
      subjects/sortwordarr/main.go
  34. 11
      subjects/swapfirst/main.go
  35. 11
      subjects/swaplast/main.go
  36. 12
      subjects/thirdtimeisacharm/main.go
  37. 11
      subjects/weareunique/main.go
  38. 11
      subjects/zipstring/main.go

18
subjects/btreedeletenode/main.go

@ -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
subjects/byebyefirst/main.go

@ -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
subjects/cameltosnakecase/main.go

@ -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
subjects/capitalize-exam/main.go

@ -0,0 +1,7 @@
package main
import "fmt"
func main() {
fmt.Println(Capitalize("Hello! How are you? How+are+things+4you?"))
}

9
subjects/capitalize/main.go

@ -0,0 +1,9 @@
package main
import (
"fmt"
)
func main() {
fmt.Println(Capitalize("Hello! How are you? How+are+things+4you?"))
}

10
subjects/checknumber/main.go

@ -0,0 +1,10 @@
package main
import (
"fmt"
)
func main() {
fmt.Println(CheckNumber("Hello"))
fmt.Println(CheckNumber("Hello1"))
}

9
subjects/chunk/main.go

@ -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
subjects/compare-exam/main.go

@ -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
subjects/compare/main.go

@ -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
subjects/concatalternate/main.go

@ -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
subjects/countalpha/main.go

@ -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
subjects/countcharacter/main.go

@ -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
subjects/digitlen/main.go

@ -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
subjects/findprevprime/main.go

@ -0,0 +1,8 @@
package main
import "fmt"
func main() {
fmt.Println(FindPrevPrime(5))
fmt.Println(FindPrevPrime(4))
}

17
subjects/foldint/main.go

@ -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
subjects/halfslice/main.go

@ -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
subjects/hashcode/main.go

@ -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
subjects/iscapitalized/main.go

@ -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
subjects/issorted/main.go

@ -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
subjects/listremoveif-exam/main.go

@ -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
subjects/listremoveif/main.go

@ -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
subjects/notdecimal/main.go

@ -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
subjects/printif/main.go

@ -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
subjects/printifnot/main.go

@ -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"))
}

11
subjects/rectperimeter/main.go

@ -0,0 +1,11 @@
package main
import (
"fmt"
)
func main() {
fmt.Println(RectPerimeter(10, 2))
fmt.Println(RectPerimeter(434343, 898989))
fmt.Println(RectPerimeter(10, -2))
}

17
subjects/reduceint/main.go

@ -0,0 +1,17 @@
package main
func main() {
mul := func(acc int, cur int) int {
return acc * cur
}
sum := func(acc int, cur int) int {
return acc + cur
}
div := func(acc int, cur int) int {
return acc / cur
}
as := []int{500, 2}
ReduceInt(as, mul)
ReduceInt(as, sum)
ReduceInt(as, div)
}

11
subjects/removeduplicate/main.go

@ -0,0 +1,11 @@
package main
import (
"fmt"
)
func main() {
fmt.Println(RemoveDuplicate([]int{1, 2, 3, 3, 4, 5, 6, 7, 8, 9, 10}))
fmt.Println(RemoveDuplicate([]int{1, 1, 2, 2, 3}))
fmt.Println(RemoveDuplicate([]int{}))
}

11
subjects/reversesecondhalf/main.go

@ -0,0 +1,11 @@
package main
import (
"fmt"
)
func main() {
fmt.Print(ReverseSecondHalf("This is the 1st half This is the 2nd half"))
fmt.Print(ReverseSecondHalf(""))
fmt.Print(ReverseSecondHalf("Hello World"))
}

13
subjects/setspace/main.go

@ -0,0 +1,13 @@
package main
import (
"fmt"
)
func main() {
fmt.Println(SetSpace("HelloWorld"))
fmt.Println(SetSpace("HelloWorld12"))
fmt.Println(SetSpace("Hello World"))
fmt.Println(SetSpace(""))
fmt.Println(SetSpace("LoremIpsumWord"))
}

10
subjects/sliceadd/main.go

@ -0,0 +1,10 @@
package main
import (
"fmt"
)
func main() {
fmt.Println(SliceAdd([]int{1, 2, 3}, 4))
fmt.Println(SliceAdd([]int{}, 4))
}

12
subjects/sliceremove/main.go

@ -0,0 +1,12 @@
package main
import (
"fmt"
)
func main() {
fmt.Println(SliceRemove([]int{1, 2, 3}, 2))
fmt.Println(SliceRemove([]int{4, 3}, 4))
fmt.Println(SliceRemove([]int{}, 1))
}

9
subjects/sortwordarr-exam/main.go

@ -0,0 +1,9 @@
package main
import "fmt"
func main() {
result := []string{"a", "A", "1", "b", "B", "2", "c", "C", "3"}
SortWordArr(result)
fmt.Println(result)
}

11
subjects/sortwordarr/main.go

@ -0,0 +1,11 @@
package main
import (
"fmt"
)
func main() {
result := []string{"a", "A", "1", "b", "B", "2", "c", "C", "3"}
SortWordArr(result)
fmt.Println(result)
}

11
subjects/swapfirst/main.go

@ -0,0 +1,11 @@
package main
import (
"fmt"
)
func main() {
fmt.Println(SwapFirst([]int{1, 2, 3, 4}))
fmt.Println(SwapFirst([]int{3, 4, 6}))
fmt.Println(SwapFirst([]int{1}))
}

11
subjects/swaplast/main.go

@ -0,0 +1,11 @@
package main
import (
"fmt"
)
func main() {
fmt.Println(SwapLast([]int{1, 2, 3, 4}))
fmt.Println(SwapLast([]int{3, 4, 5}))
fmt.Println(SwapLast([]int{1}))
}

12
subjects/thirdtimeisacharm/main.go

@ -0,0 +1,12 @@
package main
import (
"fmt"
)
func main() {
fmt.Print(ThirdTimeIsACharm("123456789"))
fmt.Print(ThirdTimeIsACharm(""))
fmt.Print(ThirdTimeIsACharm("a b c d e f"))
fmt.Print(ThirdTimeIsACharm("12"))
}

11
subjects/weareunique/main.go

@ -0,0 +1,11 @@
package main
import (
"fmt"
)
func main() {
fmt.Println(WeAreUnique("foo", "boo"))
fmt.Println(WeAreUnique("", ""))
fmt.Println(WeAreUnique("abc", "def"))
}

11
subjects/zipstring/main.go

@ -0,0 +1,11 @@
package main
import (
"fmt"
)
func main() {
fmt.Println(ZipString("YouuungFellllas"))
fmt.Println(ZipString("Thee quuick browwn fox juumps over the laaazy dog"))
fmt.Println(ZipString("Helloo Therre!"))
}
Loading…
Cancel
Save