diff --git a/Assignment/Assignment1/p1.go b/Assignment/Assignment1/p1.go index ae5421f..70ce9a3 100644 --- a/Assignment/Assignment1/p1.go +++ b/Assignment/Assignment1/p1.go @@ -24,6 +24,11 @@ Output: -1 func DivideWhole(a int, b int) int { // TODO: Your code here - return 0 -} - + var result int + if b == 0 { + result = -1 + }else{ + result = a/b + } + return result +} \ No newline at end of file diff --git a/Assignment/Assignment1/p2.go b/Assignment/Assignment1/p2.go index b0c0ea6..aa9a169 100644 --- a/Assignment/Assignment1/p2.go +++ b/Assignment/Assignment1/p2.go @@ -1,5 +1,10 @@ package Assignment1 +import ( + "unicode" + "strings" + "regexp" +) /* Clean up sentences. [WEIGHT = 1] @@ -32,6 +37,19 @@ Explanation: Replace the : and , and then remove all trailing/leading spaces func CleanUp(s string) string { // TODO: Your code here - return "" -} + cleaned := "" + space := regexp.MustCompile(`\s+`) + for _, val := range s { + if unicode.IsLetter(val) || unicode.IsNumber(val) || unicode.IsSpace(val) { + cleaned += string(val) + } + } + // Remove leading and trailing spaces + trimCleaned := strings.TrimSpace(cleaned) + + // Remove duplicate space + result := space.ReplaceAllString(trimCleaned, " ") + + return result +} \ No newline at end of file diff --git a/Assignment/Assignment1/p3.go b/Assignment/Assignment1/p3.go index 031362d..359cf95 100644 --- a/Assignment/Assignment1/p3.go +++ b/Assignment/Assignment1/p3.go @@ -21,6 +21,13 @@ Explanation: All numbers are odd, so return 0 func EvenSum(nums []int) int { // TODO: Your code here - return 0 -} - + result:= 0 + for _ , val := range nums { + if val!= 0 && val % 2 == 0 { + result += val + }else{ + result += 0 + } + } + return result +} \ No newline at end of file