Improvements
This commit is contained in:
parent
93c849f5e1
commit
7aa693d0b7
11
2/1/main.go
11
2/1/main.go
|
@ -45,17 +45,14 @@ func main() {
|
|||
scanner := bufio.NewScanner(file)
|
||||
for scanner.Scan() {
|
||||
text := scanner.Text()
|
||||
minString := inputRegex.ReplaceAllString(text, "$1")
|
||||
min, _ := strconv.Atoi(minString)
|
||||
maxString := inputRegex.ReplaceAllString(text, "$2")
|
||||
max, _ := strconv.Atoi(maxString)
|
||||
pw := &password{
|
||||
min, _ := strconv.Atoi(inputRegex.ReplaceAllString(text, "$1"))
|
||||
max, _ := strconv.Atoi(inputRegex.ReplaceAllString(text, "$2"))
|
||||
passwords = append(passwords, &password{
|
||||
min: min,
|
||||
max: max,
|
||||
letter: inputRegex.ReplaceAllString(text, "$3"),
|
||||
password: inputRegex.ReplaceAllString(text, "$4"),
|
||||
}
|
||||
passwords = append(passwords, pw)
|
||||
})
|
||||
}
|
||||
|
||||
correct := 0
|
||||
|
|
15
2/2/main.go
15
2/2/main.go
|
@ -38,24 +38,19 @@ func main() {
|
|||
scanner := bufio.NewScanner(file)
|
||||
for scanner.Scan() {
|
||||
text := scanner.Text()
|
||||
firstString := inputRegex.ReplaceAllString(text, "$1")
|
||||
first, _ := strconv.Atoi(firstString)
|
||||
secondString := inputRegex.ReplaceAllString(text, "$2")
|
||||
second, _ := strconv.Atoi(secondString)
|
||||
pw := &password{
|
||||
first, _ := strconv.Atoi(inputRegex.ReplaceAllString(text, "$1"))
|
||||
second, _ := strconv.Atoi(inputRegex.ReplaceAllString(text, "$2"))
|
||||
passwords = append(passwords, &password{
|
||||
first: first,
|
||||
second: second,
|
||||
letter: inputRegex.ReplaceAllString(text, "$3"),
|
||||
password: inputRegex.ReplaceAllString(text, "$4"),
|
||||
}
|
||||
passwords = append(passwords, pw)
|
||||
})
|
||||
}
|
||||
|
||||
correct := 0
|
||||
for _, pw := range passwords {
|
||||
firstChar := string(pw.password[pw.first-1])
|
||||
secondChar := string(pw.password[pw.second-1])
|
||||
if (firstChar == pw.letter && secondChar != pw.letter) || (firstChar != pw.letter && secondChar == pw.letter) {
|
||||
if (string(pw.password[pw.first-1]) == pw.letter) != (string(pw.password[pw.second-1]) == pw.letter) {
|
||||
correct++
|
||||
}
|
||||
}
|
||||
|
|
Reference in New Issue