mirror of https://github.com/01-edu/public.git
Frenchris
6 years ago
committed by
GitHub
266 changed files with 8455 additions and 685 deletions
@ -0,0 +1,162 @@ |
|||||||
|
# Object Attributes System |
||||||
|
|
||||||
|
> This document cover two notions, the edition of attributes and the impact it has relatively to the others Objects. |
||||||
|
|
||||||
|
## Edition of Attributes |
||||||
|
|
||||||
|
> There is no limit to how many attributes can be defined to an Object. |
||||||
|
|
||||||
|
In the "Object Attributes" section of the "Object Edit" Page, the first row is a form to create and append a new attribute. It requires two elements, the name of the attribute and its type (`String`, `Number`, `Boolean`, `Array`, `Object`, `Function`, `Null`). Click 'Add' to create the attribute. |
||||||
|
|
||||||
|
> Within a same Object, each attribute's name must be unique. |
||||||
|
|
||||||
|
Once created, the new attributes appears right bellow and the ability to associate a value to it is now available. Depending on the type of the attribute, the interface will vary. |
||||||
|
|
||||||
|
- String value input is type String. |
||||||
|
- Number value input is type Number. |
||||||
|
- Booleans value input appears as a switch, true by default. |
||||||
|
- Arrays and Objects content are hideable / showable via the "Show/Hide content" button on the right of the attribute. There is no limit on the depth of Object/Array, however, after a certain level, the interface will start to feel narrow. |
||||||
|
- String value input is type String. |
||||||
|
- Null will not display any input. |
||||||
|
- Function will offer to select from all available functions, save on select. |
||||||
|
|
||||||
|
Any attribute can be delete by clicking on the 'trash' icon on the right hand of it. |
||||||
|
|
||||||
|
Here an example of how the section looks like. |
||||||
|
![object-attributes](https://user-images.githubusercontent.com/15313830/56677487-88675600-66b8-11e9-9781-26dc0ee6301d.png) |
||||||
|
|
||||||
|
## Attributes and RelationShips |
||||||
|
|
||||||
|
When an attributes is set to an Object, other Objects, associated to this particular Object, will have access to it. Which means that, if an Object A is added as a child of an Object B, A will embed its attributes within the instance of B. |
||||||
|
|
||||||
|
Object's attributes follow a hierarchy when associated to an other Object. |
||||||
|
The **defaults attributes** of a child, the ones defined in the original Object are the weakest ones. A **children attribute** is applied to all the children and override the default attributes. Finally, **relation attribute** is the strongest one, it override Default Attributes and Children Attributes. |
||||||
|
|
||||||
|
When an object and its relationship are resolved, the three structures (`attrs`, `childrenAttrs`, `childAttrs`) are merged. |
||||||
|
|
||||||
|
The following json shows how the object would be represented: |
||||||
|
|
||||||
|
```json |
||||||
|
{ |
||||||
|
"children": { |
||||||
|
"printalphabet": { |
||||||
|
"duration": 3600, |
||||||
|
"xp": 800, |
||||||
|
"isBonus": true |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
``` |
||||||
|
|
||||||
|
Children |
||||||
|
![children](https://user-images.githubusercontent.com/15313830/56679319-b189e580-66bc-11e9-8f2a-3d51eb1486d4.png) |
||||||
|
|
||||||
|
Child |
||||||
|
![chilld-capture](https://user-images.githubusercontent.com/15313830/56679320-b189e580-66bc-11e9-90ab-c8f69f531876.png) |
||||||
|
|
||||||
|
## Detailed example |
||||||
|
|
||||||
|
Let's create a few `exercises` objects |
||||||
|
|
||||||
|
> swap |
||||||
|
|
||||||
|
```js |
||||||
|
{ |
||||||
|
"id": 12344, |
||||||
|
"title": "swap", |
||||||
|
"attrs": { |
||||||
|
"language": "go", |
||||||
|
"duration": 7200 |
||||||
|
} |
||||||
|
} |
||||||
|
``` |
||||||
|
|
||||||
|
> printalphabet |
||||||
|
|
||||||
|
```js |
||||||
|
{ |
||||||
|
"id": 12345, |
||||||
|
"title": "printalphabet-v2", |
||||||
|
"attrs": { |
||||||
|
"language": "go", |
||||||
|
"duration": 3600 |
||||||
|
} |
||||||
|
} |
||||||
|
``` |
||||||
|
|
||||||
|
We can now create a parent object that will reference them and link them. |
||||||
|
|
||||||
|
This allow you to specify the structuration of your pedagocial content. |
||||||
|
|
||||||
|
I'll make a quest that regroup those 2 exercises: |
||||||
|
|
||||||
|
> quest-03 |
||||||
|
|
||||||
|
```js |
||||||
|
{ |
||||||
|
"id": 12346, |
||||||
|
"title": "quest-03", |
||||||
|
"attrs": {}, |
||||||
|
"childrenAttrs": { |
||||||
|
"xp": 800, |
||||||
|
"duration": 4800, |
||||||
|
}, |
||||||
|
"children": { |
||||||
|
"printalphabet": { |
||||||
|
"ref": 12345, |
||||||
|
"index": 0, |
||||||
|
"attrs": { |
||||||
|
"duration": 7200 |
||||||
|
} |
||||||
|
}, |
||||||
|
"swap": { |
||||||
|
"ref": 12344, |
||||||
|
"index": 1, |
||||||
|
"attrs": {} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
``` |
||||||
|
|
||||||
|
All done, now when rendering an object, attributes are merged like so: |
||||||
|
|
||||||
|
> rendered quest object |
||||||
|
|
||||||
|
```js |
||||||
|
{ |
||||||
|
"id": 12346, |
||||||
|
"title": "quest-03", |
||||||
|
"attrs": {}, |
||||||
|
"children": { |
||||||
|
"printalphabet": { |
||||||
|
"ref": 12345, |
||||||
|
"index": 0, |
||||||
|
"attrs": { |
||||||
|
"language": "go", |
||||||
|
"xp": 800, |
||||||
|
"duration": 7200 |
||||||
|
} |
||||||
|
}, |
||||||
|
"swap": { |
||||||
|
"ref": 12344, |
||||||
|
"index": 1, |
||||||
|
"attrs": { |
||||||
|
"language": "go", |
||||||
|
"xp": 800, |
||||||
|
"duration": 4800 |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
``` |
||||||
|
|
||||||
|
First we apply the **default attributes** from the referenced object. |
||||||
|
> Here `duration` and `language` are applied. |
||||||
|
|
||||||
|
Then we apply the **children attributes** to every child. |
||||||
|
> In this case we override every `duration` to 4800 and add the new `xp` attribute. |
||||||
|
|
||||||
|
After that we apply the **relation attributes**, that are the most specific and as such, |
||||||
|
override all others attributes. |
||||||
|
> In this case only the `printalphabet` relation had attributes and so we apply |
||||||
|
the given `duration` to the final merged object. |
@ -0,0 +1,34 @@ |
|||||||
|
# Objects Edition |
||||||
|
|
||||||
|
> Allow you to edit an object, see and manage its relations. |
||||||
|
|
||||||
|
## Page Composition |
||||||
|
|
||||||
|
![object-edit-overview](https://user-images.githubusercontent.com/15313830/56667480-ceff8500-66a5-11e9-98c7-792d598f2394.png) |
||||||
|
|
||||||
|
### Pin 1 |
||||||
|
|
||||||
|
- Link back to the "Objects" page ; |
||||||
|
- Editable name field, hit 'enter' or 'cmd + s' or click on the floppy-disk icon to save ; |
||||||
|
- Major dependencies visualisation, (where my object is used as a child), click the label to navigate to the dependence ; |
||||||
|
- External URL, this is an optional parameter, it's use to point at an other source of content or information needed by the object. We generaly use to point at a Git repository ; |
||||||
|
|
||||||
|
### Pin 2 |
||||||
|
|
||||||
|
- Delete Button, Warning there, it will destroy your object! ; |
||||||
|
- Type of your Object (`organisation`, `campus`, `onboarding`, `cursus`, `quest`, `exercise`), save on select ; |
||||||
|
- Status of your Object (`draft`, `online`, `offline`), save on select ; |
||||||
|
- The first and last name of the original author ; |
||||||
|
|
||||||
|
### Pin 3 |
||||||
|
|
||||||
|
- Object Attribute edition area, manage all the attributes relative to this Object. These attributes will be exposed to its relationship ; |
||||||
|
|
||||||
|
### Pin 4 |
||||||
|
|
||||||
|
- Object Children edition area ; |
||||||
|
- Children Attributes edition area, these attributes impact and overload all the following children. Works the same way as standard attributes ; |
||||||
|
- Add a child, allows to add a child to the children list, more information here -> [Object Child creation](https://github.com/01-edu/public/blob/master/doc/object-child-creation.md) ; |
||||||
|
- Children List, allows you to reorganise, delete and edit child. Each child can be overload with its own attributes, the edition works the same way as the original attributes ; |
||||||
|
|
||||||
|
More informations about attribute overload system [here] ((https://github.com/01-edu/public/blob/master/doc/object-attribute-overload-system.md) |
@ -0,0 +1,29 @@ |
|||||||
|
# Objects |
||||||
|
|
||||||
|
> Allow you to create, manage and organize your pedagical and onboarding content. |
||||||
|
|
||||||
|
## Definition |
||||||
|
|
||||||
|
An Object is an highly customizable element, which can be use in many situations. We use it to compose cursuses and onboarding processes. |
||||||
|
Objects can be associated together and then share a vertical or horizontal relationship, which allows to build complex structure of multiple objects. |
||||||
|
|
||||||
|
It structure can be visualized in two parts. The first one is the definition of the object itself and attributes, called `attrs`. The second part is the definition of minor relationships, called `children` and attributes applied to them, called `childrenAttrs`. |
||||||
|
|
||||||
|
This is the minimal structure of an object: |
||||||
|
|
||||||
|
- name |
||||||
|
- type (`organisation`, `campus`, `onboarding`, `cursus`, `quest`, `exercise`) |
||||||
|
- status (`draft`, `online`, `offline`) |
||||||
|
- attrs {} |
||||||
|
- childrenAttrs {} |
||||||
|
- children {} |
||||||
|
|
||||||
|
## Browse Objects: |
||||||
|
|
||||||
|
To access your Objects, go to the admin dashboard and then click on the _manage object_ link within the "Object" card. |
||||||
|
|
||||||
|
![go-to-objects](https://user-images.githubusercontent.com/15313830/56653756-46bdb780-6686-11e9-98ba-18e382987e9c.png) |
||||||
|
|
||||||
|
Objects are sorted by type in different sections. This page offer a search bar that allow you query the objects by name. In the top-right corner, click the _add a new object_ button to create a new object. Fill a name, select a type and click _create_ to validate your creation. You will be redirected to the Object Edition page (document is here). |
||||||
|
|
||||||
|
![all-object-page](https://user-images.githubusercontent.com/15313830/56654475-137c2800-6688-11e9-880b-75092397890d.png) |
@ -0,0 +1,88 @@ |
|||||||
|
package main |
||||||
|
|
||||||
|
import ( |
||||||
|
"bytes" |
||||||
|
"encoding/json" |
||||||
|
"errors" |
||||||
|
"fmt" |
||||||
|
"io/ioutil" |
||||||
|
"net/http" |
||||||
|
"os" |
||||||
|
) |
||||||
|
|
||||||
|
func jsonPrettyPrint(in []byte) string { |
||||||
|
var out bytes.Buffer |
||||||
|
err := json.Indent(&out, in, "", " ") |
||||||
|
if err != nil { |
||||||
|
return string(in) |
||||||
|
} |
||||||
|
return out.String() |
||||||
|
} |
||||||
|
|
||||||
|
var HASURA_GRAPHQL_ADDRESS = os.Getenv("HASURA_GRAPHQL_ADDRESS") |
||||||
|
var HASURA_GRAPHQL_ADMIN_SECRET = os.Getenv("HASURA_GRAPHQL_ADMIN_SECRET") |
||||||
|
|
||||||
|
type GraphqlQuery struct { |
||||||
|
Data interface{} |
||||||
|
} |
||||||
|
|
||||||
|
var client = &http.Client{Transport: http.DefaultTransport} |
||||||
|
|
||||||
|
func hasura(query string, variables interface{}, data interface{}) (err error) { |
||||||
|
variablesBytes, err := json.Marshal(variables) |
||||||
|
if err != nil { |
||||||
|
return |
||||||
|
} |
||||||
|
|
||||||
|
v := string(variablesBytes) |
||||||
|
requestBody := []byte(`{"query":"` + query + `","variables":` + v + `}`) |
||||||
|
requestBytes := bytes.NewBuffer(requestBody) |
||||||
|
req, err := http.NewRequest("POST", HASURA_GRAPHQL_ADDRESS, requestBytes) |
||||||
|
if err != nil { |
||||||
|
return |
||||||
|
} |
||||||
|
|
||||||
|
req.Header.Add("X-Hasura-Admin-Secret", HASURA_GRAPHQL_ADMIN_SECRET) |
||||||
|
|
||||||
|
resp, err := client.Do(req) |
||||||
|
if err != nil { |
||||||
|
return |
||||||
|
} |
||||||
|
|
||||||
|
b, err := ioutil.ReadAll(resp.Body) |
||||||
|
if err != nil { |
||||||
|
return |
||||||
|
} |
||||||
|
|
||||||
|
// loggin the answer for debugging purposes
|
||||||
|
fmt.Println(jsonPrettyPrint(b)) |
||||||
|
|
||||||
|
if resp.StatusCode < 200 || resp.StatusCode > 299 { |
||||||
|
return errors.New(http.StatusText(resp.StatusCode)) |
||||||
|
} |
||||||
|
|
||||||
|
return json.Unmarshal(b, &GraphqlQuery{Data: data}) |
||||||
|
} |
||||||
|
|
||||||
|
type User struct { |
||||||
|
GithubLogin string |
||||||
|
} |
||||||
|
|
||||||
|
const userQuery = ` |
||||||
|
query { |
||||||
|
user { |
||||||
|
githubLogin |
||||||
|
} |
||||||
|
}` |
||||||
|
|
||||||
|
func getUsers() (users []User, err error) { |
||||||
|
var data map[string][]User |
||||||
|
err = hasura(userQuery, nil, &data) |
||||||
|
return data["user"], err |
||||||
|
} |
||||||
|
|
||||||
|
func main() { |
||||||
|
fmt.Println(getUsers()) |
||||||
|
} |
||||||
|
|
||||||
|
// HASURA_GRAPHQL_ADMIN_SECRET=VERYVERYSECRET HASURA_GRAPHQL_ADDRESS=http://localhost/graphql-engine/v1alpha1/graphql go run call-graphql.go
|
@ -1,20 +1,20 @@ |
|||||||
# abort |
## abort |
||||||
## Instructions |
|
||||||
|
### Instructions |
||||||
|
|
||||||
Write a function that returns the the value in the middle of 5 five arguments. |
Write a function that returns the the value in the middle of 5 five arguments. |
||||||
|
|
||||||
This function must have the following signature. |
This function must have the following signature. |
||||||
|
|
||||||
## Expected function |
### Expected function |
||||||
|
|
||||||
```go |
```go |
||||||
func Abort(a, b, c, d, e int) int { |
func Abort(a, b, c, d, e int) int { |
||||||
|
|
||||||
} |
} |
||||||
|
|
||||||
``` |
``` |
||||||
|
|
||||||
## Usage |
### Usage |
||||||
|
|
||||||
Here is a possible [program](TODO-LINK) to test your function : |
Here is a possible [program](TODO-LINK) to test your function : |
||||||
|
|
@ -1,21 +1,20 @@ |
|||||||
# activebits |
## activebits |
||||||
## Instructions |
|
||||||
|
### Instructions |
||||||
|
|
||||||
Write a function, ActiveBitsthat, that returns the number of active bits (bits with the value 1) in the binary representation of an integer number. |
Write a function, ActiveBitsthat, that returns the number of active bits (bits with the value 1) in the binary representation of an integer number. |
||||||
|
|
||||||
The function must have the next signature. |
The function must have the next signature. |
||||||
|
|
||||||
## Expected function |
### Expected function |
||||||
|
|
||||||
```go |
```go |
||||||
|
|
||||||
func ActiveBits(n int) uint { |
func ActiveBits(n int) uint { |
||||||
|
|
||||||
} |
} |
||||||
|
|
||||||
``` |
``` |
||||||
|
|
||||||
## Usage |
### Usage |
||||||
|
|
||||||
Here is a possible [program](TODO-LINK) to test your function : |
Here is a possible [program](TODO-LINK) to test your function : |
||||||
|
|
@ -0,0 +1,42 @@ |
|||||||
|
## advancedsortwordarr |
||||||
|
|
||||||
|
### Instructions |
||||||
|
|
||||||
|
Write a function `AdvancedSortWordArr` that sorts a `string` array, based on the function `f` passed in parameter. |
||||||
|
|
||||||
|
### Expected function |
||||||
|
|
||||||
|
```go |
||||||
|
func AdvancedSortWordTab(array []string, f func(a, b string) int) { |
||||||
|
} |
||||||
|
``` |
||||||
|
|
||||||
|
### Usage |
||||||
|
|
||||||
|
Here is a possible [program](TODO-LINK) to test your function : |
||||||
|
|
||||||
|
```go |
||||||
|
package main |
||||||
|
|
||||||
|
import ( |
||||||
|
"fmt" |
||||||
|
piscine ".." |
||||||
|
) |
||||||
|
|
||||||
|
func main() { |
||||||
|
|
||||||
|
result := []string{"a", "A", "1", "b", "B", "2", "c", "C", "3"} |
||||||
|
piscine.AdvancedSortWordTab(result, piscine.Compare) |
||||||
|
|
||||||
|
fmt.Println(result) |
||||||
|
} |
||||||
|
``` |
||||||
|
|
||||||
|
And its output : |
||||||
|
|
||||||
|
```console |
||||||
|
student@ubuntu:~/piscine/test$ go build |
||||||
|
student@ubuntu:~/piscine/test$ ./test |
||||||
|
[1 2 3 A B C a b c] |
||||||
|
student@ubuntu:~/piscine/test$ |
||||||
|
``` |
@ -0,0 +1,42 @@ |
|||||||
|
## advancedsortwordarr |
||||||
|
|
||||||
|
### Instructions |
||||||
|
|
||||||
|
Écrire une fonction `AdvancedSortWordArr` qui trie un tableau de `string`, basé sur la fonction `f` passée en paramètre. |
||||||
|
|
||||||
|
### Fonction attendue |
||||||
|
|
||||||
|
```go |
||||||
|
func AdvancedSortWordTab(array []string, f func(a, b string) int) { |
||||||
|
} |
||||||
|
``` |
||||||
|
|
||||||
|
### Utilisation |
||||||
|
|
||||||
|
Voici un éventuel [programme](TODO-LINK) pour tester votre fonction : |
||||||
|
|
||||||
|
```go |
||||||
|
package main |
||||||
|
|
||||||
|
import ( |
||||||
|
"fmt" |
||||||
|
piscine ".." |
||||||
|
) |
||||||
|
|
||||||
|
func main() { |
||||||
|
|
||||||
|
result := []string{"a", "A", "1", "b", "B", "2", "c", "C", "3"} |
||||||
|
piscine.AdvancedSortWordTab(result, piscine.Compare) |
||||||
|
|
||||||
|
fmt.Println(result) |
||||||
|
} |
||||||
|
``` |
||||||
|
|
||||||
|
Et son résultat : |
||||||
|
|
||||||
|
```console |
||||||
|
student@ubuntu:~/piscine/test$ go build |
||||||
|
student@ubuntu:~/piscine/test$ ./test |
||||||
|
[1 2 3 A B C a b c] |
||||||
|
student@ubuntu:~/piscine/test$ |
||||||
|
``` |
@ -0,0 +1 @@ |
|||||||
|
## advancedsortwordtab |
@ -0,0 +1,29 @@ |
|||||||
|
## alphamirror |
||||||
|
|
||||||
|
### Instructions |
||||||
|
|
||||||
|
Write a program called alphamirror that takes a string as argument and displays this string |
||||||
|
after replacing each alphabetical character with the opposite alphabetical |
||||||
|
character. |
||||||
|
|
||||||
|
The case of the letter stays the same, for example : |
||||||
|
|
||||||
|
'a' becomes 'z', 'Z' becomes 'A' |
||||||
|
'd' becomes 'w', 'M' becomes 'N' |
||||||
|
|
||||||
|
The final result will be followed by a newline. |
||||||
|
|
||||||
|
If the number of arguments is not 1, the program will display only a newline. |
||||||
|
|
||||||
|
Example of output : |
||||||
|
|
||||||
|
```console |
||||||
|
student@ubuntu:~/student/alphamirror$ go build |
||||||
|
student@ubuntu:~/student/alphamirror$ ./alphamirror "abc" |
||||||
|
zyx |
||||||
|
student@ubuntu:~/student/alphamirror$ ./alphamirror "My horse is Amazing." | cat -e |
||||||
|
Nb slihv rh Znzarmt.$ |
||||||
|
student@ubuntu:~/student/alphamirror$ ./alphamirror | cat -e |
||||||
|
$ |
||||||
|
student@ubuntu:~/student/alphamirror$ |
||||||
|
``` |
@ -0,0 +1,48 @@ |
|||||||
|
## any |
||||||
|
|
||||||
|
### Instructions |
||||||
|
|
||||||
|
Write a function `Any` that returns `true`, for a `string` array: |
||||||
|
|
||||||
|
- if, when that `string` array is passed through an `f` function, at least one element returns `true`. |
||||||
|
|
||||||
|
### Expected function |
||||||
|
|
||||||
|
```go |
||||||
|
func Any(f func(string) bool, arr []string) bool { |
||||||
|
} |
||||||
|
``` |
||||||
|
|
||||||
|
### Usage |
||||||
|
|
||||||
|
Here is a possible [program](TODO-LINK) to test your function : |
||||||
|
|
||||||
|
```go |
||||||
|
package main |
||||||
|
|
||||||
|
import ( |
||||||
|
"fmt" |
||||||
|
piscine ".." |
||||||
|
) |
||||||
|
|
||||||
|
func main() { |
||||||
|
tab1 := []string{"Hello", "how", "are", "you"} |
||||||
|
tab2 := []string{"This", "is", "4", "you"} |
||||||
|
|
||||||
|
result1 := piscine.Any(piscine.IsNumeric, tab1) |
||||||
|
result2 := piscine.Any(piscine.IsNumeric, tab2) |
||||||
|
|
||||||
|
fmt.Println(result1) |
||||||
|
fmt.Println(result2) |
||||||
|
} |
||||||
|
``` |
||||||
|
|
||||||
|
And its output : |
||||||
|
|
||||||
|
```console |
||||||
|
student@ubuntu:~/piscine/test$ go build |
||||||
|
student@ubuntu:~/piscine/test$ ./test |
||||||
|
false |
||||||
|
true |
||||||
|
student@ubuntu:~/piscine/test$ |
||||||
|
``` |
@ -0,0 +1,48 @@ |
|||||||
|
## any |
||||||
|
|
||||||
|
### Instructions |
||||||
|
|
||||||
|
Écrire une fonction `Any` qui retournes `true`, pour un tableau de `string`: |
||||||
|
|
||||||
|
- si, lorsque ce tableau de `string` est passé à travers une fonction `f`, au moins un element retournes `true`. |
||||||
|
|
||||||
|
### Fonction attendue |
||||||
|
|
||||||
|
```go |
||||||
|
func Any(f func(string) bool, arr []string) bool { |
||||||
|
} |
||||||
|
``` |
||||||
|
|
||||||
|
### Utilisation |
||||||
|
|
||||||
|
Voici un éventuel [programme](TODO-LINK) pour tester votre fonction : |
||||||
|
|
||||||
|
```go |
||||||
|
package main |
||||||
|
|
||||||
|
import ( |
||||||
|
"fmt" |
||||||
|
piscine ".." |
||||||
|
) |
||||||
|
|
||||||
|
func main() { |
||||||
|
tab1 := []string{"Hello", "how", "are", "you"} |
||||||
|
tab2 := []string{"This", "is", "4", "you"} |
||||||
|
|
||||||
|
result1 := piscine.Any(piscine.IsNumeric, tab1) |
||||||
|
result2 := piscine.Any(piscine.IsNumeric, tab2) |
||||||
|
|
||||||
|
fmt.Println(result1) |
||||||
|
fmt.Println(result2) |
||||||
|
} |
||||||
|
``` |
||||||
|
|
||||||
|
Et son résultat : |
||||||
|
|
||||||
|
```console |
||||||
|
student@ubuntu:~/piscine/test$ go build |
||||||
|
student@ubuntu:~/piscine/test$ ./test |
||||||
|
false |
||||||
|
true |
||||||
|
student@ubuntu:~/piscine/test$ |
||||||
|
``` |
@ -0,0 +1,48 @@ |
|||||||
|
## appendrange |
||||||
|
|
||||||
|
### Instructions |
||||||
|
|
||||||
|
Write a function that takes an `int` min and an `int` max as parameters. |
||||||
|
That function returns a slice of `int` with all the values between min and max. |
||||||
|
|
||||||
|
Min is included, and max is excluded. |
||||||
|
|
||||||
|
If min is superior or equal to max, a `nil` slice is returned. |
||||||
|
|
||||||
|
`make` is not allowed for this exercise. |
||||||
|
|
||||||
|
### Expected function |
||||||
|
|
||||||
|
```go |
||||||
|
func AppendRange(min, max int) []int { |
||||||
|
|
||||||
|
} |
||||||
|
``` |
||||||
|
|
||||||
|
### Usage |
||||||
|
|
||||||
|
Here is a possible [program](TODO-LINK) to test your function : |
||||||
|
|
||||||
|
```go |
||||||
|
package main |
||||||
|
|
||||||
|
import ( |
||||||
|
"fmt" |
||||||
|
piscine ".." |
||||||
|
) |
||||||
|
|
||||||
|
func main() { |
||||||
|
fmt.Println(piscine.AppendRange(5, 10)) |
||||||
|
fmt.Println(piscine.AppendRange(10, 5)) |
||||||
|
} |
||||||
|
``` |
||||||
|
|
||||||
|
And its output : |
||||||
|
|
||||||
|
```console |
||||||
|
student@ubuntu:~/piscine/test$ go build |
||||||
|
student@ubuntu:~/piscine/test$ ./test |
||||||
|
[5 6 7 8 9] |
||||||
|
[] |
||||||
|
student@ubuntu:~/piscine/test$ |
||||||
|
``` |
@ -0,0 +1,47 @@ |
|||||||
|
## appendrange |
||||||
|
|
||||||
|
### Instructions |
||||||
|
|
||||||
|
Écrire une fonction qui prend un `int` minimum et un `int` maximum comme paramètres. Cette fonction retournes une slice d'`int` avec toutes les valeurs comprises entre le minimum et le maximum. |
||||||
|
|
||||||
|
Le minimum est inclus, le maximum est exclu. |
||||||
|
|
||||||
|
Si le minimum est supérieur ou égal au maximum, une slice `nil` est retournée. |
||||||
|
|
||||||
|
`make` n'est pas autorisé pour cet exercice. |
||||||
|
|
||||||
|
### Fonction attendue |
||||||
|
|
||||||
|
```go |
||||||
|
func AppendRange(min, max int) []int { |
||||||
|
|
||||||
|
} |
||||||
|
``` |
||||||
|
|
||||||
|
### Utilisation |
||||||
|
|
||||||
|
Voici un éventuel [programme](TODO-LINK) pour tester votre fonction : |
||||||
|
|
||||||
|
```go |
||||||
|
package main |
||||||
|
|
||||||
|
import ( |
||||||
|
"fmt" |
||||||
|
piscine ".." |
||||||
|
) |
||||||
|
|
||||||
|
func main() { |
||||||
|
fmt.Println(piscine.AppendRange(5, 10)) |
||||||
|
fmt.Println(piscine.AppendRange(10, 5)) |
||||||
|
} |
||||||
|
``` |
||||||
|
|
||||||
|
Et son résultat : |
||||||
|
|
||||||
|
```console |
||||||
|
student@ubuntu:~/piscine/test$ go build |
||||||
|
student@ubuntu:~/piscine/test$ ./test |
||||||
|
[5 6 7 8 9] |
||||||
|
[] |
||||||
|
student@ubuntu:~/piscine/test$ |
||||||
|
``` |
@ -0,0 +1,77 @@ |
|||||||
|
## atoi |
||||||
|
|
||||||
|
### Instructions |
||||||
|
|
||||||
|
- Write a [function](TODO-LINK) that simulates the behaviour of the `Atoi` function in Go. `Atoi` transforms a number represented as a `string` in a number represented as an `int`. |
||||||
|
|
||||||
|
- Atoi returns `0` if the `string` is not considered as a valid number. For this exercise **non-valid `string` chains will be tested**. Some will contain non-digits characters. |
||||||
|
|
||||||
|
- For this exercise the handling of the signs + or - **does have** to be taken into account. |
||||||
|
|
||||||
|
- This function will **only** have to return the `int` `nbr`. For this exercise the `error` return of atoi is not required. |
||||||
|
|
||||||
|
### Format required |
||||||
|
|
||||||
|
```go |
||||||
|
func Atoi(s string) int { |
||||||
|
|
||||||
|
} |
||||||
|
``` |
||||||
|
|
||||||
|
### Usage |
||||||
|
|
||||||
|
Here is a possible [program](TODO-LINK) to test your function : |
||||||
|
|
||||||
|
```go |
||||||
|
package main |
||||||
|
|
||||||
|
import ( |
||||||
|
"fmt" |
||||||
|
piscine ".." |
||||||
|
) |
||||||
|
|
||||||
|
func main() { |
||||||
|
s := "12345" |
||||||
|
s2 := "0000000012345" |
||||||
|
s3 := "012 345" |
||||||
|
s4 := "Hello World!" |
||||||
|
s5 := "+1234" |
||||||
|
s6 := "-1234" |
||||||
|
s7 := "++1234" |
||||||
|
s8 := "--1234" |
||||||
|
|
||||||
|
n := piscine.Atoi(s) |
||||||
|
n2 := piscine.Atoi(s2) |
||||||
|
n3 := piscine.Atoi(s3) |
||||||
|
n4 := piscine.Atoi(s4) |
||||||
|
n5 := piscine.Atoi(s5) |
||||||
|
n6 := piscine.Atoi(s6) |
||||||
|
n7 := piscine.Atoi(s7) |
||||||
|
n8 := piscine.Atoi(s8) |
||||||
|
|
||||||
|
fmt.Println(n) |
||||||
|
fmt.Println(n2) |
||||||
|
fmt.Println(n3) |
||||||
|
fmt.Println(n4) |
||||||
|
fmt.Println(n5) |
||||||
|
fmt.Println(n6) |
||||||
|
fmt.Println(n7) |
||||||
|
fmt.Println(n8) |
||||||
|
} |
||||||
|
``` |
||||||
|
|
||||||
|
And its output : |
||||||
|
|
||||||
|
```console |
||||||
|
student@ubuntu:~/piscine/test$ go build |
||||||
|
student@ubuntu:~/piscine/test$ ./test |
||||||
|
12345 |
||||||
|
12345 |
||||||
|
0 |
||||||
|
0 |
||||||
|
1234 |
||||||
|
-1234 |
||||||
|
0 |
||||||
|
0 |
||||||
|
student@ubuntu:~/piscine/test$ |
||||||
|
``` |
@ -0,0 +1,77 @@ |
|||||||
|
## atoi |
||||||
|
|
||||||
|
### Instructions |
||||||
|
|
||||||
|
- Écrire une fonction qui reproduit le comportement de la fonction atoi en Go. Atoi transforme un nombre représenté en `string` (chaîne de caractères) en `int` (entier). |
||||||
|
|
||||||
|
- Atoi retourne `0` si la `string` n'est pas considéré un nombre valide. Pour cet exercice des **`string` non valides seront testées!**. Certaines contiendront d'autres charactères que des chiffres. |
||||||
|
|
||||||
|
- Pour cet exercice la gestion des signes + ou - **doit être** prise en compte. |
||||||
|
|
||||||
|
- Cette fonction aura **seulement** à retourner l'`int` (entier) `nbr`. Pour cet exercice le retour d'erreur d'atoi de go n'est pas demandé. |
||||||
|
|
||||||
|
### Fonction attendue |
||||||
|
|
||||||
|
```go |
||||||
|
func Atoi(s string) int { |
||||||
|
|
||||||
|
} |
||||||
|
``` |
||||||
|
|
||||||
|
### Utilisation |
||||||
|
|
||||||
|
Voici un éventuel [programme](TODO-LINK) pour tester votre fonction : |
||||||
|
|
||||||
|
```go |
||||||
|
package main |
||||||
|
|
||||||
|
import ( |
||||||
|
"fmt" |
||||||
|
piscine ".." |
||||||
|
) |
||||||
|
|
||||||
|
func main() { |
||||||
|
s := "12345" |
||||||
|
s2 := "0000000012345" |
||||||
|
s3 := "012 345" |
||||||
|
s4 := "Hello World!" |
||||||
|
s5 := "+1234" |
||||||
|
s6 := "-1234" |
||||||
|
s7 := "++1234" |
||||||
|
s8 := "--1234" |
||||||
|
|
||||||
|
n := piscine.Atoi(s) |
||||||
|
n2 := piscine.Atoi(s2) |
||||||
|
n3 := piscine.Atoi(s3) |
||||||
|
n4 := piscine.Atoi(s4) |
||||||
|
n5 := piscine.Atoi(s5) |
||||||
|
n6 := piscine.Atoi(s6) |
||||||
|
n7 := piscine.Atoi(s7) |
||||||
|
n8 := piscine.Atoi(s8) |
||||||
|
|
||||||
|
fmt.Println(n) |
||||||
|
fmt.Println(n2) |
||||||
|
fmt.Println(n3) |
||||||
|
fmt.Println(n4) |
||||||
|
fmt.Println(n5) |
||||||
|
fmt.Println(n6) |
||||||
|
fmt.Println(n7) |
||||||
|
fmt.Println(n8) |
||||||
|
} |
||||||
|
``` |
||||||
|
|
||||||
|
Et son résultat : |
||||||
|
|
||||||
|
```console |
||||||
|
student@ubuntu:~/piscine/test$ go build |
||||||
|
student@ubuntu:~/piscine/test$ ./test |
||||||
|
12345 |
||||||
|
12345 |
||||||
|
0 |
||||||
|
0 |
||||||
|
1234 |
||||||
|
-1234 |
||||||
|
0 |
||||||
|
0 |
||||||
|
student@ubuntu:~/piscine/test$ |
||||||
|
``` |
@ -0,0 +1,59 @@ |
|||||||
|
## atoibase |
||||||
|
|
||||||
|
### Instructions |
||||||
|
|
||||||
|
Write a function that takes a `string` number and its `string` base in parameters and returns its conversion as an `int`. |
||||||
|
|
||||||
|
If the base or the `string` number is not valid it returns `0`: |
||||||
|
|
||||||
|
Validity rules for a base : |
||||||
|
|
||||||
|
- A base must contain at least 2 characters. |
||||||
|
- Each character of a base must be unique. |
||||||
|
- A base should not contain `+` or `-` characters. |
||||||
|
|
||||||
|
Only valid `string` numbers will be tested. |
||||||
|
|
||||||
|
The function **does not have** to manage negative numbers. |
||||||
|
|
||||||
|
### Expected function |
||||||
|
|
||||||
|
```go |
||||||
|
func AtoiBase(s string, base string) int { |
||||||
|
|
||||||
|
} |
||||||
|
``` |
||||||
|
|
||||||
|
### Usage |
||||||
|
|
||||||
|
Here is a possible [program](TODO-LINK) to test your function : |
||||||
|
|
||||||
|
```go |
||||||
|
package main |
||||||
|
|
||||||
|
import ( |
||||||
|
"fmt" |
||||||
|
piscine ".." |
||||||
|
) |
||||||
|
|
||||||
|
func main() { |
||||||
|
fmt.Println(piscine.AtoiBase("125", "0123456789")) |
||||||
|
fmt.Println(piscine.AtoiBase("1111101", "01")) |
||||||
|
fmt.Println(piscine.AtoiBase("7D", "0123456789ABCDEF")) |
||||||
|
fmt.Println(piscine.AtoiBase("uoi", "choumi")) |
||||||
|
fmt.Println(piscine.AtoiBase("bbbbbab", "-ab") |
||||||
|
} |
||||||
|
``` |
||||||
|
|
||||||
|
And its output : |
||||||
|
|
||||||
|
```console |
||||||
|
student@ubuntu:~/piscine/test$ go build |
||||||
|
student@ubuntu:~/piscine/test$ ./test |
||||||
|
125 |
||||||
|
125 |
||||||
|
125 |
||||||
|
125 |
||||||
|
0 |
||||||
|
student@ubuntu:~/piscine/test$ |
||||||
|
``` |
@ -0,0 +1,59 @@ |
|||||||
|
## atoibase |
||||||
|
|
||||||
|
### Instructions |
||||||
|
|
||||||
|
Écrire une fonction qui prend un nombre `string` et sa base `string` en paramètres et retournes sa convertion en `int`. |
||||||
|
|
||||||
|
Si la base n'est pas valide elle retournes `0`: |
||||||
|
|
||||||
|
Régles de validité d'une base : |
||||||
|
|
||||||
|
- Une base doit contenir au moins 2 charactères. |
||||||
|
- Chaque charactère d'une base doit être unique. |
||||||
|
- Une base ne doit pas contenir les charactères `+` ou `-`. |
||||||
|
|
||||||
|
Seuls des nombres en `string` valides seront testés. |
||||||
|
|
||||||
|
La fonction **ne doit pas** gérer les nombres négatifs. |
||||||
|
|
||||||
|
### Fonction attendue |
||||||
|
|
||||||
|
```go |
||||||
|
func AtoiBase(s string, base string) int { |
||||||
|
|
||||||
|
} |
||||||
|
``` |
||||||
|
|
||||||
|
### Utilisation |
||||||
|
|
||||||
|
Voici un éventuel [programme](TODO-LINK) pour tester votre fonction : |
||||||
|
|
||||||
|
```go |
||||||
|
package main |
||||||
|
|
||||||
|
import ( |
||||||
|
"fmt" |
||||||
|
piscine ".." |
||||||
|
) |
||||||
|
|
||||||
|
func main() { |
||||||
|
fmt.Println(piscine.AtoiBase("125", "0123456789")) |
||||||
|
fmt.Println(piscine.AtoiBase("1111101", "01")) |
||||||
|
fmt.Println(piscine.AtoiBase("7D", "0123456789ABCDEF")) |
||||||
|
fmt.Println(piscine.AtoiBase("uoi", "choumi")) |
||||||
|
fmt.Println(piscine.AtoiBase("bbbbbab", "-ab") |
||||||
|
} |
||||||
|
``` |
||||||
|
|
||||||
|
Et son résultat : |
||||||
|
|
||||||
|
```console |
||||||
|
student@ubuntu:~/piscine/test$ go build |
||||||
|
student@ubuntu:~/piscine/test$ ./test |
||||||
|
125 |
||||||
|
125 |
||||||
|
125 |
||||||
|
125 |
||||||
|
0 |
||||||
|
student@ubuntu:~/piscine/test$ |
||||||
|
``` |
@ -0,0 +1,57 @@ |
|||||||
|
## basicatoi |
||||||
|
|
||||||
|
### Instructions |
||||||
|
|
||||||
|
- Write a function that simulates the behaviour of the atoi function in Go. Atoi transforms a number defined as a `string` in a number defined as an `int`. |
||||||
|
|
||||||
|
- Atoi returns `0` if the `string` is not considered as a valid number. For this exercise **only valid** `string` chains will be tested. They will only contain one or several digits as characters. |
||||||
|
|
||||||
|
- For this exercise the handling of the signs + or - does not have to be taken into account. |
||||||
|
|
||||||
|
- This function will **only** have to return the `int` `nbr`. For this exercise the `error` return of atoi is not required. |
||||||
|
|
||||||
|
### Expected function |
||||||
|
|
||||||
|
```go |
||||||
|
func BasicAtoi(s string) int { |
||||||
|
|
||||||
|
} |
||||||
|
``` |
||||||
|
|
||||||
|
### Usage |
||||||
|
|
||||||
|
Here is a possible [program](TODO-LINK) to test your function : |
||||||
|
|
||||||
|
```go |
||||||
|
package main |
||||||
|
|
||||||
|
import ( |
||||||
|
"fmt" |
||||||
|
piscine ".." |
||||||
|
) |
||||||
|
|
||||||
|
func main() { |
||||||
|
s := "12345" |
||||||
|
s2 := "0000000012345" |
||||||
|
s3 := "000000" |
||||||
|
|
||||||
|
n := piscine.BasicAtoi(s) |
||||||
|
n2 := piscine.BasicAtoi(s2) |
||||||
|
n3 := piscine.BasicAtoi(s3) |
||||||
|
|
||||||
|
fmt.Println(n) |
||||||
|
fmt.Println(n2) |
||||||
|
fmt.Println(n3) |
||||||
|
} |
||||||
|
``` |
||||||
|
|
||||||
|
And its output : |
||||||
|
|
||||||
|
```console |
||||||
|
student@ubuntu:~/piscine/test$ go build |
||||||
|
student@ubuntu:~/piscine/test$ ./test |
||||||
|
12345 |
||||||
|
12345 |
||||||
|
0 |
||||||
|
student@ubuntu:~/piscine/test$ |
||||||
|
``` |
@ -0,0 +1,57 @@ |
|||||||
|
## basicatoi |
||||||
|
|
||||||
|
### Instructions |
||||||
|
|
||||||
|
- Écrire une fonction qui reproduit le comportement de la fonction atoi en Go. Atoi transforme un nombre représenté en `string` (chaîne de caractères) en `int` (entier). |
||||||
|
|
||||||
|
- Atoi retourne `0` si la `string` n'est pas considéré un nombre valide. Pour cet exercice **seulement des** `string` **valides** seront testé. Elles ne contiendront que un ou plusieurs chiffres comme charact. |
||||||
|
|
||||||
|
- Pour cet exercice la gestion des signes + ou - ne doit pas être prise en compte. |
||||||
|
|
||||||
|
- Cette fonction aura **seulement** à retourner l'`int` (entier) `nbr`. Pour cet exercice le retour d'erreur d'atoi de go n'est pas demandé. |
||||||
|
|
||||||
|
### Fonction attendue |
||||||
|
|
||||||
|
```go |
||||||
|
func BasicAtoi(s string) int { |
||||||
|
|
||||||
|
} |
||||||
|
``` |
||||||
|
|
||||||
|
### Utilisation |
||||||
|
|
||||||
|
Voici un éventuel [programme](TODO-LINK) pour tester votre fonction : |
||||||
|
|
||||||
|
```go |
||||||
|
package main |
||||||
|
|
||||||
|
import ( |
||||||
|
"fmt" |
||||||
|
piscine ".." |
||||||
|
) |
||||||
|
|
||||||
|
func main() { |
||||||
|
s := "12345" |
||||||
|
s2 := "0000000012345" |
||||||
|
s3 := "000000" |
||||||
|
|
||||||
|
n := piscine.BasicAtoi(s) |
||||||
|
n2 := piscine.BasicAtoi(s2) |
||||||
|
n3 := piscine.BasicAtoi(s3) |
||||||
|
|
||||||
|
fmt.Println(n) |
||||||
|
fmt.Println(n2) |
||||||
|
fmt.Println(n3) |
||||||
|
} |
||||||
|
``` |
||||||
|
|
||||||
|
Et son résultat : |
||||||
|
|
||||||
|
```console |
||||||
|
student@ubuntu:~/piscine/test$ go build |
||||||
|
student@ubuntu:~/piscine/test$ ./test |
||||||
|
12345 |
||||||
|
12345 |
||||||
|
0 |
||||||
|
student@ubuntu:~/piscine/test$ |
||||||
|
``` |
@ -0,0 +1,62 @@ |
|||||||
|
## basicatoi2 |
||||||
|
|
||||||
|
### Instructions |
||||||
|
|
||||||
|
- Write a function that simulates the behaviour of the atoi function in Go. Atoi transforms a number defined as a `string` in a number defined as an `int`. |
||||||
|
|
||||||
|
- Atoi returns `0` if the `string` is not considered as a valid number. For this exercise **non-valid `string` chains will be tested**. Some will contain non-digits characters. |
||||||
|
|
||||||
|
- For this exercise the handling of the signs + or - does not have to be taken into account. |
||||||
|
|
||||||
|
- This function will **only** have to return the `int` `nbr`. For this exercise the `error` return of atoi is not required. |
||||||
|
|
||||||
|
### Expected Function |
||||||
|
|
||||||
|
```go |
||||||
|
func BasicAtoi2(s string) int { |
||||||
|
|
||||||
|
} |
||||||
|
``` |
||||||
|
|
||||||
|
### Usage |
||||||
|
|
||||||
|
Here is a possible [program](TODO-LINK) to test your function : |
||||||
|
|
||||||
|
```go |
||||||
|
package main |
||||||
|
|
||||||
|
import ( |
||||||
|
"fmt" |
||||||
|
piscine ".." |
||||||
|
) |
||||||
|
|
||||||
|
func main() { |
||||||
|
s := "12345" |
||||||
|
s2 := "0000000012345" |
||||||
|
s3 := "012 345" |
||||||
|
s4 := "Hello World!" |
||||||
|
|
||||||
|
n := piscine.BasicAtoi2(s) |
||||||
|
n2 := piscine.BasicAtoi2(s2) |
||||||
|
n3 := piscine.BasicAtoi2(s3) |
||||||
|
n4 := piscine.BasicAtoi2(s4) |
||||||
|
|
||||||
|
fmt.Println(n) |
||||||
|
fmt.Println(n2) |
||||||
|
fmt.Println(n3) |
||||||
|
fmt.Println(n4) |
||||||
|
|
||||||
|
} |
||||||
|
``` |
||||||
|
|
||||||
|
And its output : |
||||||
|
|
||||||
|
```console |
||||||
|
student@ubuntu:~/piscine/test$ go build |
||||||
|
student@ubuntu:~/piscine/test$ ./test |
||||||
|
12345 |
||||||
|
12345 |
||||||
|
0 |
||||||
|
0 |
||||||
|
student@ubuntu:~/piscine/test$ |
||||||
|
``` |
@ -0,0 +1,62 @@ |
|||||||
|
## basicatoi2 |
||||||
|
|
||||||
|
### Instructions |
||||||
|
|
||||||
|
- Écrire une fonction qui reproduit le comportement de la fonction atoi en Go. Atoi transforme un nombre représenté en `string` (chaîne de caractères) en `int` (entier). |
||||||
|
|
||||||
|
- Atoi retourne `0` si la `string` n'est pas considéré un nombre valide. Pour cet exercice des **`string` non valides seront testées!**. Certaines contiendront d'autres charactères que des chiffres. |
||||||
|
|
||||||
|
- Pour cet exercice la gestion des signes + ou - ne doit pas être prise en compte. |
||||||
|
|
||||||
|
- Cette fonction aura **seulement** à retourner l'`int` (entier) `nbr`. Pour cet exercice le retour d'erreur d'atoi de go n'est pas demandé. |
||||||
|
|
||||||
|
### Fonction attendue |
||||||
|
|
||||||
|
```go |
||||||
|
func BasicAtoi2(s string) int { |
||||||
|
|
||||||
|
} |
||||||
|
``` |
||||||
|
|
||||||
|
### Utilisation |
||||||
|
|
||||||
|
Voici un éventuel [programme](TODO-LINK) pour tester votre fonction : |
||||||
|
|
||||||
|
```go |
||||||
|
package main |
||||||
|
|
||||||
|
import ( |
||||||
|
"fmt" |
||||||
|
piscine ".." |
||||||
|
) |
||||||
|
|
||||||
|
func main() { |
||||||
|
s := "12345" |
||||||
|
s2 := "0000000012345" |
||||||
|
s3 := "012 345" |
||||||
|
s4 := "Hello World!" |
||||||
|
|
||||||
|
n := piscine.BasicAtoi2(s) |
||||||
|
n2 := piscine.BasicAtoi2(s2) |
||||||
|
n3 := piscine.BasicAtoi2(s3) |
||||||
|
n4 := piscine.BasicAtoi2(s4) |
||||||
|
|
||||||
|
fmt.Println(n) |
||||||
|
fmt.Println(n2) |
||||||
|
fmt.Println(n3) |
||||||
|
fmt.Println(n4) |
||||||
|
|
||||||
|
} |
||||||
|
``` |
||||||
|
|
||||||
|
Et son résultat : |
||||||
|
|
||||||
|
```console |
||||||
|
student@ubuntu:~/piscine/test$ go build |
||||||
|
student@ubuntu:~/piscine/test$ ./test |
||||||
|
12345 |
||||||
|
12345 |
||||||
|
0 |
||||||
|
0 |
||||||
|
student@ubuntu:~/piscine/test$ |
||||||
|
``` |
@ -0,0 +1,40 @@ |
|||||||
|
## basicjoin |
||||||
|
|
||||||
|
### Instructions |
||||||
|
|
||||||
|
Write a function that returns the concatenation of all the `string` of a table of `string` passed in argument. |
||||||
|
|
||||||
|
### Expected function |
||||||
|
|
||||||
|
```go |
||||||
|
func basicJoin(strs []string) string { |
||||||
|
|
||||||
|
} |
||||||
|
``` |
||||||
|
|
||||||
|
### Usage |
||||||
|
|
||||||
|
Here is a possible [program](TODO-LINK) to test your function : |
||||||
|
|
||||||
|
```go |
||||||
|
package main |
||||||
|
|
||||||
|
import ( |
||||||
|
"fmt" |
||||||
|
piscine ".." |
||||||
|
) |
||||||
|
|
||||||
|
func main() { |
||||||
|
toConcat := []string{"Hello!", " How", " are", " you?"} |
||||||
|
fmt.Println(piscine.BasicJoin(toConcat)) |
||||||
|
} |
||||||
|
``` |
||||||
|
|
||||||
|
And its output : |
||||||
|
|
||||||
|
```console |
||||||
|
student@ubuntu:~/piscine/test$ go build |
||||||
|
student@ubuntu:~/piscine/test$ ./test |
||||||
|
Hello! How are you? |
||||||
|
student@ubuntu:~/piscine/test$ |
||||||
|
``` |
@ -0,0 +1,40 @@ |
|||||||
|
## basicjoin |
||||||
|
|
||||||
|
### Instructions |
||||||
|
|
||||||
|
Écrire une fonction qui retourne la concaténation de toutes les `string` d'un slice de `string` passées en paramètres. |
||||||
|
|
||||||
|
### Fonction attendue |
||||||
|
|
||||||
|
```go |
||||||
|
func BasicJoin(strs []string) string { |
||||||
|
|
||||||
|
} |
||||||
|
``` |
||||||
|
|
||||||
|
### Utilisation |
||||||
|
|
||||||
|
Voici un éventuel [programme](TODO-LINK) pour tester votre fonction : |
||||||
|
|
||||||
|
```go |
||||||
|
package main |
||||||
|
|
||||||
|
import ( |
||||||
|
"fmt" |
||||||
|
piscine ".." |
||||||
|
) |
||||||
|
|
||||||
|
func main() { |
||||||
|
toConcat := []string{"Hello!", " How", " are", " you?"} |
||||||
|
fmt.Println(piscine.BasicJoin(toConcat)) |
||||||
|
} |
||||||
|
``` |
||||||
|
|
||||||
|
Et son résultat : |
||||||
|
|
||||||
|
```console |
||||||
|
student@ubuntu:~/piscine/test$ go build |
||||||
|
student@ubuntu:~/piscine/test$ ./test |
||||||
|
Hello! How are you? |
||||||
|
student@ubuntu:~/piscine/test$ |
||||||
|
``` |
@ -1,20 +1,20 @@ |
|||||||
# btreeapplybylevel |
## btreeapplybylevel |
||||||
## Instructions |
|
||||||
|
### Instructions |
||||||
|
|
||||||
Write a function, BTreeApplyByLevel, that applies the function given by fn to each node of the tree given by root. |
Write a function, BTreeApplyByLevel, that applies the function given by fn to each node of the tree given by root. |
||||||
|
|
||||||
This function must have the following signature. |
This function must have the following signature. |
||||||
|
|
||||||
## Expected function |
### Expected function |
||||||
|
|
||||||
```go |
```go |
||||||
func BTreeApplyByLevel(root *TreeNode, fn interface{}) { |
func BTreeApplyByLevel(root *TreeNode, fn interface{}) { |
||||||
|
|
||||||
} |
} |
||||||
|
|
||||||
``` |
``` |
||||||
|
|
||||||
## Usage |
### Usage |
||||||
|
|
||||||
Here is a possible [program](TODO-LINK) to test your function : |
Here is a possible [program](TODO-LINK) to test your function : |
||||||
|
|
@ -0,0 +1,48 @@ |
|||||||
|
## btreeinsertdata |
||||||
|
|
||||||
|
### Instructions |
||||||
|
|
||||||
|
Write a function that applies a function in order to each element in the tree |
||||||
|
(see in order tree walks) |
||||||
|
|
||||||
|
### Expected function |
||||||
|
|
||||||
|
```go |
||||||
|
func BTreeApplyInorder(root *piscine.TreeNode, f func(...interface{}) (int, error)) { |
||||||
|
|
||||||
|
} |
||||||
|
``` |
||||||
|
|
||||||
|
### Usage |
||||||
|
|
||||||
|
Here is a possible [program](TODO-LINK) to test your function : |
||||||
|
|
||||||
|
```go |
||||||
|
package main |
||||||
|
|
||||||
|
import ( |
||||||
|
"fmt" |
||||||
|
piscine "." |
||||||
|
) |
||||||
|
|
||||||
|
func main() { |
||||||
|
root := &piscine.TreeNode{Data: "4"} |
||||||
|
piscine.BTreeInsertData(root, "1") |
||||||
|
piscine.BTreeInsertData(root, "7") |
||||||
|
piscine.BTreeInsertData(root, "5") |
||||||
|
BTreeApplyInorder(root, fmt.Println) |
||||||
|
|
||||||
|
} |
||||||
|
``` |
||||||
|
|
||||||
|
And its output : |
||||||
|
|
||||||
|
```console |
||||||
|
student@ubuntu:~/piscine/btreeinsertdata$ go build |
||||||
|
student@ubuntu:~/piscine/btreeinsertdata$ ./btreeinsertdata |
||||||
|
1 |
||||||
|
4 |
||||||
|
5 |
||||||
|
7 |
||||||
|
student@ubuntu:~/piscine/btreeinsertdata$ |
||||||
|
``` |
@ -0,0 +1,47 @@ |
|||||||
|
## btreeinsertdata |
||||||
|
|
||||||
|
### Instructions |
||||||
|
|
||||||
|
Write a function that applies a function using a postorder walk to each element in the tree |
||||||
|
|
||||||
|
### Expected function |
||||||
|
|
||||||
|
```go |
||||||
|
func BTreeApplyPostorder(root *piscine.TreeNode, f func(...interface{}) (int, error)) { |
||||||
|
|
||||||
|
} |
||||||
|
``` |
||||||
|
|
||||||
|
### Usage |
||||||
|
|
||||||
|
Here is a possible [program](TODO-LINK) to test your function : |
||||||
|
|
||||||
|
```go |
||||||
|
package main |
||||||
|
|
||||||
|
import ( |
||||||
|
"fmt" |
||||||
|
piscine "." |
||||||
|
) |
||||||
|
|
||||||
|
func main() { |
||||||
|
root := &piscine.TreeNode{Data: "4"} |
||||||
|
piscine.BTreeInsertData(root, "1") |
||||||
|
piscine.BTreeInsertData(root, "7") |
||||||
|
piscine.BTreeInsertData(root, "5") |
||||||
|
BTreeApplyPostorder(root, fmt.Println) |
||||||
|
|
||||||
|
} |
||||||
|
``` |
||||||
|
|
||||||
|
And its output : |
||||||
|
|
||||||
|
```console |
||||||
|
student@ubuntu:~/piscine/btreeinsertdata$ go build |
||||||
|
student@ubuntu:~/piscine/btreeinsertdata$ ./btreeinsertdata |
||||||
|
1 |
||||||
|
5 |
||||||
|
7 |
||||||
|
4 |
||||||
|
student@ubuntu:~/piscine/btreeinsertdata$ |
||||||
|
``` |
@ -0,0 +1,47 @@ |
|||||||
|
## btreeinsertdata |
||||||
|
|
||||||
|
### Instructions |
||||||
|
|
||||||
|
Write a function that applies a function using a preorder walk to each element in the tree |
||||||
|
|
||||||
|
### Expected function |
||||||
|
|
||||||
|
```go |
||||||
|
func BTreeApplyPreorder(root *piscine.TreeNode, f func(...interface{}) (int, error)) { |
||||||
|
|
||||||
|
} |
||||||
|
``` |
||||||
|
|
||||||
|
### Usage |
||||||
|
|
||||||
|
Here is a possible [program](TODO-LINK) to test your function : |
||||||
|
|
||||||
|
```go |
||||||
|
package main |
||||||
|
|
||||||
|
import ( |
||||||
|
"fmt" |
||||||
|
piscine "." |
||||||
|
) |
||||||
|
|
||||||
|
func main() { |
||||||
|
root := &piscine.TreeNode{Data: "4"} |
||||||
|
piscine.BTreeInsertData(root, "1") |
||||||
|
piscine.BTreeInsertData(root, "7") |
||||||
|
piscine.BTreeInsertData(root, "5") |
||||||
|
BTreeApplyPreorder(root, fmt.Println) |
||||||
|
|
||||||
|
} |
||||||
|
``` |
||||||
|
|
||||||
|
And its output : |
||||||
|
|
||||||
|
```console |
||||||
|
student@ubuntu:~/piscine/btreeinsertdata$ go build |
||||||
|
student@ubuntu:~/piscine/btreeinsertdata$ ./btreeinsertdata |
||||||
|
4 |
||||||
|
1 |
||||||
|
7 |
||||||
|
5 |
||||||
|
student@ubuntu:~/piscine/btreeinsertdata$ |
||||||
|
``` |
@ -0,0 +1,52 @@ |
|||||||
|
## btreeinsertdata |
||||||
|
|
||||||
|
### Instructions |
||||||
|
|
||||||
|
Write a function that inserts new data in a binary search tree |
||||||
|
following the properties of binary search trees. |
||||||
|
The nodes must be defined as follows: |
||||||
|
|
||||||
|
### Expected function |
||||||
|
|
||||||
|
```go |
||||||
|
type TreeNode struct { |
||||||
|
Left, Right, Parent *TreeNode |
||||||
|
Data string |
||||||
|
} |
||||||
|
|
||||||
|
func BTreeInsertData(root *TreeNode, data string) *TreeNode { |
||||||
|
|
||||||
|
} |
||||||
|
``` |
||||||
|
|
||||||
|
### Usage |
||||||
|
|
||||||
|
Here is a possible [program](TODO-LINK) to test your function : |
||||||
|
|
||||||
|
```go |
||||||
|
package main |
||||||
|
|
||||||
|
func main() { |
||||||
|
root := &TreeNode{data: "4"} |
||||||
|
BTreeInsertData(root, "1") |
||||||
|
BTreeInsertData(root, "7") |
||||||
|
BTreeInsertData(root, "5") |
||||||
|
fmt.Println(root.left.data) |
||||||
|
fmt.Println(root.data) |
||||||
|
fmt.Println(root.right.left.data) |
||||||
|
fmt.Println(root.right.data) |
||||||
|
|
||||||
|
} |
||||||
|
``` |
||||||
|
|
||||||
|
And its output : |
||||||
|
|
||||||
|
```console |
||||||
|
student@ubuntu:~/piscine/btreeinsertdata$ go build |
||||||
|
student@ubuntu:~/piscine/btreeinsertdata$ ./btreeinsertdata |
||||||
|
1 |
||||||
|
4 |
||||||
|
5 |
||||||
|
7 |
||||||
|
student@ubuntu:~/piscine/btreeinsertdata$ |
||||||
|
``` |
@ -1,20 +1,20 @@ |
|||||||
# btreeisbinary |
## btreeisbinary |
||||||
## Instructions |
|
||||||
|
### Instructions |
||||||
|
|
||||||
Write a function, BTreeIsBinary, that returns true only if the tree given by root follows the binary search tree properties. |
Write a function, BTreeIsBinary, that returns true only if the tree given by root follows the binary search tree properties. |
||||||
|
|
||||||
This function must have the following signature. |
This function must have the following signature. |
||||||
|
|
||||||
## Expected function |
### Expected function |
||||||
|
|
||||||
```go |
```go |
||||||
func BTreeIsBinary(root *TreeNode) bool { |
func BTreeIsBinary(root *TreeNode) bool { |
||||||
|
|
||||||
} |
} |
||||||
|
|
||||||
``` |
``` |
||||||
|
|
||||||
## Usage |
### Usage |
||||||
|
|
||||||
Here is a possible [program](TODO-LINK) to test your function : |
Here is a possible [program](TODO-LINK) to test your function : |
||||||
|
|
@ -1,18 +1,18 @@ |
|||||||
# btreelevelcount |
## btreelevelcount |
||||||
## Instructions |
|
||||||
|
### Instructions |
||||||
|
|
||||||
Write a function, BTreeLevelCount, that return the number of levels of the tree (height of the tree) |
Write a function, BTreeLevelCount, that return the number of levels of the tree (height of the tree) |
||||||
|
|
||||||
## Expected function |
### Expected function |
||||||
|
|
||||||
```go |
```go |
||||||
func BTreeLevelCount(root *piscine.TreeNode) int { |
func BTreeLevelCount(root *piscine.TreeNode) int { |
||||||
|
|
||||||
} |
} |
||||||
|
|
||||||
``` |
``` |
||||||
|
|
||||||
## Usage |
### Usage |
||||||
|
|
||||||
Here is a possible [program](TODO-LINK) to test your function : |
Here is a possible [program](TODO-LINK) to test your function : |
||||||
|
|
@ -1,20 +1,20 @@ |
|||||||
# btreemax |
## btreemax |
||||||
## Instructions |
|
||||||
|
### Instructions |
||||||
|
|
||||||
Write a function, BTreeMax, that returns the node with the maximum value in the tree given by root |
Write a function, BTreeMax, that returns the node with the maximum value in the tree given by root |
||||||
|
|
||||||
This function must have the following signature. |
This function must have the following signature. |
||||||
|
|
||||||
## Expected function |
### Expected function |
||||||
|
|
||||||
```go |
```go |
||||||
func BTreeMax(root *TreeNode) *TreeNode { |
func BTreeMax(root *TreeNode) *TreeNode { |
||||||
|
|
||||||
} |
} |
||||||
|
|
||||||
``` |
``` |
||||||
|
|
||||||
## Usage |
### Usage |
||||||
|
|
||||||
Here is a possible [program](TODO-LINK) to test your function : |
Here is a possible [program](TODO-LINK) to test your function : |
||||||
|
|
@ -1,20 +1,20 @@ |
|||||||
# btreemin |
## btreemin |
||||||
## Instructions |
|
||||||
|
### Instructions |
||||||
|
|
||||||
Write a function, BTreeMin, that returns the node with the minimum value in the tree given by root |
Write a function, BTreeMin, that returns the node with the minimum value in the tree given by root |
||||||
|
|
||||||
This function must have the following signature. |
This function must have the following signature. |
||||||
|
|
||||||
## Expected function |
### Expected function |
||||||
|
|
||||||
```go |
```go |
||||||
func BTreeMin(root *TreeNode) *TreeNode { |
func BTreeMin(root *TreeNode) *TreeNode { |
||||||
|
|
||||||
} |
} |
||||||
|
|
||||||
``` |
``` |
||||||
|
|
||||||
## Usage |
### Usage |
||||||
|
|
||||||
Here is a possible [program](TODO-LINK) to test your function : |
Here is a possible [program](TODO-LINK) to test your function : |
||||||
|
|
@ -0,0 +1,48 @@ |
|||||||
|
## printroot |
||||||
|
|
||||||
|
### Instructions |
||||||
|
|
||||||
|
Write a function to print the value of the root node of a binary tree. |
||||||
|
You have to create a new number and print the value of data |
||||||
|
The nodes must be defined as follows: |
||||||
|
|
||||||
|
### Expected function |
||||||
|
|
||||||
|
```go |
||||||
|
type TreeNode struct { |
||||||
|
left, right *TreeNode |
||||||
|
data string |
||||||
|
} |
||||||
|
|
||||||
|
func PrintRoot(root *TreeNode){ |
||||||
|
|
||||||
|
} |
||||||
|
``` |
||||||
|
|
||||||
|
### Usage |
||||||
|
|
||||||
|
Here is a possible [program](TODO-LINK) to test your function : |
||||||
|
|
||||||
|
```go |
||||||
|
package main |
||||||
|
|
||||||
|
func main() { |
||||||
|
//rootNode initialized with the value "who" |
||||||
|
//rootNode1 initialized with the value "are" |
||||||
|
//rootNode2 initialized with the value "you" |
||||||
|
printRoot(rootNode) |
||||||
|
printRoot(rootNode1) |
||||||
|
printRoot(rootNode2) |
||||||
|
} |
||||||
|
``` |
||||||
|
|
||||||
|
And its output : |
||||||
|
|
||||||
|
```console |
||||||
|
student@ubuntu:~/piscine/printroot$ go build |
||||||
|
student@ubuntu:~/piscine/printroot$ ./printroot |
||||||
|
who |
||||||
|
are |
||||||
|
you |
||||||
|
student@ubuntu:~/piscine/test$ |
||||||
|
``` |
@ -0,0 +1,74 @@ |
|||||||
|
## btreeinsertdata |
||||||
|
|
||||||
|
### Instructions |
||||||
|
|
||||||
|
Write a function that searches for an item with a data element equal to elem and return that node |
||||||
|
|
||||||
|
### Expected function |
||||||
|
|
||||||
|
```go |
||||||
|
func BTreeSearchItem(root *piscine_test.TreeNode, elem string) *piscine_test.TreeNode { |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
``` |
||||||
|
|
||||||
|
### Usage |
||||||
|
|
||||||
|
Here is a possible [program](TODO-LINK) to test your function : |
||||||
|
|
||||||
|
```go |
||||||
|
package main |
||||||
|
|
||||||
|
import ( |
||||||
|
"fmt" |
||||||
|
piscine "." |
||||||
|
) |
||||||
|
|
||||||
|
func main() { |
||||||
|
root := &piscine_test.TreeNode{Data: "4"} |
||||||
|
piscine_test.BTreeInsertData(root, "1") |
||||||
|
piscine_test.BTreeInsertData(root, "7") |
||||||
|
piscine_test.BTreeInsertData(root, "5") |
||||||
|
selected := BTreeSearchItem(root, "7") |
||||||
|
fmt.Print("Item selected -> ") |
||||||
|
if selected != nil { |
||||||
|
fmt.Println(selected.Data) |
||||||
|
} else { |
||||||
|
fmt.Println("nil") |
||||||
|
} |
||||||
|
|
||||||
|
fmt.Print("Parent of selected item -> ") |
||||||
|
if selected.Parent != nil { |
||||||
|
fmt.Println(selected.Parent.Data) |
||||||
|
} else { |
||||||
|
fmt.Println("nil") |
||||||
|
} |
||||||
|
|
||||||
|
fmt.Print("Left child of selected item -> ") |
||||||
|
if selected.Left != nil { |
||||||
|
fmt.Println(selected.Left.Data) |
||||||
|
} else { |
||||||
|
fmt.Println("nil") |
||||||
|
} |
||||||
|
|
||||||
|
fmt.Print("Right child of selected item -> ") |
||||||
|
if selected.Right != nil { |
||||||
|
fmt.Println(selected.Right.Data) |
||||||
|
} else { |
||||||
|
fmt.Println("nil") |
||||||
|
} |
||||||
|
} |
||||||
|
``` |
||||||
|
|
||||||
|
And its output : |
||||||
|
|
||||||
|
```console |
||||||
|
student@ubuntu:~/piscine/btreesearchitem$ go build |
||||||
|
student@ubuntu:~/piscine/btreesearchitem$ ./btreesearchitem |
||||||
|
Item selected -> 7 |
||||||
|
Parent of selected item -> 4 |
||||||
|
Left child of selected item -> 5 |
||||||
|
Right child of selected item -> nil |
||||||
|
student@ubuntu:~/piscine/btreesearchitem$ |
||||||
|
``` |
@ -1,20 +1,20 @@ |
|||||||
# btreetransplant |
## btreetransplant |
||||||
## Instructions |
|
||||||
|
### Instructions |
||||||
|
|
||||||
In order to move subtrees around within the binary search tree, write a function, BTreeTransplant, which replaces the subtree started by node with the node called 'rplc' in the tree given by root. |
In order to move subtrees around within the binary search tree, write a function, BTreeTransplant, which replaces the subtree started by node with the node called 'rplc' in the tree given by root. |
||||||
|
|
||||||
This function must have the following signature. |
This function must have the following signature. |
||||||
|
|
||||||
## Expected function |
### Expected function |
||||||
|
|
||||||
```go |
```go |
||||||
func BTreeTransplant(root, node, rplc *TreeNode) *TreeNode { |
func BTreeTransplant(root, node, rplc *TreeNode) *TreeNode { |
||||||
|
|
||||||
} |
} |
||||||
|
|
||||||
``` |
``` |
||||||
|
|
||||||
## Usage |
### Usage |
||||||
|
|
||||||
Here is a possible [program](TODO-LINK) to test your function : |
Here is a possible [program](TODO-LINK) to test your function : |
||||||
|
|
@ -0,0 +1,41 @@ |
|||||||
|
## capitalize |
||||||
|
|
||||||
|
### Instructions |
||||||
|
|
||||||
|
Write a function that capitalizes the first letter of each word **and** lowercases the rest of each word of a `string`. |
||||||
|
|
||||||
|
A word is a sequence of **alphanumerical** characters. |
||||||
|
|
||||||
|
### Expected function |
||||||
|
|
||||||
|
```go |
||||||
|
func Capitalize(s string) string { |
||||||
|
|
||||||
|
} |
||||||
|
``` |
||||||
|
|
||||||
|
### Usage |
||||||
|
|
||||||
|
Here is a possible [program](TODO-LINK) to test your function : |
||||||
|
|
||||||
|
```go |
||||||
|
package main |
||||||
|
|
||||||
|
import ( |
||||||
|
"fmt" |
||||||
|
piscine ".." |
||||||
|
) |
||||||
|
|
||||||
|
func main() { |
||||||
|
fmt.Println(piscine.Capitalize("Hello! How are you? How+are+things+4you?")) |
||||||
|
} |
||||||
|
``` |
||||||
|
|
||||||
|
And its output : |
||||||
|
|
||||||
|
```console |
||||||
|
student@ubuntu:~/piscine/test$ go build |
||||||
|
student@ubuntu:~/piscine/test$ ./test |
||||||
|
Hello! How Are You? How+Are+Things+4you? |
||||||
|
student@ubuntu:~/piscine/test$ |
||||||
|
``` |
@ -0,0 +1,41 @@ |
|||||||
|
## capitalize |
||||||
|
|
||||||
|
### Instructions |
||||||
|
|
||||||
|
Écrire une fonction qui met en majuscule la premiere lettre de chaque mot et en minuscule les autres lettres du reste du mot d'une `string`. |
||||||
|
|
||||||
|
Un mot est une suite de caractères **alphanumériques**. |
||||||
|
|
||||||
|
### Fonction attendue |
||||||
|
|
||||||
|
```go |
||||||
|
func Capitalize(s string) string { |
||||||
|
|
||||||
|
} |
||||||
|
``` |
||||||
|
|
||||||
|
### Utilisation |
||||||
|
|
||||||
|
Voici un éventuel [programme](TODO-LINK) pour tester votre fonction : |
||||||
|
|
||||||
|
```go |
||||||
|
package main |
||||||
|
|
||||||
|
import ( |
||||||
|
"fmt" |
||||||
|
piscine ".." |
||||||
|
) |
||||||
|
|
||||||
|
func main() { |
||||||
|
fmt.Println(piscine.Capitalize("Hello! How are you? How+are+things+4you?")) |
||||||
|
} |
||||||
|
``` |
||||||
|
|
||||||
|
Et son résultat : |
||||||
|
|
||||||
|
```console |
||||||
|
student@ubuntu:~/piscine/test$ go build |
||||||
|
student@ubuntu:~/piscine/test$ ./test |
||||||
|
Hello! How Are You? How+Are+Things+4you? |
||||||
|
student@ubuntu:~/piscine/test$ |
||||||
|
``` |
@ -0,0 +1,21 @@ |
|||||||
|
## cl-camp1 |
||||||
|
|
||||||
|
### Instructions |
||||||
|
|
||||||
|
A little voice speaks in your head: |
||||||
|
|
||||||
|
"Now that you know who you are. You need to remember what you can do..." |
||||||
|
|
||||||
|
The instincts are coming back... |
||||||
|
|
||||||
|
Put in a file `mastertheLS` the command line that will: |
||||||
|
|
||||||
|
- list the files and folders of the current folder. |
||||||
|
- Ignore the hidden files, the "." and the "..". |
||||||
|
- Separates the resuls with commas. |
||||||
|
- Order them by ascending order of creation date. |
||||||
|
- Have the folders have a `/` in front of them. |
||||||
|
|
||||||
|
### Hint |
||||||
|
|
||||||
|
Read the man... |
@ -0,0 +1,21 @@ |
|||||||
|
## cl-camp1 |
||||||
|
|
||||||
|
### Instructions |
||||||
|
|
||||||
|
Une petite voix dans votre esprit vous dit: |
||||||
|
|
||||||
|
"Maintenant que tu sais qui tu es. Tu dois te souvenir de ce que tu peux faire..." |
||||||
|
|
||||||
|
Les instincts resurgissent... |
||||||
|
|
||||||
|
Mettez dans un fichier `mastertheLS` la ligne de commande qui: |
||||||
|
|
||||||
|
- listera les fichiers et dossiers dans le dossier courant. |
||||||
|
- Ignorera les fichiers cachés, le "." et le "..". |
||||||
|
- Separarera le resultat avec des virgules. |
||||||
|
- Les triera pas ordre croissant de date de création. |
||||||
|
- Placera un `/` en face des dossiers. |
||||||
|
|
||||||
|
### Indice |
||||||
|
|
||||||
|
Lisez le man... |
@ -0,0 +1,17 @@ |
|||||||
|
## cl-camp2 |
||||||
|
|
||||||
|
### Instructions |
||||||
|
|
||||||
|
"keep training ..." |
||||||
|
|
||||||
|
Create a file `r`, which shows `R` on a line when the `cat` command is executed |
||||||
|
|
||||||
|
A line is a sequence of characters preceding the [end of line](https://en.wikipedia.org/wiki/Newline) character (`'\n'`). |
||||||
|
|
||||||
|
### Usage |
||||||
|
|
||||||
|
```console |
||||||
|
student@ubuntu:~/piscine/test$ cat -e r |
||||||
|
R$ |
||||||
|
student@ubuntu:~/piscine/test$ |
||||||
|
``` |
@ -0,0 +1,17 @@ |
|||||||
|
## cl-camp2 |
||||||
|
|
||||||
|
### Instructions |
||||||
|
|
||||||
|
"Continue l'entrainement ..." |
||||||
|
|
||||||
|
Créez un fichier `r`, qui affiche `R` sur une ligne quand la commande `cat` command est exécutée. |
||||||
|
|
||||||
|
Une ligne est une suite de caractères précédant le caractère [fin de ligne](https://en.wikipedia.org/wiki/Newline) (`'\n'`). |
||||||
|
|
||||||
|
### Utilisation |
||||||
|
|
||||||
|
```console |
||||||
|
student@ubuntu:~/piscine/test$ cat -e r |
||||||
|
R$ |
||||||
|
student@ubuntu:~/piscine/test$ |
||||||
|
``` |
@ -0,0 +1,15 @@ |
|||||||
|
## cl-camp3 |
||||||
|
|
||||||
|
### Instructions |
||||||
|
|
||||||
|
"start looking ..." |
||||||
|
|
||||||
|
Create a file `look`, which will look for and show, in the current directory and its sub-folders all the files : |
||||||
|
|
||||||
|
- starting with an `a` and, |
||||||
|
- all the files ending with a `z` and, |
||||||
|
- all files starting with `z` and ending with `a!`. |
||||||
|
|
||||||
|
### Hint |
||||||
|
|
||||||
|
Read the `find` man... |
@ -0,0 +1,15 @@ |
|||||||
|
## cl-camp3 |
||||||
|
|
||||||
|
### Instructions |
||||||
|
|
||||||
|
"commences à chercher ..." |
||||||
|
|
||||||
|
Créer un fichier `look`, qui cherchera et montrera, dans le répertoire courant et ses sous-répertoires, tous les fichiers qui: |
||||||
|
|
||||||
|
- commence avec `a` et, |
||||||
|
- tous les fichiers qui se terminent avec `z` et, |
||||||
|
- tous les fichiers qui commencent avec `z` et qui se finissenLisezele man dea!`. |
||||||
|
|
||||||
|
#Indice |
||||||
|
|
||||||
|
Lisez le man de `find`... |
@ -0,0 +1,24 @@ |
|||||||
|
## cl-camp4 |
||||||
|
|
||||||
|
### Instructions |
||||||
|
|
||||||
|
"someone familiar" |
||||||
|
|
||||||
|
Create a file `myfamily.sh`, which will show a subject's family (key: relatives). |
||||||
|
|
||||||
|
- The quotes have to be removed. |
||||||
|
|
||||||
|
- The subject will be decided depending on his ID which will be contained in the environment variable HERO_ID. |
||||||
|
|
||||||
|
* Where to look : https://raw.githubusercontent.com/kigiri/superhero-api/master/api/all.json |
||||||
|
|
||||||
|
* What to use : curl, jq and others... |
||||||
|
|
||||||
|
### Usage |
||||||
|
|
||||||
|
```console |
||||||
|
student@ubuntu:~/piscine/test$ export HERO_ID=1 |
||||||
|
student@ubuntu:~/piscine/test$ ./myfamily.sh |
||||||
|
Marlo Chandler-Jones (wife); Polly (aunt); Mrs. Chandler (mother-in-law); Keith Chandler, Ray Chandler, three unidentified others (brothers-in-law); unidentified father (deceased); Jackie Shorr (alleged mother; unconfirmed) |
||||||
|
student@ubuntu:~/piscine/test$ |
||||||
|
``` |
@ -0,0 +1,24 @@ |
|||||||
|
## cl-camp4 |
||||||
|
|
||||||
|
### Instructions |
||||||
|
|
||||||
|
"quelqu'un de familier" |
||||||
|
|
||||||
|
Créer un fichier `myfamily.sh`, qui montrera qui affichera la famille d'un individu (clef: relatives). |
||||||
|
|
||||||
|
- Les guillemets doivent être enlevés. |
||||||
|
|
||||||
|
- L'invidu sera choisi en fonction de son ID qui sera contenu dans la variable d'environment HERO_ID. |
||||||
|
|
||||||
|
* Où chercher : https://raw.githubusercontent.com/kigiri/superhero-api/master/api/all.json |
||||||
|
|
||||||
|
* Quoi utiliser : `curl`, `jq` et d'autres... |
||||||
|
|
||||||
|
### Utilisation |
||||||
|
|
||||||
|
```console |
||||||
|
student@ubuntu:~/piscine/test$ export HERO_ID=1 |
||||||
|
student@ubuntu:~/piscine/test$ ./myfamily.sh |
||||||
|
Marlo Chandler-Jones (wife); Polly (aunt); Mrs. Chandler (mother-in-law); Keith Chandler, Ray Chandler, three unidentified others (brothers-in-law); unidentified father (deceased); Jackie Shorr (alleged mother; unconfirmed) |
||||||
|
student@ubuntu:~/piscine/test$ |
||||||
|
``` |
@ -0,0 +1,26 @@ |
|||||||
|
## cl-camp5 |
||||||
|
|
||||||
|
### Instructions |
||||||
|
|
||||||
|
"keep looking..." |
||||||
|
|
||||||
|
Create a file `lookagain.sh`, which will look for, from the current directory and its sub-folders all the files: |
||||||
|
|
||||||
|
- all the files ending with `.sh`. |
||||||
|
|
||||||
|
That command will only show the name of the files without the `.sh`. |
||||||
|
|
||||||
|
### Usage |
||||||
|
|
||||||
|
```console |
||||||
|
student@ubuntu:~/piscine/test$ export HERO_ID=1 |
||||||
|
student@ubuntu:~/piscine/test$ ./lookagain.sh | cat -e |
||||||
|
file1$ |
||||||
|
file2$ |
||||||
|
file3$ |
||||||
|
student@ubuntu:~/piscine/test$ |
||||||
|
``` |
||||||
|
|
||||||
|
### Hint |
||||||
|
|
||||||
|
A little `cut`ing might be useful... |
@ -0,0 +1,26 @@ |
|||||||
|
## cl-camp5 |
||||||
|
|
||||||
|
### Instructions |
||||||
|
|
||||||
|
"continues à chercher..." |
||||||
|
|
||||||
|
Créer un fichier `lookagain.sh`, qui cherchera et montrera, dans le répertoire courant et ses sous-répertoires, tous les fichiers qui: |
||||||
|
|
||||||
|
- qui finissent avec `.sh`. |
||||||
|
|
||||||
|
Cette commande montrera le nom des fichiers sans le`.sh`. |
||||||
|
|
||||||
|
### Utilisation |
||||||
|
|
||||||
|
```console |
||||||
|
student@ubuntu:~/piscine/test$ export HERO_ID=1 |
||||||
|
student@ubuntu:~/piscine/test$ ./lookagain.sh | cat -e |
||||||
|
file1$ |
||||||
|
file2$ |
||||||
|
file3$ |
||||||
|
student@ubuntu:~/piscine/test$ |
||||||
|
``` |
||||||
|
|
||||||
|
### Indice |
||||||
|
|
||||||
|
Un petit `cut`ter pourrait être utile... |
@ -0,0 +1,15 @@ |
|||||||
|
## cl-camp6 |
||||||
|
|
||||||
|
### Instructions |
||||||
|
|
||||||
|
"Now, do your inventory" |
||||||
|
|
||||||
|
Create a file `countfiles.sh`, which will print the number **(and only the number)** of regular files and folders cointaned in the current directory and its sub-folders : |
||||||
|
|
||||||
|
### Usage |
||||||
|
|
||||||
|
```console |
||||||
|
student@ubuntu:~/piscine/test$ ./countfiles.sh | cat -e |
||||||
|
12$ |
||||||
|
student@ubuntu:~/piscine/test$ |
||||||
|
``` |
@ -0,0 +1,15 @@ |
|||||||
|
## cl-camp6 |
||||||
|
|
||||||
|
### Instructions |
||||||
|
|
||||||
|
"Maintenant, fais ton inventaire" |
||||||
|
|
||||||
|
Créer un fichier `countfiles.sh`, qui affichera will lenombre **(et seulement le nombre)** de fichiers réguliers et répertoires contenu dans le répertoire courant et ses sous-répertoires : |
||||||
|
|
||||||
|
### Utilisation |
||||||
|
|
||||||
|
```console |
||||||
|
student@ubuntu:~/piscine/test$ ./countfiles.sh | cat -e |
||||||
|
12$ |
||||||
|
student@ubuntu:~/piscine/test$ |
||||||
|
``` |
@ -0,0 +1,15 @@ |
|||||||
|
## cl-camp7 |
||||||
|
|
||||||
|
### Instructions |
||||||
|
|
||||||
|
"Be accurate" |
||||||
|
|
||||||
|
Create a file `"\?$*'ChouMi'*$?\"` that will contain "01" and **nothing else**. |
||||||
|
|
||||||
|
### Usage |
||||||
|
|
||||||
|
```console |
||||||
|
student@ubuntu:~/piscine/test$ ls | cat -e |
||||||
|
"\?$*'ChouMi'*$?\" $ |
||||||
|
student@ubuntu:~/piscine/test$ |
||||||
|
``` |
@ -0,0 +1,15 @@ |
|||||||
|
## cl-camp7 |
||||||
|
|
||||||
|
### Instructions |
||||||
|
|
||||||
|
"Sois précis" |
||||||
|
|
||||||
|
Créer un fichier `"\?$*'ChouMi'*$?\"` qui contiendra "01" et **rien d'autre**. |
||||||
|
|
||||||
|
### Utilisation |
||||||
|
|
||||||
|
```console |
||||||
|
student@ubuntu:~/piscine/test$ ls | cat -e |
||||||
|
"\?$*'ChouMi'*$?\" $ |
||||||
|
student@ubuntu:~/piscine/test$ |
||||||
|
``` |
@ -0,0 +1,11 @@ |
|||||||
|
## cl-camp8 |
||||||
|
|
||||||
|
### Instructions |
||||||
|
|
||||||
|
"pick your equipment" |
||||||
|
|
||||||
|
Write a command line in a `skip.sh` file that prints the result of a `ls -l` skipping 1 line out of 2, starting with the **first** one. |
||||||
|
|
||||||
|
### Hint |
||||||
|
|
||||||
|
`awk` or `sed` can do the job. |
@ -0,0 +1,11 @@ |
|||||||
|
## cl-camp8 |
||||||
|
|
||||||
|
### Instructions |
||||||
|
|
||||||
|
"Choisis ton équipement" |
||||||
|
|
||||||
|
écrire une ligne dans un fichier `skip.sh` qui affiche le résultat d'un `ls -l` qui saute 1 ligne sur 2, en commençant pas la **première**. |
||||||
|
|
||||||
|
### Indice |
||||||
|
|
||||||
|
`awk` ou `sed` peuvent faire le travail. |
@ -0,0 +1,21 @@ |
|||||||
|
## cl-camp1 |
||||||
|
|
||||||
|
### Instructions |
||||||
|
|
||||||
|
A little voice speaks in your head: |
||||||
|
|
||||||
|
"Now that you know who you are. You need to remember what you can do..." |
||||||
|
|
||||||
|
The instincts are coming back... |
||||||
|
|
||||||
|
Put in a file `mastertheLS` the command line that will: |
||||||
|
|
||||||
|
- list the files and folders of the current folder. |
||||||
|
- Ignore the hidden files, the "." and the "..". |
||||||
|
- Separates the resuls with commas. |
||||||
|
- Order them by ascending order of creation date. |
||||||
|
- Have the folders have a `/` in front of them. |
||||||
|
|
||||||
|
### Hint |
||||||
|
|
||||||
|
Read the man... |
@ -1,20 +1,20 @@ |
|||||||
# collatzcountdown |
## collatzcountdown |
||||||
## Instructions |
|
||||||
|
### Instructions |
||||||
|
|
||||||
Write a function, CollatzCountdown, that returns the number of steps to reach 1 using the collatz countdown. |
Write a function, CollatzCountdown, that returns the number of steps to reach 1 using the collatz countdown. |
||||||
|
|
||||||
The function must have the following signature. |
The function must have the following signature. |
||||||
|
|
||||||
## Expected function |
### Expected function |
||||||
|
|
||||||
```go |
```go |
||||||
func CollatzCountdown(start int) int { |
func CollatzCountdown(start int) int { |
||||||
|
|
||||||
} |
} |
||||||
|
|
||||||
``` |
``` |
||||||
|
|
||||||
## Usage |
### Usage |
||||||
|
|
||||||
Here is a possible [program](TODO-LINK) to test your function : |
Here is a possible [program](TODO-LINK) to test your function : |
||||||
|
|
@ -1,19 +1,20 @@ |
|||||||
# ROT 14 |
## ROT 14 |
||||||
|
|
||||||
## Instructions |
### Instructions |
||||||
|
|
||||||
Write a function `rot14` that returns the string within the parameter but transformed into a rot14 string. |
Write a function `rot14` that returns the string within the parameter but transformed into a rot14 string. |
||||||
|
|
||||||
- If you not certain what we are talking about, there is a rot13 already. |
- If you not certain what we are talking about, there is a rot13 already. |
||||||
|
|
||||||
## Expected function |
### Expected function |
||||||
|
|
||||||
```go |
```go |
||||||
func rot14(str string) string { |
func rot14(str string) string { |
||||||
|
|
||||||
} |
} |
||||||
``` |
``` |
||||||
## Usage |
|
||||||
|
### Usage |
||||||
|
|
||||||
Here is a possible [program](TODO-LINK) to test your function : |
Here is a possible [program](TODO-LINK) to test your function : |
||||||
|
|
@ -0,0 +1,114 @@ |
|||||||
|
--- |
||||||
|
tier: 0 |
||||||
|
team: 1 |
||||||
|
duration: 1 hour |
||||||
|
objectives: reading the rules |
||||||
|
skills: git, github, reading |
||||||
|
--- |
||||||
|
|
||||||
|
## commandments |
||||||
|
|
||||||
|
A few basic principles to follow |
||||||
|
|
||||||
|
<p align="center"> |
||||||
|
<img width="476" height="600" src="https://upload.wikimedia.org/wikipedia/commons/thumb/e/e5/MCC-31231_Mozes_toont_de_wetstafelen_%281%29.tif/lossy-page1-476px-MCC-31231_Mozes_toont_de_wetstafelen_%281%29.tif.jpg"> |
||||||
|
</p> |
||||||
|
|
||||||
|
### The Commandements _(read them)_ |
||||||
|
|
||||||
|
- Le numérique est ta passion. |
||||||
|
|
||||||
|
- Ton objectif à 42 : développer ton talent et tes compétences pour le marché du numérique. |
||||||
|
|
||||||
|
- L’objectif de 42 pour toi : te faire accéder au marché de l’emploi, à une longue et pérenne carrière dans le numérique, et te faire progresser socialement. |
||||||
|
|
||||||
|
- L’ambition de 42 pour toi : être un pionnier du numérique de demain. |
||||||
|
|
||||||
|
- Il est de ta responsabilité de gérer ta progression : 42 te propose un parcours individualisé adapté à ton rythme. |
||||||
|
|
||||||
|
- Des challenges jalonnent ton parcours. 42 ne fournira aucun élément de solution. C’est ton rôle de chercher et trouver par toi-même ces solutions pour atteindre l’objectif. |
||||||
|
|
||||||
|
- Sois actif. N’attend pas que les choses se fassent pour toi. 42 est un parcours 100% pratique. |
||||||
|
|
||||||
|
- Sois autonome dans ton cursus. N’attend pas que l’on te dise quoi faire. |
||||||
|
|
||||||
|
- Sois collaboratif, autant sur les projets solos que les projets de groupe. Face aux challenges à resoudre, l’échange et le debat sont tes meilleures armes. |
||||||
|
|
||||||
|
- Ne "crois" pas. Sois sûr. Techniquement, relationnelement, organisationellement, administrativement. |
||||||
|
|
||||||
|
- Pour être sûr, teste, contrôle. |
||||||
|
|
||||||
|
- N’ai pas peur de te tromper, d’échouer. L’échec est une étape normale vers le succès. |
||||||
|
|
||||||
|
- Teste à nouveau. Collabore davantage pour tester davantage. |
||||||
|
|
||||||
|
- Ose. Le risque est de se tromper. Voir le commandement 12. |
||||||
|
|
||||||
|
- Sois rigoureux dans ton travail. |
||||||
|
|
||||||
|
- Sois investi dans ton cursus : 50 heures par semaine est un minimum. Ta capacité de travail est une valeur. L’école est ouverte 24h/24 et 7j/7. |
||||||
|
|
||||||
|
- Sois régulier dans ton travail. Un jour oui, un jour non, un coup nocturne, un coup diurne... le chaos t’empêche d’avancer. |
||||||
|
|
||||||
|
- Prévois un groupe de travail large et hétérogène pour y trouver facilement des idées neuves et des groupes de projet. |
||||||
|
|
||||||
|
- Pour tes collaborations et ton travail en groupe, privilégie des étudiants qui n’ont pas déjà la solution au problème. |
||||||
|
|
||||||
|
- Sois investi dans ton groupe de projet, et ne le laisse pas faire ton travail à ta place. |
||||||
|
|
||||||
|
- Ton groupe de projet est solidaire, son succès comme son échec est de la responsabilité de tous, et les conflits se règlent en interne. |
||||||
|
|
||||||
|
- Travaille à l’école. Faire du peer-learning, collaborer, cela demande d’être physiquement avec les autres. A distance cela ne fonctionne pas. |
||||||
|
|
||||||
|
- Implique toi dans les évaluations de tes projets. Elles te permettent de prendre du recul. |
||||||
|
|
||||||
|
- Implique toi dans tes évaluations des projets des autres. La qualité de la communauté en dépend. |
||||||
|
|
||||||
|
- Sois juste et teste rigoureusement tes projets comme ceux des autres en évaluation avec tes propres jeux de tests. |
||||||
|
|
||||||
|
- Joue pleinement le jeu de ta scolarité dans l’état d’esprit demandé, fait tous les exercices et projets demandés. |
||||||
|
|
||||||
|
- Ne cherche pas des biais et des failles dans le système. Tu vas fausser ta propre formation et ta valeur sur le marché. |
||||||
|
|
||||||
|
- Ne triche pas intentionellement. C’est amoral, cela contredit le commandement 12, et c’est du temps inutilement passé à ne pas développer tes compétences pour faire croire aux autres que tu sais coder alors que ce n’est pas le cas. |
||||||
|
|
||||||
|
- Ne rends pas un projet que tu ne serais pas capable de reproduire seul à huis clos. Même si c’est parfois involontaire, c’est aussi de la triche. |
||||||
|
|
||||||
|
- C’est pas pour tes parents que tu travailles, ni pour le staff. C’est pour toi. |
||||||
|
|
||||||
|
- Participe à la vie de la communauté, à son épanouissement, et sa qualité en sortie de formation. |
||||||
|
|
||||||
|
- Aide au respect de ces commandements par la communauté. |
||||||
|
|
||||||
|
- Sois bienveillant et empathique vis à vis de tes camarades comme des personnes avec qui tu interagis, échanges, débats. |
||||||
|
|
||||||
|
- N’ai pas peur du monde professionnel. |
||||||
|
|
||||||
|
- Respecte le matériel. Des consignes spécifiques sont données en ce sens. |
||||||
|
|
||||||
|
- Respecte les locaux. Des consignes spécifiques sont données en ce sens. |
||||||
|
|
||||||
|
- Respecte les gens, étudiants, staffs, partenaires, visiteurs. |
||||||
|
|
||||||
|
- Respecte la loi en vigueur dans le pays. |
||||||
|
|
||||||
|
- Respecte les lois et consignes en vigueur liées à la consommation d’alcool. |
||||||
|
|
||||||
|
- Respecte les lois et consignes en vigueur liées à la consommation de tabac, stupéfiants, ou produits assimilés. |
||||||
|
|
||||||
|
- N’hésite pas à interagir avec le staff, pour parler de tes problèmes, pour remonter des problèmes dans le cursus, pour contribuer au cursus. |
||||||
|
|
||||||
|
- Si tu t’interroges ou ne comprends pas nos choix pédagogiques, demande nous. On ne fait généralement rien au hasard. |
||||||
|
|
||||||
|
### Required |
||||||
|
|
||||||
|
You [clone](http://lmgtfy.com/?q=git+clone) your [fork](http://lmgtfy.com/?q=github+fork) of this [repository](http://lmgtfy.com/?q=git+repository) |
||||||
|
and in it, you must create a file named `turn_in` () in which you write EXACTLY the following sentence ending by a line break. |
||||||
|
|
||||||
|
<p align="center"> |
||||||
|
<img width="600" height="300" src="https://i.imgur.com/2PPQ2iZ.png"> |
||||||
|
</p> |
||||||
|
|
||||||
|
### Submiting your solution |
||||||
|
|
||||||
|
Your work should be commited and pushed in the master branch of your own fork of this repository. |
@ -0,0 +1,43 @@ |
|||||||
|
## compare |
||||||
|
|
||||||
|
### Instructions |
||||||
|
|
||||||
|
Write a function that behaves like the [`Compare`](https://golang.org/pkg/strings/#Compare) function. |
||||||
|
|
||||||
|
### Expected function |
||||||
|
|
||||||
|
```go |
||||||
|
func Compare(a, b string) int { |
||||||
|
|
||||||
|
} |
||||||
|
``` |
||||||
|
|
||||||
|
### Usage |
||||||
|
|
||||||
|
Here is a possible [program](TODO-LINK) to test your function : |
||||||
|
|
||||||
|
```go |
||||||
|
package main |
||||||
|
|
||||||
|
import ( |
||||||
|
"fmt" |
||||||
|
piscine ".." |
||||||
|
) |
||||||
|
|
||||||
|
func main() { |
||||||
|
fmt.Println(piscine.Compare("Hello!", "Hello!")) |
||||||
|
fmt.Println(piscine.Compare("Salut!", "lut!")) |
||||||
|
fmt.Println(piscine.Compare("Ola!", "Ol")) |
||||||
|
} |
||||||
|
``` |
||||||
|
|
||||||
|
And its output : |
||||||
|
|
||||||
|
```console |
||||||
|
student@ubuntu:~/piscine/test$ go build |
||||||
|
student@ubuntu:~/piscine/test$ ./test |
||||||
|
0 |
||||||
|
-1 |
||||||
|
1 |
||||||
|
student@ubuntu:~/piscine/test$ |
||||||
|
``` |
@ -0,0 +1,43 @@ |
|||||||
|
## compare |
||||||
|
|
||||||
|
### Instructions |
||||||
|
|
||||||
|
Écrire une fonction qui se comporte comme la fonction [`Compare`](https://golang.org/pkg/strings/#Compare). |
||||||
|
|
||||||
|
### Fonction attendue |
||||||
|
|
||||||
|
```go |
||||||
|
func Compare(a, b string) int { |
||||||
|
|
||||||
|
} |
||||||
|
``` |
||||||
|
|
||||||
|
### Utilisation |
||||||
|
|
||||||
|
Voici un éventuel [programme](TODO-LINK) pour tester votre fonction : |
||||||
|
|
||||||
|
```go |
||||||
|
package main |
||||||
|
|
||||||
|
import ( |
||||||
|
"fmt" |
||||||
|
piscine ".." |
||||||
|
) |
||||||
|
|
||||||
|
func main() { |
||||||
|
fmt.Println(piscine.Compare("Hello!", "Hello!")) |
||||||
|
fmt.Println(piscine.Compare("Salut!", "lut!")) |
||||||
|
fmt.Println(piscine.Compare("Ola!", "Ol")) |
||||||
|
} |
||||||
|
``` |
||||||
|
|
||||||
|
Et son résultat : |
||||||
|
|
||||||
|
```console |
||||||
|
student@ubuntu:~/piscine/test$ go build |
||||||
|
student@ubuntu:~/piscine/test$ ./test |
||||||
|
0 |
||||||
|
-1 |
||||||
|
1 |
||||||
|
student@ubuntu:~/piscine/test$ |
||||||
|
``` |
@ -0,0 +1,40 @@ |
|||||||
|
## concat |
||||||
|
|
||||||
|
### Instructions |
||||||
|
|
||||||
|
Write a function that returns the concatenation of two `string` passed in arguments. |
||||||
|
|
||||||
|
### Expected function |
||||||
|
|
||||||
|
```go |
||||||
|
func Concat(str1 string, str2 string) string { |
||||||
|
|
||||||
|
} |
||||||
|
``` |
||||||
|
|
||||||
|
### Usage |
||||||
|
|
||||||
|
Here is a possible [program](TODO-LINK) to test your function : |
||||||
|
|
||||||
|
```go |
||||||
|
package main |
||||||
|
|
||||||
|
import ( |
||||||
|
"fmt" |
||||||
|
piscine ".." |
||||||
|
) |
||||||
|
|
||||||
|
func main() { |
||||||
|
fmt.Println(piscine.Concat("Hello!", " How are you?")) |
||||||
|
|
||||||
|
} |
||||||
|
``` |
||||||
|
|
||||||
|
And its output : |
||||||
|
|
||||||
|
```console |
||||||
|
student@ubuntu:~/piscine/test$ go build |
||||||
|
student@ubuntu:~/piscine/test$ ./test |
||||||
|
Hello! How are you? |
||||||
|
student@ubuntu:~/piscine/test$ |
||||||
|
``` |
@ -0,0 +1,40 @@ |
|||||||
|
## concat |
||||||
|
|
||||||
|
### Instructions |
||||||
|
|
||||||
|
Écrire une fonction qui retourne la concaténation de deux `string` passées en paramètres. |
||||||
|
|
||||||
|
### Fonction attendue |
||||||
|
|
||||||
|
```go |
||||||
|
func Concat(str1 string, str2 string) string { |
||||||
|
|
||||||
|
} |
||||||
|
``` |
||||||
|
|
||||||
|
### Utilisation |
||||||
|
|
||||||
|
Voici un éventuel [programme](TODO-LINK) pour tester votre fonction : |
||||||
|
|
||||||
|
```go |
||||||
|
package main |
||||||
|
|
||||||
|
import ( |
||||||
|
"fmt" |
||||||
|
piscine ".." |
||||||
|
) |
||||||
|
|
||||||
|
func main() { |
||||||
|
fmt.Println(piscine.Concat("Hello!", " How are you?")) |
||||||
|
|
||||||
|
} |
||||||
|
``` |
||||||
|
|
||||||
|
Et son résultat : |
||||||
|
|
||||||
|
```console |
||||||
|
student@ubuntu:~/piscine/test$ go build |
||||||
|
student@ubuntu:~/piscine/test$ ./test |
||||||
|
Hello! How are you? |
||||||
|
student@ubuntu:~/piscine/test$ |
||||||
|
``` |
@ -0,0 +1,44 @@ |
|||||||
|
## concatparams |
||||||
|
|
||||||
|
### Instructions |
||||||
|
|
||||||
|
Write a function that takes the arguments reveived in parameters and returns them as a `string`. |
||||||
|
|
||||||
|
The arguments must be **separated** by a `\n`. |
||||||
|
|
||||||
|
### Expected function |
||||||
|
|
||||||
|
```go |
||||||
|
func ConcatParams(args []string) string { |
||||||
|
} |
||||||
|
``` |
||||||
|
|
||||||
|
### Usage |
||||||
|
|
||||||
|
Here is a possible [program](TODO-LINK) to test your function : |
||||||
|
|
||||||
|
```go |
||||||
|
package main |
||||||
|
|
||||||
|
import ( |
||||||
|
"fmt" |
||||||
|
piscine ".." |
||||||
|
) |
||||||
|
|
||||||
|
func main() { |
||||||
|
test := []string{"Hello", "how", "are", "you?"} |
||||||
|
fmt.Println(piscine.ConcatParams(test)) |
||||||
|
} |
||||||
|
``` |
||||||
|
|
||||||
|
And its output : |
||||||
|
|
||||||
|
```console |
||||||
|
student@ubuntu:~/piscine/test$ go build |
||||||
|
student@ubuntu:~/piscine/test$ ./test |
||||||
|
Hello |
||||||
|
how |
||||||
|
are |
||||||
|
you? |
||||||
|
student@ubuntu:~/piscine/test$ |
||||||
|
``` |
@ -0,0 +1,44 @@ |
|||||||
|
## concatparams |
||||||
|
|
||||||
|
### Instructions |
||||||
|
|
||||||
|
Écrire une fonction qui prend les arguments en paramètres et les retournes dans une `string`. |
||||||
|
|
||||||
|
Les arguments doivent être **séparés** par un `\n`. |
||||||
|
|
||||||
|
### Fonction attendue |
||||||
|
|
||||||
|
```go |
||||||
|
func ConcatParams(args []string) string { |
||||||
|
} |
||||||
|
``` |
||||||
|
|
||||||
|
### Utilisation |
||||||
|
|
||||||
|
Voici un éventuel [programme](TODO-LINK) pour tester votre fonction : |
||||||
|
|
||||||
|
```go |
||||||
|
package main |
||||||
|
|
||||||
|
import ( |
||||||
|
"fmt" |
||||||
|
piscine ".." |
||||||
|
) |
||||||
|
|
||||||
|
func main() { |
||||||
|
test := []string{"Hello", "how", "are", "you?"} |
||||||
|
fmt.Println(piscine.ConcatParams(test)) |
||||||
|
} |
||||||
|
``` |
||||||
|
|
||||||
|
Et son résultat : |
||||||
|
|
||||||
|
```console |
||||||
|
student@ubuntu:~/piscine/test$ go build |
||||||
|
student@ubuntu:~/piscine/test$ ./test |
||||||
|
Hello |
||||||
|
how |
||||||
|
are |
||||||
|
you? |
||||||
|
student@ubuntu:~/piscine/test$ |
||||||
|
``` |
@ -0,0 +1,43 @@ |
|||||||
|
## convertbase |
||||||
|
|
||||||
|
### Instructions |
||||||
|
|
||||||
|
Write a function that returns the convertion of a `string` number from one `string` baseFrom to one `string` baseTo. |
||||||
|
|
||||||
|
Only valid bases will be tested. |
||||||
|
|
||||||
|
Negative numbers will not be tested. |
||||||
|
|
||||||
|
### Expected function |
||||||
|
|
||||||
|
```go |
||||||
|
func ConvertBase(nbr, baseFrom, baseTo string) string { |
||||||
|
} |
||||||
|
``` |
||||||
|
|
||||||
|
### Usage |
||||||
|
|
||||||
|
Here is a possible [program](TODO-LINK) to test your function : |
||||||
|
|
||||||
|
```go |
||||||
|
package main |
||||||
|
|
||||||
|
import ( |
||||||
|
"fmt" |
||||||
|
piscine ".." |
||||||
|
) |
||||||
|
|
||||||
|
func main() { |
||||||
|
result := piscine.ConvertBase("101011", "01", "0123456789") |
||||||
|
fmt.Println(result) |
||||||
|
} |
||||||
|
``` |
||||||
|
|
||||||
|
And its output : |
||||||
|
|
||||||
|
```console |
||||||
|
student@ubuntu:~/piscine/test$ go build |
||||||
|
student@ubuntu:~/piscine/test$ ./test |
||||||
|
43 |
||||||
|
student@ubuntu:~/piscine/test$ |
||||||
|
``` |
@ -0,0 +1,43 @@ |
|||||||
|
## convertbase |
||||||
|
|
||||||
|
### Instructions |
||||||
|
|
||||||
|
Écrire une fonction qui retourne la convertion d'un nombre `string` d'une baseFrom `string` à une baseTo `string`. |
||||||
|
|
||||||
|
Seules des bases valides seront testées. |
||||||
|
|
||||||
|
Les nombres négatifs ne seront pas testés. |
||||||
|
|
||||||
|
### Fonction attendue |
||||||
|
|
||||||
|
```go |
||||||
|
func ConvertBase(nbr, baseFrom, baseTo string) string { |
||||||
|
} |
||||||
|
``` |
||||||
|
|
||||||
|
### Utilisation |
||||||
|
|
||||||
|
Voici un éventuel [programme](TODO-LINK) pour tester votre fonction : |
||||||
|
|
||||||
|
```go |
||||||
|
package main |
||||||
|
|
||||||
|
import ( |
||||||
|
"fmt" |
||||||
|
piscine ".." |
||||||
|
) |
||||||
|
|
||||||
|
func main() { |
||||||
|
result := piscine.ConvertBase("101011", "01", "0123456789") |
||||||
|
fmt.Println(result) |
||||||
|
} |
||||||
|
``` |
||||||
|
|
||||||
|
Et son résultat : |
||||||
|
|
||||||
|
```console |
||||||
|
student@ubuntu:~/piscine/test$ go build |
||||||
|
student@ubuntu:~/piscine/test$ ./test |
||||||
|
43 |
||||||
|
student@ubuntu:~/piscine/test$ |
||||||
|
``` |
@ -1,13 +1,13 @@ |
|||||||
# countdown |
## countdown |
||||||
|
|
||||||
## Instructions |
### Instructions |
||||||
|
|
||||||
Write a program that displays all digits in descending order, followed by a |
Write a program that displays all digits in descending order, followed by a |
||||||
newline. |
newline. |
||||||
|
|
||||||
## Expected main and function for the program |
### Expected main and function for the program |
||||||
|
|
||||||
## Expected output |
### Expected output |
||||||
|
|
||||||
```console |
```console |
||||||
student@ubuntu:~/piscine/test$ go build |
student@ubuntu:~/piscine/test$ go build |
@ -0,0 +1,44 @@ |
|||||||
|
## countif |
||||||
|
|
||||||
|
### Instructions |
||||||
|
|
||||||
|
Write a function `CountIf` that returns the number of elements of a `string` array for which the `f` function returns `true`. |
||||||
|
|
||||||
|
### Expected function |
||||||
|
|
||||||
|
```go |
||||||
|
func CountIf(f func(string) bool, tab []string) int { |
||||||
|
} |
||||||
|
``` |
||||||
|
|
||||||
|
### Usage |
||||||
|
|
||||||
|
Here is a possible [program](TODO-LINK) to test your function : |
||||||
|
|
||||||
|
```go |
||||||
|
package main |
||||||
|
|
||||||
|
import ( |
||||||
|
"fmt" |
||||||
|
piscine ".." |
||||||
|
) |
||||||
|
|
||||||
|
func main() { |
||||||
|
tab1 := []string{"Hello", "how", "are", "you"} |
||||||
|
tab2 := []string{"This","1", "is", "4", "you"} |
||||||
|
answer1 := piscine.CountIf(piscine.IsNumeric, tab1) |
||||||
|
answer2 := piscine.CountIf(piscine.IsNumeric, tab2) |
||||||
|
fmt.Println(answer1) |
||||||
|
fmt.Println(answer2) |
||||||
|
} |
||||||
|
``` |
||||||
|
|
||||||
|
And its output : |
||||||
|
|
||||||
|
```console |
||||||
|
student@ubuntu:~/piscine/test$ go build |
||||||
|
student@ubuntu:~/piscine/test$ ./test |
||||||
|
0 |
||||||
|
2 |
||||||
|
student@ubuntu:~/piscine/test$ |
||||||
|
``` |
@ -0,0 +1,44 @@ |
|||||||
|
## countif |
||||||
|
|
||||||
|
### Instructions |
||||||
|
|
||||||
|
Écrire une fonction `CountIf` qui retournes le nombre d'éléments d'un tableau de `string` pour lesquels la fonction `f` retourne `true`. |
||||||
|
|
||||||
|
### Fonction attendue |
||||||
|
|
||||||
|
```go |
||||||
|
func CountIf(f func(string) bool, tab []string) int { |
||||||
|
} |
||||||
|
``` |
||||||
|
|
||||||
|
### Utilisation |
||||||
|
|
||||||
|
Voici un éventuel [programme](TODO-LINK) pour tester votre fonction : |
||||||
|
|
||||||
|
```go |
||||||
|
package main |
||||||
|
|
||||||
|
import ( |
||||||
|
"fmt" |
||||||
|
piscine ".." |
||||||
|
) |
||||||
|
|
||||||
|
func main() { |
||||||
|
tab1 := []string{"Hello", "how", "are", "you"} |
||||||
|
tab2 := []string{"This","1", "is", "4", "you"} |
||||||
|
answer1 := piscine.CountIf(piscine.IsNumeric, tab1) |
||||||
|
answer2 := piscine.CountIf(piscine.IsNumeric, tab2) |
||||||
|
fmt.Println(answer1) |
||||||
|
fmt.Println(answer2) |
||||||
|
} |
||||||
|
``` |
||||||
|
|
||||||
|
Et son résultat : |
||||||
|
|
||||||
|
```console |
||||||
|
student@ubuntu:~/piscine/test$ go build |
||||||
|
student@ubuntu:~/piscine/test$ ./test |
||||||
|
0 |
||||||
|
2 |
||||||
|
student@ubuntu:~/piscine/test$ |
||||||
|
``` |
@ -1,10 +1,10 @@ |
|||||||
# dispfirstpar |
## dispfirstpar |
||||||
|
|
||||||
## Instructions |
### Instructions |
||||||
|
|
||||||
Write a program that takes strings as arguments, and displays its first argument. |
Write a program that takes strings as arguments, and displays its first argument. |
||||||
|
|
||||||
## Expected output |
### Expected output |
||||||
|
|
||||||
```console |
```console |
||||||
student@ubuntu:~/piscine/test$ go build |
student@ubuntu:~/piscine/test$ go build |
@ -1,10 +1,10 @@ |
|||||||
# displastpar |
## displastpar |
||||||
|
|
||||||
## Instructions |
### Instructions |
||||||
|
|
||||||
Write a program that takes strings as arguments, and displays its last argument. |
Write a program that takes strings as arguments, and displays its last argument. |
||||||
|
|
||||||
## Expected output |
### Expected output |
||||||
|
|
||||||
```console |
```console |
||||||
student@ubuntu:~/piscine/test$ go build |
student@ubuntu:~/piscine/test$ go build |
@ -1,15 +1,15 @@ |
|||||||
# displaya |
## displaya |
||||||
|
|
||||||
## Instructions |
### Instructions |
||||||
|
|
||||||
Write a program that takes a string, and displays the first 'a' character it |
Write a program that takes a string, and displays the first 'a' character it |
||||||
encounters in it, followed by a newline. If there are no 'a' characters in the |
encounters in it, followed by a newline. If there are no 'a' characters in the |
||||||
string, the program just writes a newline. If the number of parameters is not |
string, the program just writes a newline. If the number of parameters is not |
||||||
1, the program displays 'a' followed by a newline. |
1, the program displays 'a' followed by a newline. |
||||||
|
|
||||||
## Expected main and function for the program |
### Expected main and function for the program |
||||||
|
|
||||||
## Expected output |
### Expected output |
||||||
|
|
||||||
```console |
```console |
||||||
student@ubuntu:~/piscine/test$ go build |
student@ubuntu:~/piscine/test$ go build |
@ -1,5 +1,6 @@ |
|||||||
# displayalpham |
## displayalpham |
||||||
## Instructions |
|
||||||
|
### Instructions |
||||||
|
|
||||||
Write a program that displays the alphabet, with even letters in uppercase, and |
Write a program that displays the alphabet, with even letters in uppercase, and |
||||||
odd letters in lowercase, followed by a newline. |
odd letters in lowercase, followed by a newline. |
@ -1,5 +1,6 @@ |
|||||||
# displayalrevm |
## displayalrevm |
||||||
## Instructions |
|
||||||
|
### Instructions |
||||||
|
|
||||||
Write a program that displays the alphabet in reverse, with even letters in |
Write a program that displays the alphabet in reverse, with even letters in |
||||||
uppercase, and odd letters in lowercase, followed by a newline. |
uppercase, and odd letters in lowercase, followed by a newline. |
@ -1,13 +1,13 @@ |
|||||||
# displayz |
## displayz |
||||||
|
|
||||||
## Instructions |
### Instructions |
||||||
|
|
||||||
Write a program that takes a string, and displays the first 'a' character it |
Write a program that takes a string, and displays the first 'a' character it |
||||||
encounters in it, followed by a newline. If there are no 'a' characters in the |
encounters in it, followed by a newline. If there are no 'a' characters in the |
||||||
string, the program just writes a newline. If the number of parameters is not |
string, the program just writes a newline. If the number of parameters is not |
||||||
1, the program displays 'a' followed by a newline. |
1, the program displays 'a' followed by a newline. |
||||||
|
|
||||||
## Expected output |
### Expected output |
||||||
|
|
||||||
```console |
```console |
||||||
student@ubuntu:~/piscine/test$ go build |
student@ubuntu:~/piscine/test$ go build |
@ -0,0 +1,50 @@ |
|||||||
|
## divmod |
||||||
|
|
||||||
|
### Instructions |
||||||
|
|
||||||
|
- Write a function that will be formatted as below. |
||||||
|
|
||||||
|
### Expected function |
||||||
|
|
||||||
|
```go |
||||||
|
func DivMod(a int, b int, div *int, mod *int) { |
||||||
|
|
||||||
|
} |
||||||
|
``` |
||||||
|
|
||||||
|
- This function will divide the int **a** and **b**. |
||||||
|
- The result of this division will be stored in the int pointed by **div**. |
||||||
|
- The remainder of this division will be stored in the int pointed by **mod**. |
||||||
|
|
||||||
|
### Usage |
||||||
|
|
||||||
|
Here is a possible [program](TODO-LINK) to test your function : |
||||||
|
|
||||||
|
```go |
||||||
|
package main |
||||||
|
|
||||||
|
import ( |
||||||
|
"fmt" |
||||||
|
piscine ".." |
||||||
|
) |
||||||
|
|
||||||
|
func main() { |
||||||
|
a := 13 |
||||||
|
b := 2 |
||||||
|
var div int |
||||||
|
var mod int |
||||||
|
piscine.DivMod(a, b, &div, &mod) |
||||||
|
fmt.Println(div) |
||||||
|
fmt.Println(mod) |
||||||
|
} |
||||||
|
``` |
||||||
|
|
||||||
|
And its output : |
||||||
|
|
||||||
|
```console |
||||||
|
student@ubuntu:~/piscine/test$ go build |
||||||
|
student@ubuntu:~/piscine/test$ ./test |
||||||
|
6 |
||||||
|
1 |
||||||
|
student@ubuntu:~/piscine/test$ |
||||||
|
``` |
@ -0,0 +1,50 @@ |
|||||||
|
## divmod |
||||||
|
|
||||||
|
### Instructions |
||||||
|
|
||||||
|
- Écrire une fonction qui aura le format ci-dessous. |
||||||
|
|
||||||
|
### Fonction attendue |
||||||
|
|
||||||
|
```go |
||||||
|
func DivMod(a int, b int, div *int, mod *int) { |
||||||
|
|
||||||
|
} |
||||||
|
``` |
||||||
|
|
||||||
|
- Cette fonction divisera les int **a** et **b**. |
||||||
|
- Le résultat de la division sera stocké dans l'int pointé par **div**. |
||||||
|
- Le reste de cette division sera stocké dans l'int pointé par **mod**. |
||||||
|
|
||||||
|
### Utilisation |
||||||
|
|
||||||
|
Voici un éventuel [programme](TODO-LINK) pour tester votre fonction : |
||||||
|
|
||||||
|
```go |
||||||
|
package main |
||||||
|
|
||||||
|
import ( |
||||||
|
"fmt" |
||||||
|
piscine ".." |
||||||
|
) |
||||||
|
|
||||||
|
func main() { |
||||||
|
a := 13 |
||||||
|
b := 2 |
||||||
|
var div int |
||||||
|
var mod int |
||||||
|
piscine.DivMod(a, b, &div, &mod) |
||||||
|
fmt.Println(div) |
||||||
|
fmt.Println(mod) |
||||||
|
} |
||||||
|
``` |
||||||
|
|
||||||
|
Et son résultat : |
||||||
|
|
||||||
|
```console |
||||||
|
student@ubuntu:~/piscine/test$ go build |
||||||
|
student@ubuntu:~/piscine/test$ ./test |
||||||
|
6 |
||||||
|
1 |
||||||
|
student@ubuntu:~/piscine/test$ |
||||||
|
``` |
@ -0,0 +1,39 @@ |
|||||||
|
## doop |
||||||
|
|
||||||
|
### Instructions |
||||||
|
|
||||||
|
Write a [program](TODO-LINK) that is called `doop`. |
||||||
|
|
||||||
|
The program has to be used with three arguments: |
||||||
|
|
||||||
|
- A value |
||||||
|
- An operator |
||||||
|
- Another value |
||||||
|
|
||||||
|
In case of an invalid entry the programs prints `0`. |
||||||
|
|
||||||
|
In case of an invalid number of arguments the program prints nothing. |
||||||
|
|
||||||
|
`fmt.Print` is authorized. |
||||||
|
|
||||||
|
### Usage |
||||||
|
|
||||||
|
```console |
||||||
|
student@ubuntu:~/piscine/test$ go build doop.go |
||||||
|
student@ubuntu:~/piscine/test$ ./doop |
||||||
|
student@ubuntu:~/piscine/test$ ./doop 1 + 1 |
||||||
|
2 |
||||||
|
student@ubuntu:~/piscine/test$ ./doop hello + 1 |
||||||
|
0 |
||||||
|
student@ubuntu:~/piscine/test$ ./doop 1 p 1 |
||||||
|
0 |
||||||
|
student@ubuntu:~/piscine/test$ ./doop 1 + 1 |
||||||
|
2 |
||||||
|
student@ubuntu:~/piscine/test$ ./doop 1 / 0 |
||||||
|
No division by 0 |
||||||
|
student@ubuntu:~/piscine/test$ ./doop 1 % 0 |
||||||
|
No modulo by 0 |
||||||
|
student@ubuntu:~/piscine/test$ ./doop 1 * 1 |
||||||
|
1 |
||||||
|
|
||||||
|
``` |
@ -0,0 +1,39 @@ |
|||||||
|
## doop |
||||||
|
|
||||||
|
### Instructions |
||||||
|
|
||||||
|
Écrire un [programme](TODO-LINK) qui s'apelle `doop`. |
||||||
|
|
||||||
|
Le programme doit être utilisé avec trois arguments: |
||||||
|
|
||||||
|
- Une valeur |
||||||
|
- Un opérateur |
||||||
|
- Une autre valeur |
||||||
|
|
||||||
|
En cas d'argument invalide le programme affiche `0`. |
||||||
|
|
||||||
|
En cas de nombre invalide d'arguments le programme affiche rien. |
||||||
|
|
||||||
|
`fmt.Print` est autorisé. |
||||||
|
|
||||||
|
### Utilisation |
||||||
|
|
||||||
|
```console |
||||||
|
student@ubuntu:~/piscine/test$ go build doop.go |
||||||
|
student@ubuntu:~/piscine/test$ ./doop |
||||||
|
student@ubuntu:~/piscine/test$ ./doop 1 + 1 |
||||||
|
2 |
||||||
|
student@ubuntu:~/piscine/test$ ./doop hello + 1 |
||||||
|
0 |
||||||
|
student@ubuntu:~/piscine/test$ ./doop 1 p 1 |
||||||
|
0 |
||||||
|
student@ubuntu:~/piscine/test$ ./doop 1 + 1 |
||||||
|
2 |
||||||
|
student@ubuntu:~/piscine/test$ ./doop 1 / 0 |
||||||
|
No division by 0 |
||||||
|
student@ubuntu:~/piscine/test$ ./doop 1 % 0 |
||||||
|
No modulo by 0 |
||||||
|
student@ubuntu:~/piscine/test$ ./doop 1 * 1 |
||||||
|
1 |
||||||
|
|
||||||
|
``` |
@ -0,0 +1,33 @@ |
|||||||
|
## eightqueens |
||||||
|
|
||||||
|
### Intructions |
||||||
|
|
||||||
|
Write a function that prints the solutions to the [eight queens puzzle](https://en.wikipedia.org/wiki/Eight_queens_puzzle). |
||||||
|
|
||||||
|
Recursivity must be used to solve this problem. |
||||||
|
|
||||||
|
It should print something like this : |
||||||
|
|
||||||
|
```console |
||||||
|
student@ubuntu:~/piscine/test$ go build |
||||||
|
student@ubuntu:~/piscine/test$ ./test |
||||||
|
15863724 |
||||||
|
16837425 |
||||||
|
17468253 |
||||||
|
... |
||||||
|
``` |
||||||
|
|
||||||
|
Each solution will be on a single line. |
||||||
|
The index of the placement of a queen starts at 1. |
||||||
|
It reads from left to right and each digit is the position for each column. |
||||||
|
The solutions will be printed in ascending order. |
||||||
|
|
||||||
|
### Expected function |
||||||
|
|
||||||
|
```go |
||||||
|
package main |
||||||
|
|
||||||
|
func EightQueens() { |
||||||
|
|
||||||
|
} |
||||||
|
``` |
@ -0,0 +1,33 @@ |
|||||||
|
## eightqueens |
||||||
|
|
||||||
|
### Intructions |
||||||
|
|
||||||
|
Écrire une [fonction](TODO-LINK) qui affiche toutes les solutions du [problème des huit dames](https://en.wikipedia.org/wiki/Eight_queens_puzzle). |
||||||
|
|
||||||
|
La récursion doit être utilisée pour résoudre ce problème. |
||||||
|
|
||||||
|
L'affichage sera quelque chose comme ça : |
||||||
|
|
||||||
|
```console |
||||||
|
student@ubuntu:~/piscine/test$ go build |
||||||
|
student@ubuntu:~/piscine/test$ ./test |
||||||
|
15863724 |
||||||
|
16837425 |
||||||
|
17468253 |
||||||
|
... |
||||||
|
``` |
||||||
|
|
||||||
|
Chaque solution sera sur une ligne unique. |
||||||
|
L'index du placement d'une reine commence à 1. |
||||||
|
Elle se lit de gauche à droite et chaque chiffre est la position pour chacune des colonnes. |
||||||
|
Les solutions seront affichées dans l'ordre croissant. |
||||||
|
|
||||||
|
### Fonction attendue |
||||||
|
|
||||||
|
```go |
||||||
|
package main |
||||||
|
|
||||||
|
func EightQueens() { |
||||||
|
|
||||||
|
} |
||||||
|
``` |
@ -0,0 +1,41 @@ |
|||||||
|
## findnextprime |
||||||
|
|
||||||
|
### Intructions |
||||||
|
|
||||||
|
Write a function that returns the first prime number that is equal or superior to the `int` passed as parameter. |
||||||
|
|
||||||
|
### Expected function |
||||||
|
|
||||||
|
```go |
||||||
|
func FindNextPrime(int nb) int { |
||||||
|
|
||||||
|
} |
||||||
|
``` |
||||||
|
|
||||||
|
### Usage |
||||||
|
|
||||||
|
Here is a possible [program](TODO-LINK) to test your function : |
||||||
|
|
||||||
|
```go |
||||||
|
package main |
||||||
|
|
||||||
|
import ( |
||||||
|
"fmt" |
||||||
|
piscine ".." |
||||||
|
) |
||||||
|
|
||||||
|
func main() { |
||||||
|
fmt.Println(piscine.FindNextPrime(5)) |
||||||
|
fmt.Println(piscine.FindNextPrime(4)) |
||||||
|
} |
||||||
|
``` |
||||||
|
|
||||||
|
And its output : |
||||||
|
|
||||||
|
```console |
||||||
|
student@ubuntu:~/piscine/test$ go build |
||||||
|
student@ubuntu:~/piscine/test$ ./test |
||||||
|
5 |
||||||
|
5 |
||||||
|
student@ubuntu:~/piscine/test$ |
||||||
|
``` |
@ -0,0 +1 @@ |
|||||||
|
## firebase-demo |
@ -0,0 +1,42 @@ |
|||||||
|
## firstrune |
||||||
|
|
||||||
|
### Instructions |
||||||
|
|
||||||
|
Write a function that returns the first `rune` of a `string`. |
||||||
|
|
||||||
|
### Expected function |
||||||
|
|
||||||
|
```go |
||||||
|
func FirstRune(s string) rune { |
||||||
|
|
||||||
|
} |
||||||
|
``` |
||||||
|
|
||||||
|
### Usage |
||||||
|
|
||||||
|
Here is a possible [program](TODO-LINK) to test your function : |
||||||
|
|
||||||
|
```go |
||||||
|
package main |
||||||
|
|
||||||
|
import ( |
||||||
|
"github.com/01-edu/z01" |
||||||
|
piscine ".." |
||||||
|
) |
||||||
|
|
||||||
|
func main() { |
||||||
|
z01.PrintRune(piscine.FirstRune("Hello!")) |
||||||
|
z01.PrintRune(piscine.FirstRune("Salut!")) |
||||||
|
z01.PrintRune(piscine.FirstRune("Ola!")) |
||||||
|
z01.PrintRune('\n') |
||||||
|
} |
||||||
|
``` |
||||||
|
|
||||||
|
And its output : |
||||||
|
|
||||||
|
```console |
||||||
|
student@ubuntu:~/piscine/test$ go build |
||||||
|
student@ubuntu:~/piscine/test$ ./test |
||||||
|
HSO |
||||||
|
student@ubuntu:~/piscine/test$ |
||||||
|
``` |
@ -0,0 +1,42 @@ |
|||||||
|
## firstrune |
||||||
|
|
||||||
|
### Instructions |
||||||
|
|
||||||
|
Écrire une fonction qui retourne la première `rune` d'une `string`. |
||||||
|
|
||||||
|
### Fonction attendue |
||||||
|
|
||||||
|
```go |
||||||
|
func FirstRune(s string) rune { |
||||||
|
|
||||||
|
} |
||||||
|
``` |
||||||
|
|
||||||
|
### Utilisation |
||||||
|
|
||||||
|
Voici un éventuel [programme](TODO-LINK) pour tester votre fonction : |
||||||
|
|
||||||
|
```go |
||||||
|
package main |
||||||
|
|
||||||
|
import ( |
||||||
|
"github.com/01-edu/z01" |
||||||
|
piscine ".." |
||||||
|
) |
||||||
|
|
||||||
|
func main() { |
||||||
|
z01.PrintRune(piscine.FirstRune("Hello!")) |
||||||
|
z01.PrintRune(piscine.FirstRune("Salut!")) |
||||||
|
z01.PrintRune(piscine.FirstRune("Ola!")) |
||||||
|
z01.PrintRune('\n') |
||||||
|
} |
||||||
|
``` |
||||||
|
|
||||||
|
Et son résultat : |
||||||
|
|
||||||
|
```console |
||||||
|
student@ubuntu:~/piscine/test$ go build |
||||||
|
student@ubuntu:~/piscine/test$ ./test |
||||||
|
HSO |
||||||
|
student@ubuntu:~/piscine/test$ |
||||||
|
``` |
Some files were not shown because too many files changed in this diff diff.show_more
Loading…
Reference in new issue