In internet i found 800 rows of code. Its really hard to understand. And its too complicated. Im receiving from an input and printing the input. But thats all i got.
What im trying to do/achieve:
`Instructions:
You need to create tunnels and rooms.
A room will never start with the letter L or with # and must have no spaces.
You join the rooms together with as many tunnels as you need.
A tunnel joins only two rooms together never more than that.
A room can be linked to multiple rooms.
Two rooms cant have more than one tunnel connecting them.
Each room can only contain one ant at a time (expect at ##start and ##end which can contains as many ants as necessary).
Each tunnel can only be used once per turn.
To be the first to arrive, ants will need to take the shortest path or paths.
They will also need to avoid traffic jams as well as walking all over their fellow ants.
You will only display the ants that moved at each turn, and you can move each ant only once and through a tunnel (the room at the receiving end must be empty).
The rooms names will not necessarily be numbers, and in order.
Any unknown command will be ignored.
The program must handle errors carefully. In no way can it quit an unexpected manner.
The coordinates of the rooms will always be int.
The program must be written in go.
The code must respect the good practices.
It is recommended to have test files for unit testing.
Usage:
Example:
$ go run . test.txt
3
##start
1 23 3
2 16 7
3 16 3
4 16 5
5 9 3
6 1 5
7 4 8
##end
0 9 5
0-4
0-6
1-3
4-3
5-3
3-5
4-2
1-2
7-6
7-2
7-4
6-5
L1-3 L2-2
L1-4 L2-5 L3-3
L1-0 L2-6 L3-4
L2-0 L3-0
$`
My code for now:
import (
"fmt"
"io/ioutil"
"log"
"os"
"strconv"
"strings"
)
// çiftlik yapısı
type ciftlik struct {
karincasayisi int
odaKoordinatları [][]string // İki sütunlu bir dilim (slice) kullanıyoruz
tünel []string
startline int
endline int
startOdaNumarası int
endOdaNumarası int
}
// Giriş verisini okuma işlevi
func parseInput(textfile string) (ciftlik, error) {
var ciftlikinfo ciftlik
content, err := ioutil.ReadFile("examples/" + textfile)
if err != nil {
return ciftlikinfo, err
}
lines := strings.Split(string(content), "n")
for i, satir := range lines {
if satir == "##start" {
ciftlikinfo.startline = i + 2
} else if satir == "##end" {
ciftlikinfo.endline = i + 2
} else if strings.Contains(satir, "-") {
ciftlikinfo.tünel = append(ciftlikinfo.tünel, satir)
} else if !strings.Contains(satir, "#") && len(strings.Split(satir, " ")) == 3 {
// İki sütunlu bir dilim (slice) oluşturuyoruz
odaKoordinat := strings.Split(satir, " ")
ciftlikinfo.odaKoordinatları = append(ciftlikinfo.odaKoordinatları, odaKoordinat)
} else if len(satir) > 0 {
ciftlikinfo.karincasayisi, err = strconv.Atoi(satir[:1])
if err != nil {
fmt.Println("karınca sayısı bulunamadı")
}
} else if len(satir) > 0 {
ciftlikinfo.startOdaNumarası = ciftlikinfo.startline
}
}
if ciftlikinfo.startline == 0 || ciftlikinfo.endline == 0 {
return ciftlikinfo, fmt.Errorf("start ve/veya end işaretleri bulunamadı")
}
return ciftlikinfo, nil
}
func main() {
if len(os.Args) != 2 {
fmt.Println("Kullanım: go run . <dosya_adı>")
os.Exit(1)
}
textfile := os.Args[1]
ciftlikinfo, err := parseInput(textfile)
if err != nil {
log.Fatal(err)
}
// parseInput fonksiyonundan gelen verileri kullanabilirsiniz
fmt.Println("Karınca Sayısı:", ciftlikinfo.karincasayisi)
fmt.Println("Start Line:", ciftlikinfo.startline)
fmt.Println("End Line:", ciftlikinfo.endline)
fmt.Println("Oda Koordinatları:")
for _, oda := range ciftlikinfo.odaKoordinatları {
fmt.Println(oda[1], oda[2]) // İki sütunlu oda koordinatlarını yazdırıyoruz
}
fmt.Println("Tüneller:", ciftlikinfo.tünel)
}
I tried chatgpt and a few algorithms…
Abruzzi is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.