@ -18,7 +18,7 @@ You need to find the quickest way to get `n` ants across a colony (composed of r
- At the beginning of the game, all the ants are in the room `##start`. The goal is to bring them to the room `##end` with as few moves as possible.
- At the beginning of the game, all the ants are in the room `##start`. The goal is to bring them to the room `##end` with as few moves as possible.
- The shortest path is not necessarily the simplest.
- The shortest path is not necessarily the simplest.
- Some colonies will have many rooms and many links, but no path between `##start` and `##end`.
- Some colonies will have many rooms and many links, but no path between `##start` and `##end`.
- Some will have rooms that link to themselves, sending your path-search spinning in circles, some will have too many/too few ants, no `##start` or `##end`, duplicated rooms, links to unknown rooms, rooms with invalid coordinates and a variety of other invalid or poorly-formatted input. In this cases the program will return an error message `ERROR: invalid data format`. If you want, you can elaborate the error message by being more specific (example: `ERROR: invalid data format, invalid number of Ants`and`ERROR: invalid data format, no start room found`).
- Some will have rooms that link to themselves, sending your path-search spinning in circles, some will have too many/too few ants, no `##start` or `##end`, duplicated rooms, links to unknown rooms, rooms with invalid coordinates and a variety of other invalid or poorly-formatted input. In this cases the program will return an error message `ERROR: invalid data format`. If you want, you can elaborate the error message by being more specific (example: `ERROR: invalid data format, invalid number of Ants`or`ERROR: invalid data format, no start room found`).
You must display your results on the standard output in the following format :
You must display your results on the standard output in the following format :
@ -30,8 +30,7 @@ the_links
Lx-y Lz-w Lr-o ...
Lx-y Lz-w Lr-o ...
```
```
- x, z, r represents the ants numbers (going from 1 to number_of_ants) and y,
- x, z, r represents the ants numbers (going from 1 to number_of_ants) and y, w, o represents the rooms names.
w, o represents the rooms names.
- A room is defined by `"name coord_x coord_y"`, and will usually look like `"Room 1 2", "nameoftheroom 1 6", "4 6 7"`.
- A room is defined by `"name coord_x coord_y"`, and will usually look like `"Room 1 2", "nameoftheroom 1 6", "4 6 7"`.
@ -79,22 +78,6 @@ Which corresponds to the following representation :
[7]_________/
[7]_________/
```
```
This project will help you learn about :
- Algorithmics
- Ways to receive data
- Ways to output data
- Manipulation of strings
- Manipulation of structures
### Bonus
- As a bonus you have to create an ant farm visualizer that shows the ants moving trough the colony.
- Here is an usage example : `./lem-in ant-farm.txt | ./visualizer`
- The coordinates of the room will be useful only here.
### Instructions
### Instructions
- You need to create tunnels and rooms.
- You need to create tunnels and rooms.
@ -115,7 +98,7 @@ This project will help you learn about :
### Allowed packages
### Allowed packages
- Only the [standard go](https://golang.org/pkg/) packages are allowed
- Only the [standard go](https://golang.org/pkg/) packages are allowed.
### Usage
### Usage
@ -199,3 +182,19 @@ L1-1 L2-1 L3-2
L3-1
L3-1
$
$
```
```
### Bonus
- As a bonus you can create an ant farm visualizer that shows the ants moving trough the colony.
- Here is an usage example : `./lem-in ant-farm.txt | ./visualizer`
- The coordinates of the room will be useful only here.
##### Try running the program with example06.txt and with 100 ants.
##### Try running the program with [example06](https://public.01-edu.org/subjects/lem-in/examples/) and with 100 ants.
###### Is the real time less than 1.5 minutes?
###### Is the real time less than 1.5 minutes?
##### Try running the program with example07.txt and with 1000 ants.
##### Try running the program with [example07](https://public.01-edu.org/subjects/lem-in/examples/) and with 1000 ants.
###### Is the real time less than 2.5 minutes?
###### Is the real time less than 2.5 minutes?
@ -327,7 +327,7 @@ $
###### +Is the error output more specific? (example: `"ERROR: invalid data format, invalid number of Ants"` or `"ERROR: invalid data format, no start room found"`)
###### +Is the error output more specific? (example: `"ERROR: invalid data format, invalid number of Ants"` or `"ERROR: invalid data format, no start room found"`)
Push_swap is a very simple and highly effective algorithm. You have at your disposal a list of `int` values, two stacks (`a` and `b`) and a set of instructions.
Push-swap is a very simple and highly effective algorithm. You have at your disposal a list of `int` values, two stacks (`a` and `b`) and a set of instructions.
You will have to write 2 programs:
You will have to write 2 programs:
- **push_swap**, which calculates and displays on the standard output the smallest program using push_swap instruction language that sorts integer arguments received.
- **push-swap**, which calculates and displays on the standard output the smallest program using push-swap instruction language that sorts integer arguments received.
- **checker**, which takes integer arguments and reads instructions on the standard output. Once read, checker executes them and displays `OK` if integers are sorted. Otherwise, it will display `KO`.
- **checker**, which takes integer arguments and reads instructions on the standard output. Once read, checker executes them and displays `OK` if integers are sorted. Otherwise, it will display `KO`.
As said before, you will have two stacks at your disposal. Your goal is to sort stack `a`, that will contain the `int` values received, in ascending order, using both stacks and a set of instructions.
As said before, you will have two stacks at your disposal. Your goal is to sort the stack `a`, that will contain the `int` values received, in ascending order, using both stacks and a set of instructions.
These are the instructions that you can use to sort the stack :
These are the instructions that you can use to sort the stack :
@ -80,20 +80,14 @@ Exec pa pa pa:
a b
a b
```
```
This project will help you learn about :
#### The push-swap program
- the use of basic algorithms
- the use of sorting algorithms
- the use of stacks
#### The push_swap program
- You have to write a program named push-swap, which will receive as an argument the stack `a` formatted as a list of integers. The first integer should be at the top of the stack.
- You have to write a program named push_swap, which will receive as an argument the stack a formatted as a list of integers. The first integer should be at the top of the stack.
- The program must display the smallest list of instructions possible to sort the stack `a`, with the smallest number being at the top.
- The program must display the smallest list of instructions possible to sort the stack `a`, with the smallest number being at the top.
- Instructions must be separated by a `\n` and nothing else.
- Instructions must be separated by a `\n` and nothing else.
- The goal is to sort the stack with the minimum possible number of operations.
- The goal is to sort the stack with the minimum possible number of operations.
- In case of error, you must display `Error` followed by a `\n` on the standard error. Errors are understood as: some arguments aren’t integers and/or there are duplicates.
- In case of error, you must display `Error` followed by a `\n` on the standard error. Errors are understood as: some arguments are not integers and/or there are duplicates.
- In case of there are no arguments the program displays nothing (0 instructions).
- If there are no arguments, the program does not display anything (0 instructions).
```console
```console
$ go run . "2 1 3 6 5 8"
$ go run . "2 1 3 6 5 8"
@ -115,7 +109,7 @@ $
- You have to write a program named checker, which will get as an argument the stack `a` formatted as a list of integers. The first argument should be at the top of the stack (be careful about the order). If no argument is given, checker stops and displays nothing.
- You have to write a program named checker, which will get as an argument the stack `a` formatted as a list of integers. The first argument should be at the top of the stack (be careful about the order). If no argument is given, checker stops and displays nothing.
- Checker will then read instructions on the standard input, each instruction will be followed by `\n`. Once all the instructions have been read, checker will execute them on the stack received as an argument.
- Checker will then read instructions on the standard input, each instruction will be followed by `\n`. Once all the instructions have been read, checker will execute them on the stack received as an argument.
- If after executing those instructions, stack `a` is actually sorted and `b` is empty, then checker must display "OK" followed by a `\n` on the standard output. In every other case, checker must display "KO" followed by a `\n` on the standard output.
- If after executing those instructions, stack `a` is actually sorted and `b` is empty, then checker must display "OK" followed by a `\n` on the standard output. In every other case, checker must display "KO" followed by a `\n` on the standard output.
- In case of error, you must display Error followed by a `\n` on the standard error. Errors include for example: some arguments are not integers, there are duplicates, an instruction don’t exist and/or is incorrectly formatted.
- In case of error, you must display Error followed by a `\n` on the standard error. Errors include for example: some arguments are not integers, there are duplicates, an instruction do not exist and/or is incorrectly formatted.
- In case of there are no arguments the program displays nothing.
- In case of there are no arguments the program displays nothing.
```console
```console
@ -138,26 +132,32 @@ $ go run ./checker
$
$
```
```
### Allowed packages
- Only the [standard go](https://golang.org/pkg/) packages are allowed
### Instructions
### Instructions
- Your project must be written in **Go**.
- Your project must be written in **Go**.
- The code must respect the [**good practices**](https://public.01-edu.org/subjects/good-practices/).
- The code must respect the [**good practices**](https://public.01-edu.org/subjects/good-practices/).
- It is recommended that the code should present a **test file**.
- It is recommended that the code should present a **test file**.
- The first executable file must be named **checker** and the second **push_swap**.
- The first executable file must be named **checker** and the second **push-swap**.
- You have to be able to handle the errors.
- You have to be able to handle the errors.
### Allowed packages
- Only the [standard go](https://golang.org/pkg/) packages are allowed
### Usage
### Usage
```console
```console
$ ARG="4 67 3 87 23"; ./push_swap "$ARG" | wc -l
$ ARG="4 67 3 87 23"; ./push-swap "$ARG" | wc -l
6
6
$ ARG="4 67 3 87 23"; ./push_swap "$ARG" | go run ./checker "$ARG"
$ ARG="4 67 3 87 23"; ./push-swap "$ARG" | go run ./checker "$ARG"
OK
OK
$
$
```
```
If the program checker displays KO, it means that your **push_swap** came up with a list of instructions that doesn't sort the list.
If the program checker displays KO, it means that your **push-swap** came up with a list of instructions that does not sort the list.
###### Has the requirement for the allowed packages been respected? (Reminder for this project: (only [standard packages](https://golang.org/pkg/)
###### Has the requirement for the allowed packages been respected? (Reminder for this project: (only [standard packages](https://golang.org/pkg/)
##### Try to run `"./push_swap"`.
##### Try to run `"./push-swap"`.
###### Does it display nothing?
###### Does it display nothing?
##### Try to run `"./push_swap 2 1 3 6 5 8"`.
##### Try to run `"./push-swap 2 1 3 6 5 8"`.
###### Does it display a valid solution and less than 9 instructions?
###### Does it display a valid solution and less than 9 instructions?
##### Try to run `"./push_swap 0 1 2 3 4 5"`.
##### Try to run `"./push-swap 0 1 2 3 4 5"`.
###### Does it display nothing?
###### Does it display nothing?
##### Try to run `"./push_swap 0 one 2 3"`.
##### Try to run `"./push-swap 0 one 2 3"`.
```console
```console
Error
Error
```
```
###### Does it display the right result as above?
###### Does it display the correct result as above?
##### Try to run `"./push_swap 1 2 2 3"`.
##### Try to run `"./push-swap 1 2 2 3"`.
```console
```console
Error
Error
```
```
###### Does it display the right result as above?
###### Does it display the correct result as above?
##### Try to run `"./push_swap <5 random numbers>"` with 5 random numbers instead of the tag.
##### Try to run `"./push-swap <5 random numbers>"` with 5 random numbers instead of the tag.
###### Does it display a valid solution and less than 12 instructions?
###### Does it display a valid solution and less than 12 instructions?
##### Try to run `"./push_swap <5 random numbers>"` with 5 different random numbers instead of the tag.
##### Try to run `"./push-swap <5 random numbers>"` with 5 different random numbers instead of the tag.
###### Does it still displays a valid solution and less than 12 instructions?
###### Does it still displays a valid solution and less than 12 instructions?
@ -48,7 +48,7 @@ Error
Error
Error
```
```
###### Does it display the right result as above?
###### Does it display the correct result as above?
##### Try to run `"echo -e "sa\npb\nrrr\n" | ./checker 0 9 1 8 2 7 3 6 4 5"`.
##### Try to run `"echo -e "sa\npb\nrrr\n" | ./checker 0 9 1 8 2 7 3 6 4 5"`.
@ -56,7 +56,7 @@ Error
KO
KO
```
```
###### Does it display the right result as above?
###### Does it display the correct result as above?
##### Try to run `"echo -e "pb\nra\npb\nra\nsa\nra\npa\npa\n" | ./checker 0 9 1 8 2"`.
##### Try to run `"echo -e "pb\nra\npb\nra\nsa\nra\npa\npa\n" | ./checker 0 9 1 8 2"`.
@ -64,31 +64,31 @@ KO
OK
OK
```
```
###### Does it display the right result as above?
###### Does it display the correct result as above?
##### Try to run `"ARG=("4 67 3 87 23"); ./push_swap $ARG | ./checker $ARG"`.
##### Try to run `"ARG=("4 67 3 87 23"); ./push-swap $ARG | ./checker $ARG"`.
```console
```console
OK
OK
```
```
###### Does it display the right result as above?
###### Does it display the correct result as above?
###### As an auditor, is this project up to every standard? If not, why are you failing the project?(Empty Work, Incomplete Work, Invalid compilation, Cheating, Crashing, Leaks)
###### As an auditor, is this project up to every standard? If not, why are you failing the project?(Empty Work, Incomplete Work, Invalid compilation, Cheating, Crashing, Leaks)
#### General
#### General
##### Try to run `"ARG=("<100 random numbers>"); ./push_swap $ARG"` with 100 random different numbers instead of the tag.
##### Try to run `"ARG=("<100 random numbers>"); ./push-swap $ARG"` with 100 random different numbers instead of the tag.
###### +Does it display less than 700 commands?
###### +Does it display less than 700 commands?
##### Try to run `"ARG=("<100 random numbers>"); ./push_swap $ARG | ./checker $ARG"` with the same 100 random different numbers as before instead of the tag.
##### Try to run `"ARG=("<100 random numbers>"); ./push-swap $ARG | ./checker $ARG"` with the same 100 random different numbers as before instead of the tag.
```console
```console
OK
OK
```
```
###### +Does it display the right result as above?
###### +Does it display the correct result as above?