lem-in is a program that simulates ants moving through a colony of rooms and tunnels. The objective is to calculate and display the quickest way to get a specified number of ants from the starting room (##start) to the ending room (##end) with as few moves as possible.
- The colony consists of rooms connected by tunnels.
- All ants start in the
##startroom, and the goal is to move them to the##endroom. - The program must find and display the fastest way to achieve this.
- The shortest path is not always the most optimal due to the potential for traffic jams.
- The program reads from a file passed as an argument, which contains:
- The number of ants.
- Example of file format:
$ go run . test0.txt
3
##start
1 23 3 # room 1 is the start room.
2 16 7
3 16 3 # room 3 is at ( X = 16 ) and ( Y = 3 ).
4 16 5
5 9 3 # commnent.
6 1 5
7 4 8
##end
0 9 5
0-4 # Room 0 is connected to room 4 and 4 is connected to room 0.
0-6
1-3
4-3
5-2
3-5
4-2
2-1
# this line and the next one are ignored.
7-6
7-2
7-4
6-5
- The program must handle a variety of invalid inputs, such as:
- No start or end room.
- Invalid number of ants.
- Invalid room or tunnel descriptions.
- When an error is encountered, an appropriate message such as
ERROR: invalid data formatshould be returned.
- Multiple paths can be taken by the ants at the same time.
- A tunnel can only be used by one ant per move.
- Each room can only hold one ant at a time, except for the
##startand##endrooms, which can hold multiple ants.
To run the program, use the following command:
$ go run . <file.txt>or
$ go build .
$ ./lem-in <file.txt>Replace file.txt with the name of your input file.
https://github.com/Med-Elalj/lemin-test
git clone https://github.com/Med-Elalj/lemin-testspecial thanks to our friend @yaouzddou for helping us with the logic to make the RemoveRepetition function.