Browse Source

Merge pull request #380 from 01-edu/fix-exercise-exam-alem

fixes on subject for exam made by alem
content-update
MSilva95 5 years ago committed by GitHub
parent
commit
0877adb4bb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 29
      subjects/addlinkednumbers.en.md
  2. 18
      subjects/changeorder.en.md
  3. 8
      subjects/inverttree.en.md
  4. 24
      subjects/merge.en.md
  5. 16
      subjects/priorprime.en.md
  6. 29
      subjects/reverse.en.md
  7. 40
      subjects/sametree.en.md
  8. 13
      subjects/sortll.en.md
  9. 9
      subjects/uniqueoccurences.en.md

29
subjects/addlinkednumbers.en.md

@ -8,31 +8,32 @@ This means that:
- The package needs to be named `package main`. - The package needs to be named `package main`.
- The submitted code needs one declared function main(```func main()```) even if empty. - The submitted code needs one declared function main(```func main()```) even if empty.
- The function main declared needs to **also pass** the `Restrictions Checker`(illegal functions tester). It is advised for the student to just empty the function main after its own testings are done. - The function main declared needs to **also pass** the `Restrictions Checker`(illegal functions tester). It is advised for the student to just empty the function main after its own testing are done.
- Every other rules are obviously the same than for a `program`. - Every other rules are obviously the same than for a `program`.
### Instructions ### Instructions
You have two numbers represented by a linked list, where each node contains a single digit. You have two numbers represented by a linked list, where each NodeAddL contains a single digit.
The digits are stored in reverse order, such that the 1’s digit is at the head of the list. The digits are stored in reverse order, such that the 1’s digit is at the head of the list.
Write a function that adds the two numbers and returns the sum as a linked list Write a function that adds the two numbers and returns the sum as a linked list
### Expected function and struct ### Expected function and structure
```go ```go
package main package main
type Node struct { type NodeAddL struct {
Next *Node Next *NodeAddL
Num int Num int
} }
func AddLinkedNumbers(num1, num1 *Node) *Node { func AddLinkedNumbers(num1, num1 *NodeAddL) *NodeAddL {
} }
``` ```
### Usage ### Usage
Here is a possible program to test your function: Here is a possible program to test your function:
```go ```go
@ -40,27 +41,26 @@ package main
import ( import (
"fmt" "fmt"
piscine ".."
) )
func pushFront(node *piscine.Node, num int) *piscine.Node { func pushFront(node *NodeAddL, num int) *NodeAddL {
// ... // ...
// Write yourself // Write yourself
} }
func main() { func main() {
// 3 -> 1 -> 5 // 3 -> 1 -> 5
num1 := &piscine.Node{Num:5} num1 := &NodeAddL{Num:5}
num1 = pushFront(num1, 1) num1 = pushFront(num1, 1)
num1 = pushFront(num1, 3) num1 = pushFront(num1, 3)
// 5 -> 9 -> 2 // 5 -> 9 -> 2
num2 := &piscine.Node{Num:2} num2 := &NodeAddL{Num:2}
num2 = pushFront(num2, 9) num2 = pushFront(num2, 9)
num2 = pushFront(num2, 5) num2 = pushFront(num2, 5)
// 9 -> 0 -> 7 // 9 -> 0 -> 7
result := piscine.AddLinkedNumbers(num1, num2) result := AddLinkedNumbers(num1, num2)
for tmp := result; tmp != nil; tmp = tmp.Next { for tmp := result; tmp != nil; tmp = tmp.Next {
fmt.Print(tmp.Num) fmt.Print(tmp.Num)
if tmp.Next != nil { if tmp.Next != nil {
@ -71,10 +71,11 @@ func main() {
} }
``` ```
Its output: An its output:
```console ```console
$> go build student@ubuntu:~/[[ROOT]]/test$ go build
$> ./main student@ubuntu:~/[[ROOT]]/test$ ./main
9 -> 0 -> 7 9 -> 0 -> 7
student@ubuntu:~/[[ROOT]]/test$
``` ```

18
subjects/changeorder.en.md

@ -8,7 +8,7 @@ This means that:
- The package needs to be named `package main`. - The package needs to be named `package main`.
- The submitted code needs one declared function main(```func main()```) even if empty. - The submitted code needs one declared function main(```func main()```) even if empty.
- The function main declared needs to **also pass** the `Restrictions Checker`(illegal functions tester). It is advised for the student to just empty the function main after its own testings are done. - The function main declared needs to **also pass** the `Restrictions Checker`(illegal functions tester). It is advised for the student to just empty the function main after its own testing are done.
- Every other rules are obviously the same than for a `program`. - Every other rules are obviously the same than for a `program`.
### Instructions ### Instructions
@ -18,42 +18,42 @@ Change order of linked list so that elements with odd index come first, elements
with even index come afterwards. with even index come afterwards.
You have to return pointer/reference to the beginning of new list You have to return pointer/reference to the beginning of new list
### Expected function and struct ### Expected function and structure
```go ```go
package piscine package main
type Node struct { type NodeAddL struct {
Next *Node Next *NodeAddL
Num int Num int
} }
func Changeorder(node *Node) *Node { func Changeorder(node *NodeAddL) *NodeAddL {
} }
``` ```
### Usage ### Usage
Here is a possible program to test your function: Here is a possible program to test your function:
```go ```go
package main package main
import ( import (
piscine ".."
"fmt" "fmt"
) )
// I implemented pushBack for this // I implemented pushBack for this
func main() { func main() {
num1 := &piscine.Node{Num: 1} num1 := &NodeAddL{Num: 1}
num1 = pushBack(num1, 2) num1 = pushBack(num1, 2)
num1 = pushBack(num1, 3) num1 = pushBack(num1, 3)
num1 = pushBack(num1, 4) num1 = pushBack(num1, 4)
num1 = pushBack(num1, 5) num1 = pushBack(num1, 5)
result := piscine.Changeorder(num1) result := Changeorder(num1)
for tmp := result; tmp != nil; tmp = tmp.Next { for tmp := result; tmp != nil; tmp = tmp.Next {
fmt.Print(tmp.Num) fmt.Print(tmp.Num)
if tmp.Next != nil { if tmp.Next != nil {

8
subjects/inverttree.en.md

@ -15,10 +15,10 @@ This means that:
### Instructions: ### Instructions:
Write a function that takes tree and inverts(flips) and returns it. Write a function that takes tree and inverts(flips) and returns it.
``` ```
type Node struct { type TNode struct {
Val int Val int
Left *Node Left *TNode
Right *Node Right *TNode
} }
``` ```
Example: Example:
@ -39,6 +39,6 @@ Output:
``` ```
Expected function: Expected function:
``` ```
func InvertTree(root *Node) *Node { func InvertTree(root *TNode) *TNode {
} }
``` ```

24
subjects/merge.en.md

@ -1,4 +1,4 @@
## Merge ## merge
## **WARNING! VERY IMPORTANT!** ## **WARNING! VERY IMPORTANT!**
@ -8,10 +8,9 @@ This means that:
- The package needs to be named `package main`. - The package needs to be named `package main`.
- The submitted code needs one declared function main(```func main()```) even if empty. - The submitted code needs one declared function main(```func main()```) even if empty.
- The function main declared needs to **also pass** the `Restrictions Checker`(illegal functions tester). It is advised for the student to just empty the function main after its own testings are done. - The function main declared needs to **also pass** the `Restrictions Checker`(illegal functions tester). It is advised for the student to just empty the function main after its own testing are done.
- Every other rules are obviously the same than for a `program`. - Every other rules are obviously the same than for a `program`.
### Instructions ### Instructions
Given two binary trees and imagine that when you put one of them to cover the other, some nodes of the two trees are overlapped while the others are not. Given two binary trees and imagine that when you put one of them to cover the other, some nodes of the two trees are overlapped while the others are not.
@ -21,7 +20,7 @@ You need to merge them into a new binary tree. The merge rule is that if two nod
Write a function, `MergeTrees`, that returns merged tree . Write a function, `MergeTrees`, that returns merged tree .
Note: The merging process must start from the root nodes of both trees. Note: The merging process must start from the root nodes of both trees.
Example 1: Example 1:
Input: Input:
@ -37,7 +36,7 @@ Input:
[1,2,3] [1,2,3]
Merged Tree: Merged Tree:
2 2
/ \ / \
@ -48,14 +47,14 @@ Merged Tree:
### Expected function ### Expected function
```go ```go
type TreeNode struct { type TreeNodeM struct {
Left *TreeNodeL Left *TreeNodeM
Val int Val int
Right *TreeNodeL Right *TreeNodeM
} }
func MergeTrees(t1 *TreeNode, t2 *TreeNode) *TreeNode { func MergeTrees(t1 *TreeNodeM, t2 *TreeNodeM) *TreeNodeM {
} }
``` ```
@ -67,12 +66,9 @@ Here is a possible program to test your function :
```go ```go
package main package main
import (
piscine ".."
)
func main() { func main() {
mergedTree := &TreeNode{} mergedTree := &TreeNodeM{}
t1 := NewRandTree() t1 := NewRandTree()
t2 := NewRandTree() t2 := NewRandTree()
@ -81,10 +77,8 @@ func main() {
} }
``` ```
### Output ### Output
```console ```console
student@ubuntu:~/[[ROOT]]/test$ go build student@ubuntu:~/[[ROOT]]/test$ go build
student@ubuntu:~/[[ROOT]]/test$ ./test student@ubuntu:~/[[ROOT]]/test$ ./test

16
subjects/priorprime.en.md

@ -8,17 +8,18 @@ This means that:
- The package needs to be named `package main`. - The package needs to be named `package main`.
- The submitted code needs one declared function main(```func main()```) even if empty. - The submitted code needs one declared function main(```func main()```) even if empty.
- The function main declared needs to **also pass** the `Restrictions Checker`(illegal functions tester). It is advised for the student to just empty the function main after its own testings are done. - The function main declared needs to **also pass** the `Restrictions Checker`(illegal functions tester). It is advised for the student to just empty the function main after its own testing are done.
- Every other rules are obviously the same than for a `program`. - Every other rules are obviously the same than for a `program`.
### Instructions ### Instructions
You are given an integer. You are given an integer.
Your function must return sum of all prime numbers prior to the number exclusively. The number is not included. Your function must return sum of all prime numbers prior to the number exclusively. The number is not included.
### Expected function and struct
### Expected function and structure
```go ```go
package piscine package main
func Priorprime(x int) int { func Priorprime(x int) int {
@ -26,18 +27,18 @@ func Priorprime(x int) int {
``` ```
### Usage ### Usage
Here is a possible program to test your function: Here is a possible program to test your function:
```go ```go
package main package main
import ( import (
piscine ".."
"fmt" "fmt"
) )
func main() { func main() {
fmt.Println(piscine.Priorprime(14)) fmt.Println(Priorprime(14))
} }
``` ```
@ -45,7 +46,8 @@ func main() {
Its output: Its output:
```console ```console
$> go build student@ubuntu:~/[[ROOT]]/test$ go build
$> ./main student@ubuntu:~/[[ROOT]]/test$ ./priorprime
41 41
student@ubuntu:~/[[ROOT]]/test$
``` ```

29
subjects/reverse.en.md

@ -1,4 +1,4 @@
## reverselinkedlist ## reverse
## **WARNING! VERY IMPORTANT!** ## **WARNING! VERY IMPORTANT!**
@ -8,7 +8,7 @@ This means that:
- The package needs to be named `package main`. - The package needs to be named `package main`.
- The submitted code needs one declared function main(```func main()```) even if empty. - The submitted code needs one declared function main(```func main()```) even if empty.
- The function main declared needs to **also pass** the `Restrictions Checker`(illegal functions tester). It is advised for the student to just empty the function main after its own testings are done. - The function main declared needs to **also pass** the `Restrictions Checker`(illegal functions tester). It is advised for the student to just empty the function main after its own testing are done.
- Every other rules are obviously the same than for a `program`. - Every other rules are obviously the same than for a `program`.
### Instructions ### Instructions
@ -16,36 +16,38 @@ This means that:
You are given a linked list, where each node contains a single digit. You are given a linked list, where each node contains a single digit.
Write a function that reverses the list and returns pointer/reference to new linked list Write a function that reverses the list and returns pointer/reference to new linked list
### Expected function and struct ### Expected function and structure
```go ```go
package piscine package main
type Node struct { type NodeAddL struct {
Next *Node Next *NodeAddL
Num int Num int
} }
func Reverse(node *Node) *Node { func Reverse(node *NodeAddL) *NodeAddL {
} }
``` ```
### Usage ### Usage
Here is a possible program to test your function:
Here is a possible program to test your function :
```go ```go
package main package main
import ( import (
"fmt" "fmt"
piscine ".."
) )
// I implemented pushBack for this func pushBack(n *NodeAddL, num int) *NodeAddL{
}
func main() { func main() {
num1 := &piscine.Node{Num: 1} num1 := &piscine.NodeAddL{Num: 1}
num1 = pushBack(num1, 3) num1 = pushBack(num1, 3)
num1 = pushBack(num1, 2) num1 = pushBack(num1, 2)
num1 = pushBack(num1, 4) num1 = pushBack(num1, 4)
@ -66,7 +68,8 @@ func main() {
Its output: Its output:
```console ```console
$> go build student@ubuntu:~/[[ROOT]]/test$ go build
$> ./main student@ubuntu:~/[[ROOT]]/test$ ./main
5 -> 4 -> 2 -> 3 -> 1 5 -> 4 -> 2 -> 3 -> 1
student@ubuntu:~/[[ROOT]]/test$
``` ```

40
subjects/sametree.en.md

@ -1,4 +1,4 @@
## Same Tree ## sametree
## **WARNING! VERY IMPORTANT!** ## **WARNING! VERY IMPORTANT!**
@ -8,34 +8,33 @@ This means that:
- The package needs to be named `package main`. - The package needs to be named `package main`.
- The submitted code needs one declared function main(```func main()```) even if empty. - The submitted code needs one declared function main(```func main()```) even if empty.
- The function main declared needs to **also pass** the `Restrictions Checker`(illegal functions tester). It is advised for the student to just empty the function main after its own testings are done. - The function main declared needs to **also pass** the `Restrictions Checker`(illegal functions tester). It is advised for the student to just empty the function main after its own testing are done.
- Every other rules are obviously the same than for a `program`. - Every other rules are obviously the same than for a `program`.
### Instructions ### Instructions
Given two binary trees, write a function to check if they are the same or not. Given two binary trees, write a function to check if they are the same or not.
Two binary trees are considered the same if they are structurally identical and the nodes have the same value. Two binary trees are considered the same if they are structurally identical and the nodes have the same value.
Write a function, `IsSameTree`, that returns bool. Write a function, `IsSameTree`, that returns `bool`.
### Expected function ### Expected function
```go ```go
type TreeNodeL struct { type TreeNodeM struct {
Left *TreeNodeL Left *TreeNodeM
Val int Val int
Right *TreeNodeL Right *TreeNodeM
} }
func IsSameTree(p *TreeNodeL, q *TreeNodeL) bool { func IsSameTree(p *TreeNodeM, q *TreeNodeM) bool {
} }
``` ```
Example 1:
Example 1:
Input: Input:
@ -51,9 +50,9 @@ Input:
[1,2,3] [1,2,3]
Output: true Output: true
Input: Input:
1 1
/ /
@ -67,9 +66,10 @@ Input:
[1,null,2] [1,null,2]
Output: false Output: false
Input: Input:
```
1 1
/ \ / \
@ -82,8 +82,8 @@ Input:
1 2 1 2
[1,1,2] [1,1,2]
```
Output: false Output: false
### Usage ### Usage
@ -92,10 +92,6 @@ Here is a possible program to test your function :
```go ```go
package main package main
import (
piscine ".."
)
func main() { func main() {
t1 := NewRandTree() t1 := NewRandTree()
t2 := NewRandTree() t2 := NewRandTree()
@ -104,10 +100,8 @@ func main() {
} }
``` ```
### Output ### Output
```console ```console
student@ubuntu:~/[[ROOT]]/test$ go build student@ubuntu:~/[[ROOT]]/test$ go build
student@ubuntu:~/[[ROOT]]/test$ ./test student@ubuntu:~/[[ROOT]]/test$ ./test

13
subjects/sortll.en.md

@ -19,14 +19,14 @@ Write a function that sorts the list in descending order and return pointer/refe
### Expected function and struct ### Expected function and struct
```go ```go
package piscine package main
type Node struct { type NodeAddL struct {
Next *Node Next *NodeAddL
Num int Num int
} }
func Sortll(node *Node) *Node { func Sortll(node *NodeAddL) *NodeAddL {
} }
``` ```
@ -39,19 +39,18 @@ package main
import ( import (
"fmt" "fmt"
piscine ".."
) )
// I implemented pushBack for this // I implemented pushBack for this
func main() { func main() {
num1 := &piscine.Node{Num: 5} num1 := &NodeAddL{Num: 5}
num1 = pushBack(num1, 1) num1 = pushBack(num1, 1)
num1 = pushBack(num1, 3) num1 = pushBack(num1, 3)
num1 = pushBack(num1, 1) num1 = pushBack(num1, 1)
num1 = pushBack(num1, 3) num1 = pushBack(num1, 3)
result := piscine.Sortll(num1) result := Sortll(num1)
for tmp := result; tmp != nil; tmp = tmp.Next { for tmp := result; tmp != nil; tmp = tmp.Next {
fmt.Print(tmp.Num) fmt.Print(tmp.Num)
if tmp.Next != nil { if tmp.Next != nil {

9
subjects/uniqueoccurences.en.md

@ -11,14 +11,13 @@ Only lower case characters will be given.
### Usage ### Usage
```console ```console
$> go build student@ubuntu:~/[[ROOT]]/test$ go build
$> ./main "abbaac" student@ubuntu:~/[[ROOT]]/test$ ./main "abbaac"
true true
$> ./main "ab" student@ubuntu:~/[[ROOT]]/test$ ./main "ab"
false false
$> ./main "abcacccazb" student@ubuntu:~/[[ROOT]]/test$ ./main "abcacccazb"
true true
``` ```
In first example, character 'a' has 3 occurrences, 'b' has 2 and 'c' has 1. No two characters have the same number of occurrences. In first example, character 'a' has 3 occurrences, 'b' has 2 and 'c' has 1. No two characters have the same number of occurrences.

Loading…
Cancel
Save