Skip to content

Commit

Permalink
docs(gcd): update subject to require a function instead of a program
Browse files Browse the repository at this point in the history
- add main.go to test the function in exam mode
  • Loading branch information
nprimo authored and HarryVasanth committed Jun 27, 2024
1 parent d07d9d6 commit 529e5c8
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 11 deletions.
42 changes: 31 additions & 11 deletions subjects/gcd/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 13 additions & 0 deletions subjects/gcd/main.go
Original file line number Diff line number Diff line change
@@ -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))
}

0 comments on commit 529e5c8

Please sign in to comment.