Browse Source

Solve 2020/04/first

master
Garrit Franke 3 years ago
parent
commit
60595b1f0a
  1. 3
      2020/4/go.mod
  2. 1133
      2020/4/input.txt
  3. 59
      2020/4/main.go

3
2020/4/go.mod

@ -0,0 +1,3 @@
module 3
go 1.15

1133
2020/4/input.txt

File diff suppressed because it is too large Load Diff

59
2020/4/main.go

@ -0,0 +1,59 @@
package main
import (
"fmt"
"io/ioutil"
"regexp"
"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{} {
passports := make([]string, 0)
current := ""
for _, line := range lines {
if line == "" {
passports = append(passports, current)
current = ""
} else {
current += (line + " ")
}
}
passports = append(passports, current)
sumValid := 0
// && regexp.MustCompile(`(byr&iyr&eyr:)`).MatchString(passport) && regexp.MustCompile(`(byr&iyr&eyr:)`).MatchString(passport)
for _, passport := range passports {
valid := regexp.MustCompile(`(byr:)`).MatchString(passport)
valid = valid && regexp.MustCompile(`(iyr:)`).MatchString(passport)
valid = valid && regexp.MustCompile(`(eyr:)`).MatchString(passport)
valid = valid && regexp.MustCompile(`(hgt:)`).MatchString(passport)
valid = valid && regexp.MustCompile(`(hcl:)`).MatchString(passport)
valid = valid && regexp.MustCompile(`(ecl:)`).MatchString(passport)
valid = valid && regexp.MustCompile(`(pid:)`).MatchString(passport)
if valid {
sumValid++
}
}
return sumValid
}
func second(lines []string) interface{} {
return 0
}
Loading…
Cancel
Save