diff --git a/challenge-1/submissions/brenoamin/solution-template.go b/challenge-1/submissions/brenoamin/solution-template.go new file mode 100644 index 000000000..479c17741 --- /dev/null +++ b/challenge-1/submissions/brenoamin/solution-template.go @@ -0,0 +1,24 @@ +package main + +import ( + "fmt" +) + +func main() { + var a, b int + // Read two integers from standard input + _, err := fmt.Scanf("%d, %d", &a, &b) + if err != nil { + fmt.Println("Error reading input:", err) + return + } + + // Call the Sum function and print the result + result := Sum(a, b) + fmt.Println(result) +} + +// Sum returns the sum of a and b. +func Sum(a int, b int) int { + return a + b +} diff --git a/challenge-6/submissions/brenoamin/solution-template.go b/challenge-6/submissions/brenoamin/solution-template.go new file mode 100644 index 000000000..344f76d59 --- /dev/null +++ b/challenge-6/submissions/brenoamin/solution-template.go @@ -0,0 +1,37 @@ +// Package challenge6 contains the solution for Challenge 6. +package challenge6 + +import ( + "regexp" + "strings" +) + +// CountWordFrequency takes a string containing multiple words and returns +// a map where each key is a word and the value is the number of times that +// word appears in the string. The comparison is case-insensitive. +// +// Words are defined as sequences of letters and digits. +// All words are converted to lowercase before counting. +// All punctuation, spaces, and other non-alphanumeric characters are ignored. +// +// For example: +// Input: "The quick brown fox jumps over the lazy dog." +// Output: map[string]int{"the": 2, "quick": 1, "brown": 1, "fox": 1, "jumps": 1, "over": 1, "lazy": 1, "dog": 1} +func CountWordFrequency(text string) map[string]int { + freq := make(map[string]int) + + re := regexp.MustCompile(`[^a-zA-Z0-9']+`) + cleaned := strings.ReplaceAll(re.ReplaceAllString(strings.ToLower(text), " "), "'", "") + fields := strings.Fields(cleaned) + + for _, word := range fields { + _, exists := freq[word] + if exists { + freq[word]++ + continue + } + freq[word] = 1 + } + + return freq +}