From e8e325ce4f4895f8fb3a728eb166c8004fa5b12a Mon Sep 17 00:00:00 2001 From: Augusto Date: Wed, 17 Apr 2019 09:55:36 +0100 Subject: [PATCH] readmes for binary trees exercises and some of quest 10 --- subjects/abort.md | 42 +++++++++++++++++ subjects/activebits.md | 43 ++++++++++++++++++ subjects/btreeapplybylevel.md | 48 +++++++++++++++++++ subjects/btreedeletenode.md | 60 ++++++++++++++++++++++++ subjects/btreeisbinary.md | 45 ++++++++++++++++++ subjects/btreelevelcount.md | 43 ++++++++++++++++++ subjects/btreemax.md | 46 +++++++++++++++++++ subjects/btreemin.md | 46 +++++++++++++++++++ subjects/btreetransplant.md | 51 +++++++++++++++++++++ subjects/collatzcountdown.md | 42 +++++++++++++++++ subjects/enigma.md | 86 +++++++++++++++++++++++++++++++++++ subjects/join.md | 44 ++++++++++++++++++ subjects/max.md | 44 ++++++++++++++++++ subjects/pilot.md | 26 +++++++++++ subjects/unmatch.md | 44 ++++++++++++++++++ subjects/ztail.md | 13 ++++++ 16 files changed, 723 insertions(+) create mode 100644 subjects/abort.md create mode 100644 subjects/activebits.md create mode 100644 subjects/btreeapplybylevel.md create mode 100644 subjects/btreedeletenode.md create mode 100644 subjects/btreeisbinary.md create mode 100644 subjects/btreelevelcount.md create mode 100644 subjects/btreemax.md create mode 100644 subjects/btreemin.md create mode 100644 subjects/btreetransplant.md create mode 100644 subjects/collatzcountdown.md create mode 100644 subjects/enigma.md create mode 100644 subjects/join.md create mode 100644 subjects/max.md create mode 100644 subjects/pilot.md create mode 100644 subjects/unmatch.md create mode 100644 subjects/ztail.md diff --git a/subjects/abort.md b/subjects/abort.md new file mode 100644 index 000000000..ba029f93c --- /dev/null +++ b/subjects/abort.md @@ -0,0 +1,42 @@ +# abort +## Instructions + +Write a function that returns the the value in the middle of 5 five arguments. + +This function must have the following signature. + +## Expected function + +```go +func Abort(a, b, c, d, e int) int { + +} + +``` + +## Usage + +Here is a possible [program](TODO-LINK) to test your function : + +```go +package main + +import ( + "fmt" + student ".." +) + +func main() { + middle := student.Abort(2, 3, 8, 5, 7) + fmt.Println(middle) +} +``` + +And its output : + +```console +student@ubuntu:~/student/abort$ go build +student@ubuntu:~/student/abort$ ./abort +5 +student@ubuntu:~/student/abort$ +``` diff --git a/subjects/activebits.md b/subjects/activebits.md new file mode 100644 index 000000000..e23c6b41e --- /dev/null +++ b/subjects/activebits.md @@ -0,0 +1,43 @@ +# activebits +## Instructions + +Write a function, ActiveBitsthat, that returns the number of active bits (bits with the value 1) in the binary representation of an integer number. + +The function must have the next signature. + +## Expected function + +```go + +func ActiveBits(n int) uint { + +} + +``` + +## Usage + +Here is a possible [program](TODO-LINK) to test your function : + +```go +package main + +import ( + "fmt" + student ".." +) + +func main() { + nbits := student.ActiveBits(7) + fmt.Println(nbits) +} +``` + +And its output : + +```console +student@ubuntu:~/student/activebits$ go build +student@ubuntu:~/student/activebits$ ./activebits +10 +student@ubuntu:~/student/activebits$ +``` diff --git a/subjects/btreeapplybylevel.md b/subjects/btreeapplybylevel.md new file mode 100644 index 000000000..410b518d9 --- /dev/null +++ b/subjects/btreeapplybylevel.md @@ -0,0 +1,48 @@ +# btreeapplybylevel +## Instructions + +Write a function, BTreeApplyByLevel, that applies the function given by fn to each node of the tree given by root. + +This function must have the following signature. + +## Expected function + +```go +func BTreeApplyByLevel(root *TreeNode, fn interface{}) { + +} + +``` + +## Usage + +Here is a possible [program](TODO-LINK) to test your function : + +```go +package main + +import ( + "fmt" + student ".." +) + +func main() { + root := &student.TreeNode{Data: "4"} + student.BTreeInsertData(root, "1") + student.BTreeInsertData(root, "7") + student.BTreeInsertData(root, "5") + student.BTreeApplyByLevel(root, fmt.Println) +} +``` + +And its output : + +```console +student@ubuntu:~/student/btreeapplybylevel$ go build +student@ubuntu:~/student/btreeapplybylevel$ ./btreeapplybylevel +4 +1 +7 +5 +student@ubuntu:~/student/btreeapplybylevel$ +``` diff --git a/subjects/btreedeletenode.md b/subjects/btreedeletenode.md new file mode 100644 index 000000000..7220eeed9 --- /dev/null +++ b/subjects/btreedeletenode.md @@ -0,0 +1,60 @@ +# btreedeletenode +## Instructions + +Write a function, BTreeDeleteNode, that deletes 'node' from the tree given by root. + +The resulting tree should still follow the binary search tree rules. + +This function must have the following signature. + +## Expected function + +```go +func BTreeDeleteNode(root, node *TreeNode) *TreeNode { + +} + +``` + +## Usage + +Here is a possible [program](TODO-LINK) to test your function : + +```go +package main + +import ( + "fmt" + student ".." +) + +func main() { + root := &student.TreeNode{Data: "4"} + student.BTreeInsertData(root, "1") + student.BTreeInsertData(root, "7") + student.BTreeInsertData(root, "5") + node := student.BTreeSearchItem(root, "4") + fmt.Println("Before delete:") + student.BTreeApplyInorder(root, fmt.Println) + root = student.BTreeDeleteNode(root, node) + fmt.Println("After delete:") + student.BTreeApplyInorder(root, fmt.Println) +} +``` + +And its output : + +```console +student@ubuntu:~/student/btreedeletenode$ go build +student@ubuntu:~/student/btreedeletenode$ ./btreedeletenode +Before delete: +1 +4 +5 +7 +After delete: +1 +5 +7 +student@ubuntu:~/student/btreedeletenode$ +``` diff --git a/subjects/btreeisbinary.md b/subjects/btreeisbinary.md new file mode 100644 index 000000000..8f58fa9b1 --- /dev/null +++ b/subjects/btreeisbinary.md @@ -0,0 +1,45 @@ +# btreeisbinary +## Instructions + +Write a function, BTreeIsBinary, that returns true only if the tree given by root follows the binary search tree properties. + +This function must have the following signature. + +## Expected function + +```go +func BTreeIsBinary(root *TreeNode) bool { + +} + +``` + +## Usage + +Here is a possible [program](TODO-LINK) to test your function : + +```go +package main + +import ( + "fmt" + student ".." +) + +func main() { + root := &student.TreeNode{Data: "4"} + student.BTreeInsertData(root, "1") + student.BTreeInsertData(root, "7") + student.BTreeInsertData(root, "5") + fmt.Println(student.BTreeIsBinary(root)) +} +``` + +And its output : + +```console +student@ubuntu:~/student/btreeisbinary$ go build +student@ubuntu:~/student/btreeisbinary$ ./btreeisbinary +true +student@ubuntu:~/student/btreeisbinary$ +``` diff --git a/subjects/btreelevelcount.md b/subjects/btreelevelcount.md new file mode 100644 index 000000000..d3f8983cc --- /dev/null +++ b/subjects/btreelevelcount.md @@ -0,0 +1,43 @@ +# btreelevelcount +## Instructions + +Write a function, BTreeLevelCount, that return the number of levels of the tree (height of the tree) + +## Expected function + +```go +func BTreeLevelCount(root *piscine.TreeNode) int { + +} + +``` + +## Usage + +Here is a possible [program](TODO-LINK) to test your function : + +```go +package main + +import ( + "fmt" + student ".." +) + +func main() { + root := &student.TreeNode{Data: "4"} + student.BTreeInsertData(root, "1") + student.BTreeInsertData(root, "7") + student.BTreeInsertData(root, "5") + fmt.Println(BTreeLevelCount(root)) +} +``` + +And its output : + +```console +student@ubuntu:~/student/btreesearchitem$ go build +student@ubuntu:~/student/btreesearchitem$ ./btreesearchitem +3 +student@ubuntu:~/student/btreesearchitem$ +``` diff --git a/subjects/btreemax.md b/subjects/btreemax.md new file mode 100644 index 000000000..46ee38df9 --- /dev/null +++ b/subjects/btreemax.md @@ -0,0 +1,46 @@ +# btreemax +## Instructions + +Write a function, BTreeMax, that returns the node with the maximum value in the tree given by root + +This function must have the following signature. + +## Expected function + +```go +func BTreeMax(root *TreeNode) *TreeNode { + +} + +``` + +## Usage + +Here is a possible [program](TODO-LINK) to test your function : + +```go +package main + +import ( + "fmt" + student ".." +) + +func main() { + root := &student.TreeNode{Data: "4"} + student.BTreeInsertData(root, "1") + student.BTreeInsertData(root, "7") + student.BTreeInsertData(root, "5") + max := student.BTreeMax(root) + fmt.Println(max.Data) +} +``` + +And its output : + +```console +student@ubuntu:~/student/btreemax$ go build +student@ubuntu:~/student/btreemax$ ./btreemax +7 +student@ubuntu:~/student/btreemax$ +``` diff --git a/subjects/btreemin.md b/subjects/btreemin.md new file mode 100644 index 000000000..2371c0fee --- /dev/null +++ b/subjects/btreemin.md @@ -0,0 +1,46 @@ +# btreemin +## Instructions + +Write a function, BTreeMin, that returns the node with the minimum value in the tree given by root + +This function must have the following signature. + +## Expected function + +```go +func BTreeMin(root *TreeNode) *TreeNode { + +} + +``` + +## Usage + +Here is a possible [program](TODO-LINK) to test your function : + +```go +package main + +import ( + "fmt" + student ".." +) + +func main() { + root := &student.TreeNode{Data: "4"} + student.BTreeInsertData(root, "1") + student.BTreeInsertData(root, "7") + student.BTreeInsertData(root, "5") + min := student.BTreeMin(root) + fmt.Println(min.Data) +} +``` + +And its output : + +```console +student@ubuntu:~/student/btreemin$ go build +student@ubuntu:~/student/btreemin$ ./btreemin +1 +student@ubuntu:~/student/btreemin$ +``` diff --git a/subjects/btreetransplant.md b/subjects/btreetransplant.md new file mode 100644 index 000000000..695fdc76d --- /dev/null +++ b/subjects/btreetransplant.md @@ -0,0 +1,51 @@ +# btreetransplant +## Instructions + +In order to move subtrees around within the binary search tree, write a function, BTreeTransplant, which replaces the subtree started by node with the node called 'rplc' in the tree given by root. + +This function must have the following signature. + +## Expected function + +```go +func BTreeTransplant(root, node, rplc *TreeNode) *TreeNode { + +} + +``` + +## Usage + +Here is a possible [program](TODO-LINK) to test your function : + +```go +package main + +import ( + "fmt" + student ".." +) + +func main() { + root := &student.TreeNode{Data: "4"} + student.BTreeInsertData(root, "1") + student.BTreeInsertData(root, "7") + student.BTreeInsertData(root, "5") + node := student.BTreeSearchItem(root, "1") + replacement := &student.TreeNode{Data: "3"} + root = student.BTreeTransplant(root, node, replacement) + student.BTreeApplyInorder(root, fmt.Println) +} +``` + +And its output : + +```console +student@ubuntu:~/student/btreetransplant$ go build +student@ubuntu:~/student/btreetrandsplant$ ./btreetransplant +3 +4 +5 +7 +student@ubuntu:~/student/btreetrandsplant$ +``` diff --git a/subjects/collatzcountdown.md b/subjects/collatzcountdown.md new file mode 100644 index 000000000..72c0522cb --- /dev/null +++ b/subjects/collatzcountdown.md @@ -0,0 +1,42 @@ +# collatzcountdown +## Instructions + +Write a function, CollatzCountdown, that returns the number of steps to reach 1 using the collatz countdown. + +The function must have the following signature. + +## Expected function + +```go +func CollatzCountdown(start int) int { + +} + +``` + +## Usage + +Here is a possible [program](TODO-LINK) to test your function : + +```go +package main + +import ( + "fmt" + student ".." +) + +func main() { + steps := student.CollatzCountdown(12) + fmt.Println(steps) +} +``` + +And its output : + +```console +student@ubuntu:~/student/collatzcountdown$ go build +student@ubuntu:~/student/collatzcountdown$ ./collatzcountdown +10 +student@ubuntu:~/student/collatzcountdown$ +``` diff --git a/subjects/enigma.md b/subjects/enigma.md new file mode 100644 index 000000000..27fb76c5f --- /dev/null +++ b/subjects/enigma.md @@ -0,0 +1,86 @@ +# enigma +## Instructions + +Write a function called `Enigma` that receives poiters to functions and move its values around to hide them + +This function will put a into c; c into d; d into b and b into a + +This function must have the following signature. + +## Expected function + +```go +func Enigma(a ***int, b *int, c *******int, d ****int) { + +} + +``` + +## Usage + +Here is a possible [program](TODO-LINK) to test your function : + +```go +package main + +import ( + "fmt" + student ".." +) + +func main() { + x := 5 + y := &x + z := &y + a := &z + + w := 2 + b := &w + + u := 7 + e := &u + f := &e + g := &f + h := &g + i := &h + j := &i + c := &j + + k := 6 + l := &k + m := &l + n := &m + d := &n + + fmt.Println(***a) + fmt.Println(*b) + fmt.Println(*******c) + fmt.Println(****d) + + student.Enigma(a, b, c, d) + + fmt.Println("After using Enigma") + fmt.Println(***a) + fmt.Println(*b) + fmt.Println(*******c) + fmt.Println(****d) + +} +``` + +And its output : + +```console +student@ubuntu:~/student/enigma$ go build +student@ubuntu:~/student/enigma$ ./enigma +5 +2 +7 +6 +After using Enigma +2 +6 +5 +7 +student@ubuntu:~/student/enigma$ +``` diff --git a/subjects/join.md b/subjects/join.md new file mode 100644 index 000000000..013afd3d3 --- /dev/null +++ b/subjects/join.md @@ -0,0 +1,44 @@ +# join +## Instructions + +Write a function, Join, that returns the elements of a slice strings (arstr) join together in one string. Using the string 'sep' as a separator between each element of the array + +The function must have the next signature. + +## Expected function + +```go + +func Join(arstr []string, sep string) string { + +} + +``` + +## Usage + +Here is a possible [program](TODO-LINK) to test your function : + +```go +package main + +import ( + "fmt" + student ".." +) + +func main() { + arrStr := []string{"hello", "how", "are", "you"} + joined := student.Join(arrStr, "--") + fmt.Println(joined) +} +``` + +And its output : + +```console +student@ubuntu:~/student/join$ go build +student@ubuntu:~/student/join$ ./join +hello--how--are--you +student@ubuntu:~/student/join$ +``` diff --git a/subjects/max.md b/subjects/max.md new file mode 100644 index 000000000..7b2503f5c --- /dev/null +++ b/subjects/max.md @@ -0,0 +1,44 @@ +# max +## Instructions + +Write a function, Max, that returns the maximum value in a slice of integers + +The function must have the next signature. + +## Expected function + +```go + +func Max(arr []int) int { + +} + +``` + +## Usage + +Here is a possible [program](TODO-LINK) to test your function : + +```go +package main + +import ( + "fmt" + student ".." +) + +func main() { + arrInt := []int{23, 123, 1, 11, 55, 93} + max := student.Max(arrInt) + fmt.Println(max +} +``` + +And its output : + +```console +student@ubuntu:~/student/max$ go build +student@ubuntu:~/student/max$ ./max +123 +student@ubuntu:~/student/max$ +``` diff --git a/subjects/pilot.md b/subjects/pilot.md new file mode 100644 index 000000000..fd9649e8b --- /dev/null +++ b/subjects/pilot.md @@ -0,0 +1,26 @@ +# pilot +## Instructions + +Write a go file so that the following program compile + +## Usage + +```go +package main + +import ( + "fmt" + student ".." +) + +func main() { + var donnie student.Pilot + donnie.Name = "Donnie" + donnie.Life = 100.0 + donnie.Age = 24 + donnie.Aircraft = student.AIRCRAFT1 + + fmt.Println(donnie) +} +``` + diff --git a/subjects/unmatch.md b/subjects/unmatch.md new file mode 100644 index 000000000..26c61a8b4 --- /dev/null +++ b/subjects/unmatch.md @@ -0,0 +1,44 @@ +# join +## Instructions + +Write a function, Unmatch, that returns the element of the slice (arr) that does not have a correspondent pair. + +The function must have the next signature. + +## Expected function + +```go + +func Unmatch(arr []int) int { + +} + +``` + +## Usage + +Here is a possible [program](TODO-LINK) to test your function : + +```go +package main + +import ( + "fmt" + student ".." +) + +func main() { + arr := []int{1, 2, 3, 1, 2, 3, 4} + unmatch := student.Unmatch(arr) + fmt.Println(unmatch) +} +``` + +And its output : + +```console +student@ubuntu:~/student/unmatch$ go build +student@ubuntu:~/student/unmatch$ ./unmatch +4 +student@ubuntu:~/student/unmatch$ +``` diff --git a/subjects/ztail.md b/subjects/ztail.md new file mode 100644 index 000000000..8c7c424a1 --- /dev/null +++ b/subjects/ztail.md @@ -0,0 +1,13 @@ +# ztail +## Instructions + +Write a program called ztail that does the same thing as the system command tail, but witch takes at least one file as argument. + +The only option you have to handle is -c. This option will be used in all tests. + +For this program you can use the "os" package. + +For the program to pass the test you should follow the convention for the return code of program in Unix sistems (see os.Exit) + +For more information consult the man page for tail. +