Browse Source

new exercises for exam

content-update
lee 4 years ago
parent
commit
38f756f564
  1. 55
      subjects/chunk.en.md
  2. 62
      subjects/reduceint.en.md
  3. 27
      subjects/romannumbers.en.md

55
subjects/chunk.en.md

@ -0,0 +1,55 @@
## chunk
## **WARNING! VERY IMPORTANT!**
For this exercise a function will be tested **with the exam own main**. However the student **still needs** to submit a structured program:
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.
- Every other rules are obviously the same than for a `program`.
### Instructions
Write a function called `Chunk` that receives as parameters a slice, `slice []int`, and an number `size int`. The goal of this function is to chunk a slice into many sub slices where each sub slice has the length of `size`.
- If the `size` is `0` it should print `\n`
### Expected function
```go
func Chunk(slice []int, size int) {
}
```
### Usage
Here is a possible program to test your function :
```go
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)
}
```
And its output :
```console
student@ubuntu:~/[[ROOT]]/test$ go build
student@ubuntu:~/[[ROOT]]/test$ ./test
[]
[[0 1 2] [3 4 5] [6 7]]
[[0 1 2 3 4] [5 6 7]]
[[0 1 2 3] [4 5 6 7]]
student@ubuntu:~/[[ROOT]]/test$
```

62
subjects/reduceint.en.md

@ -0,0 +1,62 @@
## reduceint
## **WARNING! VERY IMPORTANT!**
For this exercise a function will be tested **with the exam own main**. However the student **still needs** to submit a structured program:
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.
- Every other rules are obviously the same than for a `program`.
### Instructions
Write a function called `reduceint` that simulates the behaviour of reduce from JavaScript.
The function should have as parameters a function, `f func(int, int) int` and a slice of integers, `slice []int`. You should apply for each element of the slice the arithmetic function, saving it and printing.
### Expected function
```go
func ReduceInt(f func(int, int) int, slice []int) {
}
```
### Usage
Here is a possible program to test your function :
```go
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(mul, as)
ReduceInt(sum, as)
ReduceInt(div, as)
}
```
And its output :
```console
student@ubuntu:~/[[ROOT]]/test$ go build
student@ubuntu:~/[[ROOT]]/test$ ./test
1000
502
250
student@ubuntu:~/[[ROOT]]/test$
```

27
subjects/romannumbers.en.md

@ -0,0 +1,27 @@
## romannumbers
### Instructions
Write a program called `rn`. The objective is to converte a number, given has argument, into a roman number and print it with roman number calculation.
The program should have a limit of `4000`. In case of an invalid number, for example `"hello"` or `0` the program should print `ERROR: can not convert to roman digit`.
## Usage
```console
student@ubuntu:~/[[ROOT]]/test$ go build
student@ubuntu:~/[[ROOT]]/test$ ./rn hello
ERROR: can not convert to roman digit
student@ubuntu:~/[[ROOT]]/test$ ./rn 123
C+X+X+I+I+I
CXXIII
student@ubuntu:~/[[ROOT]]/test$ ./rn 999
(M-C)+(C-X)+(X-I)
CMXCIX
student@ubuntu:~/[[ROOT]]/test$ ./rn 3999
M+M+M+(M-C)+(C-X)+(X-I)
MMMCMXCIX
student@ubuntu:~/[[ROOT]]/test$ ./rn 4000
ERROR: can not convert to roman digit
student@ubuntu:~/[[ROOT]]/test$
```
Loading…
Cancel
Save