Browse Source

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

- add main.go to test the function in exam mode
pull/2555/head
nprimo 2 weeks ago
parent
commit
e3090d773c
  1. 42
      subjects/gcd/README.md
  2. 13
      subjects/gcd/main.go

42
subjects/gcd/README.md

@ -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
$ go run .
2
6
$ go run . 14 77
7
$ go run . 17 3
1
$ go run .
$ go run . 50 12 4
$
```

13
subjects/gcd/main.go

@ -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))
}
Loading…
Cancel
Save