Browse Source

Rename directories

master
Garrit Franke 3 years ago
parent
commit
b62ceaff3a
  1. 2
      .gitignore
  2. 0
      2020/Day1/first/go.mod
  3. 0
      2020/Day1/first/input.txt
  4. 0
      2020/Day1/first/main.go
  5. 0
      2020/Day1/second/go.mod
  6. 0
      2020/Day1/second/input.txt
  7. 0
      2020/Day1/second/main.go
  8. 0
      2020/Day2/go.mod
  9. 0
      2020/Day2/input.txt
  10. 0
      2020/Day2/main.go
  11. 0
      2020/Day3/go.mod
  12. 0
      2020/Day3/input.txt
  13. 0
      2020/Day3/main.go
  14. 0
      2020/Day4/go.mod
  15. 0
      2020/Day4/input.txt
  16. 0
      2020/Day4/main.go
  17. 0
      2020/Day5/go.mod
  18. 0
      2020/Day5/input.txt
  19. 0
      2020/Day5/main.go
  20. 2046
      2020/Day6/input.txt
  21. 87
      2020/Day6/main.go

2
.gitignore vendored

@ -0,0 +1,2 @@
main
target/

0
2020/1/first/go.mod → 2020/Day1/first/go.mod

0
2020/1/first/input.txt → 2020/Day1/first/input.txt

0
2020/1/first/main.go → 2020/Day1/first/main.go

0
2020/1/second/go.mod → 2020/Day1/second/go.mod

0
2020/1/second/input.txt → 2020/Day1/second/input.txt

0
2020/1/second/main.go → 2020/Day1/second/main.go

0
2020/2/go.mod → 2020/Day2/go.mod

0
2020/2/input.txt → 2020/Day2/input.txt

0
2020/2/main.go → 2020/Day2/main.go

0
2020/3/go.mod → 2020/Day3/go.mod

0
2020/3/input.txt → 2020/Day3/input.txt

0
2020/3/main.go → 2020/Day3/main.go

0
2020/4/go.mod → 2020/Day4/go.mod

0
2020/4/input.txt → 2020/Day4/input.txt

0
2020/4/main.go → 2020/Day4/main.go

0
2020/5/go.mod → 2020/Day5/go.mod

0
2020/5/input.txt → 2020/Day5/input.txt

0
2020/5/main.go → 2020/Day5/main.go

2046
2020/Day6/input.txt

File diff suppressed because it is too large Load Diff

87
2020/Day6/main.go

@ -0,0 +1,87 @@
package main
import (
"fmt"
"io/ioutil"
"strings"
)
func main() {
data, err := ioutil.ReadFile("input.txt")
if err != nil {
fmt.Println("File reading error", err)
return
}
lines := strings.Split(string(data), "\n")
fmt.Println("First result:", first(lines))
fmt.Println("Second result:", second(lines))
}
func first(lines []string) interface{} {
groups := make([]string, 0)
current := ""
for _, line := range lines {
if line == "" {
groups = append(groups, current)
current = ""
} else {
current += line
}
}
groups = append(groups, current)
sum := 0
for _, group := range groups {
unique := string(unique([]byte(group)))
len := len(unique)
sum += len
}
return sum
}
func second(lines []string) interface{} {
groups := make([]string, 0)
current := ""
for _, line := range lines {
if line == "" {
groups = append(groups, current)
current = ""
} else {
current += line
}
}
groups = append(groups, current)
sum := 0
for _, group := range groups {
unique := string(unique([]byte(group)))
len := len(unique)
sum += len
}
return sum
}
func unique(intSlice []byte) []byte {
keys := make(map[byte]bool)
list := []byte{}
for _, entry := range intSlice {
if _, value := keys[entry]; !value {
keys[entry] = true
list = append(list, entry)
}
}
return list
}
Loading…
Cancel
Save