From 2f0e5bc87b027358157d81503445e00e6e9b72d9 Mon Sep 17 00:00:00 2001 From: 3013050 <3013050@stud.hs-mannheim.de> Date: Tue, 3 Dec 2024 02:07:51 +0100 Subject: [PATCH] Added solutions --- Aufgabe1/circle.go | 16 ++++++++++++++++ Aufgabe1/test.go | 6 ------ Aufgabe2/wordcount.go | 25 +++++++++++++++++++++++++ Aufgabe3/channelZählen.go | 26 ++++++++++++++++++++++++++ KompliziertereAufgabe/main.go | 0 Vortrag/bascis.go => bascis.go | 5 +++++ 6 files changed, 72 insertions(+), 6 deletions(-) create mode 100644 Aufgabe1/circle.go delete mode 100644 Aufgabe1/test.go create mode 100644 Aufgabe2/wordcount.go create mode 100644 Aufgabe3/channelZählen.go delete mode 100644 KompliziertereAufgabe/main.go rename Vortrag/bascis.go => bascis.go (85%) diff --git a/Aufgabe1/circle.go b/Aufgabe1/circle.go new file mode 100644 index 0000000..e20da9f --- /dev/null +++ b/Aufgabe1/circle.go @@ -0,0 +1,16 @@ +package main + +import ( + "fmt" + "math" +) + +type Circle struct { + radius float64 +} + +func main() { + circle := Circle{radius: 6.4} + circumference := 2 * math.Pi * circle.radius + fmt.Println(circumference) +} diff --git a/Aufgabe1/test.go b/Aufgabe1/test.go deleted file mode 100644 index 95eefaa..0000000 --- a/Aufgabe1/test.go +++ /dev/null @@ -1,6 +0,0 @@ -package main - -import "fmt" - -//Idee: Wordcount nutzt forloops und bisschen logik - diff --git a/Aufgabe2/wordcount.go b/Aufgabe2/wordcount.go new file mode 100644 index 0000000..184253f --- /dev/null +++ b/Aufgabe2/wordcount.go @@ -0,0 +1,25 @@ +package main + +import ( + "fmt" + "strings" +) + +func main() { + fruits := "ananas orange apfel apfel\n aprikose kirche" + + words := strings.Split(fruits, " ") + + wordCount := make(map[string]int) + + for _, word := range words { + word = strings.ReplaceAll(word, "\n", ""); // Wenn man newlines entfernen will + if strings.HasPrefix(word, "a") { + wordCount[word]++ + } + } + + for word, count := range wordCount { + fmt.Printf("%T: %v \n", word, count); + } +} diff --git a/Aufgabe3/channelZählen.go b/Aufgabe3/channelZählen.go new file mode 100644 index 0000000..c9c4672 --- /dev/null +++ b/Aufgabe3/channelZählen.go @@ -0,0 +1,26 @@ +package main + +import "fmt" + +func count(start, end int, ch chan int) { + for i := start; i <= end; i++ { + ch <- i + } +} + +func printCh(ch chan int) { + for i := 0; i < 10; i++ { + fmt.Println(<-ch) + } +} + +func main() { + channel1to5 := make(chan int) + channel6to10 := make(chan int) + + go count(1, 10, channel1to5) + go count(6, 10, channel6to10) + + printCh(channel1to5) + printCh(channel6to10) +} diff --git a/KompliziertereAufgabe/main.go b/KompliziertereAufgabe/main.go deleted file mode 100644 index e69de29..0000000 diff --git a/Vortrag/bascis.go b/bascis.go similarity index 85% rename from Vortrag/bascis.go rename to bascis.go index 3d7595e..ba3f210 100644 --- a/Vortrag/bascis.go +++ b/bascis.go @@ -26,6 +26,11 @@ func main() { fmt.Printf("%d + %d = %d \n", num2, num, result); + for i := 0; i <= 6; i++ { // Alle Zahlen von 0 - 6 + if i%2 == 0 { // Filtert nach gerade Zahlen + fmt.Println(i); + } + } text := "Willkommen zu unserem Go Vortrag!"; words := strings.Fields(text);