name my functions to proper set theory

This commit is contained in:
David 2020-12-06 14:10:21 -05:00
parent 5a9e07c174
commit 708c4a53f9

View File

@ -12,7 +12,7 @@ func main() {
partTwo() partTwo()
} }
func unique(s string) string { func union(s string) string {
result := "" result := ""
for _, r := range s { for _, r := range s {
@ -24,7 +24,7 @@ func unique(s string) string {
return result return result
} }
func union(s, q string) string { func intersection(s, q string) string {
result := "" result := ""
for _, r := range s { for _, r := range s {
@ -56,13 +56,13 @@ func partOne() {
for scanner.Scan() { for scanner.Scan() {
line := scanner.Text() line := scanner.Text()
if line == "" { if line == "" {
sum = sum + len(unique(currentForm)) sum = sum + len(union(currentForm))
currentForm = "" currentForm = ""
} else { } else {
currentForm = currentForm + line currentForm = currentForm + line
} }
} }
sum = sum + len(unique(currentForm)) sum = sum + len(union(currentForm))
fmt.Println(sum) fmt.Println(sum)
} }
@ -87,7 +87,7 @@ func partTwo() {
newgroup = false newgroup = false
} else { } else {
if line != "" { if line != "" {
currentForm = union(currentForm, line) currentForm = intersection(currentForm, line)
} else { } else {
sum = sum + len(currentForm) sum = sum + len(currentForm)
newgroup = true newgroup = true