Add Files of first version

This commit is contained in:
2025-11-12 22:17:04 +01:00
parent a43b15566b
commit d568231f94
11 changed files with 7294 additions and 0 deletions

11
data/hund01.txt Normal file
View File

@@ -0,0 +1,11 @@
5
13 18 29 8
29 8 31 19
31 19 41 30
41 30 17 32
17 32 13 18
1
3
23 19
31 25
21 27

27
data/hund02.txt Normal file
View File

@@ -0,0 +1,27 @@
9
54 42 52 32
54 64 54 42
2 64 54 64
2 42 2 64
8 38 2 42
18 44 8 38
52 32 18 44
36 2 52 32
8 38 36 2
2
8
30 22
35 16
40 21
36 23
37 28
36 32
26 34
25 23
6
38 46
43 40
48 45
44 56
18 57
23 48

116
data/hund03.txt Normal file
View File

@@ -0,0 +1,116 @@
30
87 63 68 91
68 91 34 94
68 91 55 53
55 53 34 94
55 53 87 63
87 63 66 26
66 26 31 6
34 94 29 59
66 26 99 53
55 53 31 6
29 59 31 6
99 53 90 17
90 17 66 26
87 63 99 53
29 59 1 36
31 6 90 17
1 36 31 6
99 53 99 91
29 59 5 83
55 53 66 26
5 83 34 94
29 59 55 53
87 63 99 91
68 91 99 91
1 36 6 6
1 36 5 83
31 6 6 6
31 6 19 34
19 34 29 59
19 34 1 36
11
8
91 2
95 5
95 9
89 4
80 9
79 5
91 1
91 2
4
16 56
15 63
8 62
16 56
11
12 98
6 93
5 99
5 100
5 92
8 93
13 92
17 93
20 100
15 95
12 98
7
53 77
57 77
59 79
57 84
55 83
53 78
53 77
6
59 3
66 3
72 1
75 6
57 2
59 3
5
52 79
52 83
46 85
50 80
52 79
5
35 43
35 42
38 36
41 38
35 43
6
72 67
76 65
70 69
68 68
68 64
72 67
10
42 44
45 45
46 50
43 49
42 50
38 50
41 47
41 46
41 43
42 44
5
10 17
10 16
16 11
15 12
10 17
6
100 93
110 97
113 98
110 103
92 107
95 103

45
data/hund04.txt Normal file
View File

@@ -0,0 +1,45 @@
22
90 56 50 55
50 55 95 42
90 56 52 68
90 56 95 42
50 55 52 68
52 68 12 73
50 55 12 73
52 68 57 98
52 68 27 91
50 55 21 36
90 56 69 78
21 36 17 5
17 5 2 42
2 42 50 55
50 55 17 5
52 68 69 78
69 78 57 98
50 55 66 15
17 5 49 26
57 98 27 91
17 5 66 15
50 55 49 26
4
4
53 52
69 13
105 27
98 39
7
79 107
85 113
77 127
80 112
70 114
68 130
65 110
3
9 50
22 55
5 66
3
20 80
30 75
1 105

4297
data/hund05.txt Normal file

File diff suppressed because it is too large Load Diff

2626
data/hund06.txt Normal file

File diff suppressed because it is too large Load Diff

3
go.mod Normal file
View File

@@ -0,0 +1,3 @@
module bwinf-nasserhund
go 1.24.7

25
main.go Normal file
View File

@@ -0,0 +1,25 @@
package main
import (
"fmt"
"os"
)
func main() {
maps := make([]Map, len(os.Args)-1)
for i, a := range os.Args {
if i == 0 {
continue
}
maps[i-1] = parseMap(a)
}
printMaps(maps)
minDist := calcMin(maps)
fmt.Printf("The max distance is: %f", minDist)
}
func printMaps(maps []Map) {
for i, v := range maps {
fmt.Printf("%d:\n\tPaths: %v\n\tPonds: %v\n", i, v.paths, v.ponds)
}
}

32
minpath.go Normal file
View File

