Browse Source

fixes on subject for exam made by alem

content-update
lee 5 years ago
parent
commit
bcbb7b285f
  1. 21
      subjects/addlinkednumbers.en.md
  2. 12
      subjects/changeorder.en.md
  3. 14
      subjects/merge.en.md
  4. 16
      subjects/priorprime.en.md
  5. 21
      subjects/reverse.en.md
  6. 32
      subjects/sametree.en.md
  7. 9
      subjects/uniqueoccurences.en.md

21
subjects/addlinkednumbers.en.md

@ -8,7 +8,7 @@ This means that:
- The package needs to be named `package main`.
- 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`.
### Instructions
@ -17,7 +17,7 @@ You have two numbers represented by a linked list, where each node contains a si
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
### Expected function and struct
### Expected function and structure
```go
package main
@ -33,6 +33,7 @@ func AddLinkedNumbers(num1, num1 *Node) *Node {
```
### Usage
Here is a possible program to test your function:
```go
@ -40,27 +41,26 @@ package main
import (
"fmt"
piscine ".."
)
func pushFront(node *piscine.Node, num int) *piscine.Node {
func pushFront(node *Node, num int) *Node {
// ...
// Write yourself
}
func main() {
// 3 -> 1 -> 5
num1 := &piscine.Node{Num:5}
num1 := &Node{Num:5}
num1 = pushFront(num1, 1)
num1 = pushFront(num1, 3)
// 5 -> 9 -> 2
num2 := &piscine.Node{Num:2}
num2 := &Node{Num:2}
num2 = pushFront(num2, 9)
num2 = pushFront(num2, 5)
// 9 -> 0 -> 7
result := piscine.AddLinkedNumbers(num1, num2)
result := AddLinkedNumbers(num1, num2)
for tmp := result; tmp != nil; tmp = tmp.Next {
fmt.Print(tmp.Num)
if tmp.Next != nil {
@ -71,10 +71,11 @@ func main() {
}
```
Its output:
An its output:
```console
$> go build
$> ./main
student@ubuntu:~/[[ROOT]]/test$ go build
student@ubuntu:~/[[ROOT]]/test$ ./main
9 -> 0 -> 7
student@ubuntu:~/[[ROOT]]/test$
```

12
subjects/changeorder.en.md

@ -8,7 +8,7 @@ This means that:
- The package needs to be named `package main`.
- 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`.
### Instructions
@ -18,10 +18,10 @@ Change order of linked list so that elements with odd index come first, elements
with even index come afterwards.
You have to return pointer/reference to the beginning of new list
### Expected function and struct
### Expected function and structure
```go
package piscine
package main
type Node struct {
Next *Node
@ -34,26 +34,26 @@ func Changeorder(node *Node) *Node {
```
### Usage
Here is a possible program to test your function:
```go
package main
import (
piscine ".."
"fmt"
)
// I implemented pushBack for this
func main() {
num1 := &piscine.Node{Num: 1}
num1 := &Node{Num: 1}
num1 = pushBack(num1, 2)
num1 = pushBack(num1, 3)
num1 = pushBack(num1, 4)
num1 = pushBack(num1, 5)
result := piscine.Changeorder(num1)
result := Changeorder(num1)
for tmp := result; tmp != nil; tmp = tmp.Next {
fmt.Print(tmp.Num)
if tmp.Next != nil {

14
subjects/merge.en.md

@ -1,4 +1,4 @@
## Merge
## merge
## **WARNING! VERY IMPORTANT!**
@ -8,10 +8,9 @@ This means that:
- The package needs to be named `package main`.
- 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`.
### 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.
@ -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 .
Note: The merging process must start from the root nodes of both trees.
Example 1:
Example 1:
Input:
@ -37,7 +36,7 @@ Input:
[1,2,3]
Merged Tree:
Merged Tree:
2
/ \
@ -67,9 +66,6 @@ Here is a possible program to test your function :
```go
package main
import (
piscine ".."
)
func main() {
mergedTree := &TreeNode{}
@ -81,10 +77,8 @@ func main() {
}
```
### Output
```console
student@ubuntu:~/[[ROOT]]/test$ go build
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 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`.
### Instructions
You are given an integer.
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
package piscine
package main
func Priorprime(x int) int {
@ -26,18 +27,18 @@ func Priorprime(x int) int {
```
### Usage
Here is a possible program to test your function:
```go
package main
import (
piscine ".."
"fmt"
)
func main() {
fmt.Println(piscine.Priorprime(14))
fmt.Println(Priorprime(14))
}
```
@ -45,7 +46,8 @@ func main() {
Its output:
```console
$> go build
$> ./main
student@ubuntu:~/[[ROOT]]/test$ go build
student@ubuntu:~/[[ROOT]]/test$ ./priorprime
41
student@ubuntu:~/[[ROOT]]/test$
```

21
subjects/reverse.en.md

@ -1,4 +1,4 @@
## reverselinkedlist
## reverse
## **WARNING! VERY IMPORTANT!**
@ -8,7 +8,7 @@ This means that:
- The package needs to be named `package main`.
- 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`.
### Instructions
@ -16,10 +16,10 @@ This means that:
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
### Expected function and struct
### Expected function and structure
```go
package piscine
package main
type Node struct {
Next *Node
@ -32,17 +32,19 @@ func Reverse(node *Node) *Node {
```
### Usage
Here is a possible program to test your function:
Here is a possible program to test your function :
```go
package main
import (
"fmt"
piscine ".."
)
// I implemented pushBack for this
func pushBack(n *Node, num int) *Node{
}
func main() {
num1 := &piscine.Node{Num: 1}
@ -66,7 +68,8 @@ func main() {
Its output:
```console
$> go build
$> ./main
student@ubuntu:~/[[ROOT]]/test$ go build
student@ubuntu:~/[[ROOT]]/test$ ./main
5 -> 4 -> 2 -> 3 -> 1
student@ubuntu:~/[[ROOT]]/test$
```

32
subjects/sametree.en.md

@ -1,4 +1,4 @@
## Same Tree
## sametree
## **WARNING! VERY IMPORTANT!**
@ -8,19 +8,16 @@ This means that:
- The package needs to be named `package main`.
- 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`.
### Instructions
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.
Write a function, `IsSameTree`, that returns bool.
Write a function, `IsSameTree`, that returns `bool`.
### Expected function
@ -33,9 +30,11 @@ type TreeNodeL struct {
func IsSameTree(p *TreeNodeL, q *TreeNodeL) bool {
}
```
Example 1:
Example 1:
Input:
@ -51,9 +50,9 @@ Input:
[1,2,3]
Output: true
Output: true
Input:
Input:
1
/
@ -67,9 +66,10 @@ Input:
[1,null,2]
Output: false
Output: false
Input:
Input:
```
1
/ \
@ -82,8 +82,8 @@ Input:
1 2
[1,1,2]
Output: false
```
Output: false
### Usage
@ -92,10 +92,6 @@ Here is a possible program to test your function :
```go
package main
import (
piscine ".."
)
func main() {
t1 := NewRandTree()
t2 := NewRandTree()
@ -104,10 +100,8 @@ func main() {
}
```
### Output
```console
student@ubuntu:~/[[ROOT]]/test$ go build
student@ubuntu:~/[[ROOT]]/test$ ./test

9
subjects/uniqueoccurences.en.md

@ -11,14 +11,13 @@ Only lower case characters will be given.
### Usage
```console
$> go build
$> ./main "abbaac"
student@ubuntu:~/[[ROOT]]/test$ go build
student@ubuntu:~/[[ROOT]]/test$ ./main "abbaac"
true
$> ./main "ab"
student@ubuntu:~/[[ROOT]]/test$ ./main "ab"
false
$> ./main "abcacccazb"
student@ubuntu:~/[[ROOT]]/test$ ./main "abcacccazb"
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.

Loading…
Cancel
Save