Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions Assignment/Assignment1/p1.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
22 changes: 20 additions & 2 deletions Assignment/Assignment1/p2.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package Assignment1

import (
"unicode"
"strings"
"regexp"
)
/*
Clean up sentences. [WEIGHT = 1]

Expand Down Expand Up @@ -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
}
13 changes: 10 additions & 3 deletions Assignment/Assignment1/p3.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}