docs(gcd): update subject to require a function instead of a program

- add main.go to test the function in exam mode
This commit is contained in:
nprimo 2024-04-29 12:10:41 +01:00 committed by Harry
parent d07d9d681c
commit 529e5c8fdb
2 changed files with 46 additions and 13 deletions

View File

@ -2,26 +2,46 @@
### Instructions
Write a program that takes two `string` representing two strictly positive integers that fit in an `int`.
Write a function that takes two `uint` representing two strictly positive integers and returns their greatest common divisor.
If any of the input numbers is 0, the function should return 0.
The program displays their greatest common divisor followed by a newline (`'\n'`).
> [In mathematics, the greatest common divisor (GCD) of two or more integers, which are not all zero, is the largest positive integer that divides each of the integers.](https://en.wikipedia.org/wiki/Greatest_common_divisor)
If the number of arguments is different from 2, the program displays nothing.
### Expected function
All arguments tested will be positive `int` values.
```go
func Gcd(a, b uint) uint {
}
```
### Usage
Here is a possible program to test your function:
```go
package main
import (
"fmt"
"piscine"
)
func main() {
fmt.Println(piscine.Gcd(42, 10))
fmt.Println(piscine.Gcd(42, 12))
fmt.Println(piscine.Gcd(14, 77))
fmt.Println(piscine.Gcd(17, 3))
}
```
And its output :
```console
$ go run . 42 10 | cat -e
2$
$ go run . 42 12
6
$ go run . 14 77
7
$ go run . 17 3
1
$ go run .
$ go run . 50 12 4
2
6
7
1
$
```

13
subjects/gcd/main.go Normal file
View File

@ -0,0 +1,13 @@
package main
import (
"fmt"
"piscine"
)
func main() {
fmt.Println(piscine.Gcd(42, 10))
fmt.Println(piscine.Gcd(42, 12))
fmt.Println(piscine.Gcd(14, 77))
fmt.Println(piscine.Gcd(17, 3))
}