@@ -0,0 +1,32 @@
package main
import (
"fmt"
"math"
)
func calcMin(maps []Map) float64 {
var minDist float64 = math.MaxFloat64
for _, m := range maps {
for _, path := range m.paths {
minDist = math.Min(minDist, calcMinPath(path, m.ponds))
}
}
return minDist
}
func calcMinPath(path Path, ponds []Pond) float64 {
var minDist float64 = math.MaxFloat64
for _, pond := range ponds {
for _, vertex := range pond.vertices {
cinitial := path.start.distance(path.end)
ainitial := path.end.distance(vertex)
c := path.start.distance(vertex)
alpha := math.Acos((ainitial*ainitial - cinitial*cinitial - c*c) / (-2 * cinitial * c))
height := math.Sin(alpha) * c
minDist = math.Min(minDist, height)
fmt.Printf("alpha: %f, c: %f, cinital: %f, ainitial: %F, h: %f\n", alpha, c, cinitial, ainitial, height)
}
}
return minDist
}

86
parse.go Normal file
View File

@@ -0,0 +1,86 @@
package main
import (
"bufio"
"os"
"strconv"
"strings"
)
func parseMap(path string) Map {
file, err := os.Open(path)
if err != nil {
panic(err)
}
defer func() {
file.Close()
}()
scanner := bufio.NewScanner(file)
scanner.Scan()
line := scanner.Text()
amountPaths, err := strconv.ParseInt(line, 10, 8)
if err != nil {
panic(err)
}
paths := parsePaths(scanner, int(amountPaths))
scanner.Scan()
line = scanner.Text()
amountPonds, err := strconv.ParseInt(line, 10, 8)
if err != nil {
panic(err)
}
ponds := parsePonds(scanner, int(amountPonds))
return Map{paths, ponds}
}
func parsePaths(scanner *bufio.Scanner, amount int) []Path {
paths := make([]Path, amount)
for i := 0; i < amount && scanner.Scan(); i++ {
line := scanner.Text()
numbers := strings.Split(line, " ")
startx, _ := strconv.ParseInt(numbers[0], 10, 8)
starty, _ := strconv.ParseInt(numbers[1], 10, 8)
endx, _ := strconv.ParseInt(numbers[2], 10, 8)
endy, _ := strconv.ParseInt(numbers[3], 10, 8)
startc := Coordinate{int(startx), int(starty)}
endc := Coordinate{int(endx), int(endy)}
paths[i] = Path{startc, endc}
}
if scanner.Err() != nil {
panic(scanner.Err())
}
return paths
}
func parsePonds(scanner *bufio.Scanner, amount int) []Pond {
ponds := make([]Pond, amount)
for i := 0; i < amount && scanner.Scan(); i++ {
line := scanner.Text()
amountVertices, err := strconv.ParseInt(line, 10, 8)
vertices := make([]Coordinate, amountVertices)
if err != nil {
panic(err)
}
for j := 0; j < int(amountVertices) && scanner.Scan(); j++ {
line := scanner.Text()
numbers := strings.Split(line, " ")
vx, _ := strconv.ParseInt(numbers[0], 10, 8)
vy, _ := strconv.ParseInt(numbers[1], 10, 8)
vertices[j] = Coordinate{int(vx), int(vy)}
}
if scanner.Err() != nil {
panic(scanner.Err())
}
ponds[i] = Pond{vertices}
}
if scanner.Err() != nil {
panic(scanner.Err())
}
return ponds
}

26
structs.go Normal file
View File

@@ -0,0 +1,26 @@
package main
import "math"
type Coordinate struct {
x, y int
}
type Path struct {
start, end Coordinate
}
type Pond struct {
vertices []Coordinate
}
type Map struct {
paths []Path
ponds []Pond
}
func (current Coordinate) distance(other Coordinate) float64 {
dx := math.Abs(float64(current.x - other.x))
dy := math.Abs(float64(current.y - other.y))
return math.Sqrt(dx*dx + dy*dy)
}