mirror of https://github.com/01-edu/public.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
66 lines
1.1 KiB
66 lines
1.1 KiB
5 years ago
|
## putnbrbase
|
||
5 years ago
|
|
||
5 years ago
|
### Instructions
|
||
5 years ago
|
|
||
|
Write a function that prints an `int` in a `string` base passed in parameters.
|
||
|
|
||
|
If the base is not valid, the function prints `NV` (Not Valid):
|
||
|
|
||
|
Validity rules for a base :
|
||
|
|
||
5 years ago
|
- A base must contain at least 2 characters.
|
||
|
- Each character of a base must be unique.
|
||
|
- A base should not contain `+` or `-` characters.
|
||
5 years ago
|
|
||
|
The function has to manage negative numbers. (as shown in the example)
|
||
|
|
||
5 years ago
|
### Expected function
|
||
5 years ago
|
|
||
|
```go
|
||
![]()
5 years ago
|
func PrintNbrBase(nbr int, base string) {
|
||
5 years ago
|
|
||
|
}
|
||
|
```
|
||
|
|
||
5 years ago
|
### Usage
|
||
5 years ago
|
|
||
5 years ago
|
Here is a possible program to test your function :
|
||
5 years ago
|
|
||
|
```go
|
||
|
package main
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
![]()
4 years ago
|
|
||
5 years ago
|
"github.com/01-edu/z01"
|
||
![]()
4 years ago
|
|
||
5 years ago
|
piscine ".."
|
||
|
)
|
||
|
|
||
|
func main() {
|
||
|
piscine.PrintNbrBase(125, "0123456789")
|
||
|
z01.PrintRune('\n')
|
||
|
piscine.PrintNbrBase(-125, "01")
|
||
|
z01.PrintRune('\n')
|
||
|
piscine.PrintNbrBase(125, "0123456789ABCDEF")
|
||
|
z01.PrintRune('\n')
|
||
|
piscine.PrintNbrBase(-125, "choumi")
|
||
|
z01.PrintRune('\n')
|
||
|
piscine.PrintNbrBase(125, "aa")
|
||
|
z01.PrintRune('\n')
|
||
|
}
|
||
|
```
|
||
|
|
||
|
And its output :
|
||
|
|
||
|
```console
|
||
5 years ago
|
student@ubuntu:~/[[ROOT]]/test$ go build
|
||
|
student@ubuntu:~/[[ROOT]]/test$ ./test
|
||
5 years ago
|
125
|
||
|
-1111101
|
||
|
7D
|
||
|
-uoi
|
||
|
NV
|
||
5 years ago
|
student@ubuntu:~/[[ROOT]]/test$
|
||
5 years ago
|
```
|