- Write a [function](TODO-LINK) that simulates the behaviour of the `Atoi` function in Go. `Atoi` transforms a number represented as a `string` in a number represented as an `int`.
-`Atoi` returns `0` if the `string` is not considered as a valid number. For this exercise **non-valid `string` chains will be tested**. Some will contain non-digits characters.
- For this exercise the handling of the signs + or - **does have** to be taken into account.
- This function will **only** have to return the `int`. For this exercise the `error` result of atoi is not required.
### Expected function
```go
func Atoi(s string) int {
}
```
### Usage
Here is a possible [program](TODO-LINK) to test your function :
```go
package main
import (
"fmt"
student ".."
)
func main() {
s := "12345"
s2 := "0000000012345"
s3 := "012 345"
s4 := "Hello World!"
s5 := "+1234"
s6 := "-1234"
s7 := "++1234"
s8 := "--1234"
n := student.Atoi(s)
n2 := student.Atoi(s2)
n3 := student.Atoi(s3)
n4 := student.Atoi(s4)
n5 := student.Atoi(s5)
n6 := student.Atoi(s6)
n7 := student.Atoi(s7)
n8 := student.Atoi(s8)
fmt.Println(n)
fmt.Println(n2)
fmt.Println(n3)
fmt.Println(n4)
fmt.Println(n5)
fmt.Println(n6)
fmt.Println(n7)
fmt.Println(n8)
}
```
And its output :
```console
student@ubuntu:~/[[ROOT]]/test$ go build
student@ubuntu:~/[[ROOT]]/test$ ./test
12345
12345
0
0
1234
-1234
0
0
student@ubuntu:~/[[ROOT]]/test$
```
## recursivepower
### Instructions
Write an **recursive** function that returns the power of the `int` passed as parameter.
Negative powers will return `0`. Overflows do **not** have to be dealt with.
`for` is **forbidden** for this exercise.
### Expected function
```go
func RecursivePower(nb int, power int) int {
}
```
### Usage
Here is a possible [program](TODO-LINK) to test your function :
```go
package main
import (
"fmt"
student ".."
)
func main() {
arg1 := 4
arg2 := 3
fmt.Println(student.RecursivePower(arg1, arg2))
}
```
And its output :
```console
student@ubuntu:~/[[ROOT]]/test$ go build
student@ubuntu:~/[[ROOT]]/test$ ./test
64
student@ubuntu:~/[[ROOT]]/test$
```
## printcombn
### Instructions
- Write a function that prints all possible combinations of **n** different digits in ascending order.
- n will be defined as : 0 <n<10
below are your references for the **printing format** expected.
Here is a possible [program](TODO-LINK) to test your function :
```go
package main
import (
"fmt"
student ".."
)
func main() {
result := student.ConvertBase("101011", "01", "0123456789")
fmt.Println(result)
}
```
And its output :
```console
student@ubuntu:~/[[ROOT]]/test$ go build
student@ubuntu:~/[[ROOT]]/test$ ./test
43
student@ubuntu:~/[[ROOT]]/test$
```
## rotatevowels
### Instructions
Write a **program** that checks the arguments for vowels.
- If the argument contains vowels (for this exercise `y` is not considered a vowel) the program has to **"mirror"** the position of the vowels in the argument (see the examples).
- If the number of arguments is less than 1, the program display a new line ("`\n`").
- If the arguments does not have any vowels, the program just prints the arguments.
Write a program that has the same behaviour as the system's `cat` command-line.
- The `options` do not have to be handled.
- If the program is called without arguments it should take the `input` and print it back (as shown with the "Hello" example below).
- In the program folder create two files named `quest8.txt` and `quest8T.txt`.
- Copy to the `quest8.txt` file the following sentence :
`"Programming is a skill best acquired by pratice and example rather than from books" by Alan Turing`
- Copy to the `quest8T.txt` file the following sentence :
`"Alan Mathison Turing was an English mathematician, computer scientist, logician, cryptanalyst. Turing was highly influential in the development of theoretical computer science, providing a formalisation of the concepts of algorithm and computation with the Turing machine, which can be considered a model of a general-purpose computer. Turing is widely considered to be the father of theoretical computer science and artificial intelligence."`
- In case of error the program should print the error.
- The program must be submitted inside a folder named `cat`.
```console
student@ubuntu:~/[[ROOT]]/cat$ go build
student@ubuntu:~/[[ROOT]]/cat$ ./cat abc
open abc: no such file or directory
student@ubuntu:~/[[ROOT]]/cat$ ./cat quest8.txt
"Programming is a skill best acquired by pratice and example rather than from books" by Alan Turing
"Programming is a skill best acquired by pratice and example rather than from books" by Alan Turing
"Alan Mathison Turing was an English mathematician, computer scientist, logician, cryptanalyst. Turing was highly influential in the development of theoretical computer science, providing a formalisation of the concepts of algorithm and computation with the Turing machine, which can be considered a model of a general-purpose computer. Turing is widely considered to be the father of theoretical computer science and artificial intelligence."
student@ubuntu:~/[[ROOT]]/cat$
```
## ztail
### Instructions
Write a program called `ztail` that has the same behaviour as the system command `tail`, but which takes at least one file as argument.
- The only option to be handled is `-c`. This option will be used in all tests.
- For this program the "os" package can be used.
- For the program to pass the tests the convention for the return code of program in Unix systems should be followed (see os.Exit).
- Handle the errors and output the same error messages as `tail`.
- For more information consult the man page for `tail`.
### Note:
This program is gonna be tested against `tail`, be sure to check all the different error messages with different permutations of the arguments.
## activebits
### Instructions
Write a function, `ActiveBits`, that returns the number of active `bits` (bits with the value 1) in the binary representation of an integer number.
### 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:~/[[ROOT]]/test$ go build
student@ubuntu:~/[[ROOT]]/test$ ./test
3
student@ubuntu:~/[[ROOT]]/test$
```
## sortlistinsert
### Instructions
Write a function `SortListInsert` that inserts `data_ref` in the linked list `l` while keeping the list sorted in ascending order.
- During the tests the list passed as an argument will be already sorted.
Here is a possible [program](TODO-LINK) to test your function :
```go
package main
import (
"fmt"
student ".."
)
func PrintList(l *student.List) {
it := l.Head
for it != nil {
fmt.Print(it.Data, " -> ")
it = it.Next
}
fmt.Print(nil, "\n")
}
func main() {
link := &student.List{}
link2 := &student.List{}
fmt.Println("----normal state----")
student.ListPushBack(link2, 1)
PrintList(link2)
student.ListRemoveIf(link2, 1)
fmt.Println("------answer-----")
PrintList(link2)
fmt.Println()
fmt.Println("----normal state----")
student.ListPushBack(link, 1)
student.ListPushBack(link, "Hello")
student.ListPushBack(link, 1)
student.ListPushBack(link, "There")
student.ListPushBack(link, 1)
student.ListPushBack(link, 1)
student.ListPushBack(link, "How")
student.ListPushBack(link, 1)
student.ListPushBack(link, "are")
student.ListPushBack(link, "you")
student.ListPushBack(link, 1)
PrintList(link)
student.ListRemoveIf(link, 1)
fmt.Println("------answer-----")
PrintList(link)
}
```
And its output :
```console
student@ubuntu:~/[[ROOT]]/test$ go build
student@ubuntu:~/[[ROOT]]/test$ ./test
----normal state----
1 -> <nil>
------answer-----
<nil>
----normal state----
1 -> Hello -> 1 -> There -> 1 -> 1 -> How -> 1 -> are -> you -> 1 -> <nil>
------answer-----
Hello -> There -> How -> are -> you -> <nil>
student@ubuntu:~/[[ROOT]]/test$
```
## 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 `rplc` in the tree given by `root`.