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)
|
scanner := bufio.NewScanner(file)
|
||||||
for scanner.Scan() {
|
for scanner.Scan() {
|
||||||
text := scanner.Text()
|
text := scanner.Text()
|
||||||
minString := inputRegex.ReplaceAllString(text, "$1")
|
min, _ := strconv.Atoi(inputRegex.ReplaceAllString(text, "$1"))
|
||||||
min, _ := strconv.Atoi(minString)
|
max, _ := strconv.Atoi(inputRegex.ReplaceAllString(text, "$2"))
|
||||||
maxString := inputRegex.ReplaceAllString(text, "$2")
|
passwords = append(passwords, &password{
|
||||||
max, _ := strconv.Atoi(maxString)
|
|
||||||
pw := &password{
|
|
||||||
min: min,
|
min: min,
|
||||||
max: max,
|
max: max,
|
||||||
letter: inputRegex.ReplaceAllString(text, "$3"),
|
letter: inputRegex.ReplaceAllString(text, "$3"),
|
||||||
password: inputRegex.ReplaceAllString(text, "$4"),
|
password: inputRegex.ReplaceAllString(text, "$4"),
|
||||||
}
|
})
|
||||||
passwords = append(passwords, pw)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
correct := 0
|
correct := 0
|
||||||
|
|
15
2/2/main.go
15
2/2/main.go
|
@ -38,24 +38,19 @@ func main() {
|
||||||
scanner := bufio.NewScanner(file)
|
scanner := bufio.NewScanner(file)
|
||||||
for scanner.Scan() {
|
for scanner.Scan() {
|
||||||
text := scanner.Text()
|
text := scanner.Text()
|
||||||
firstString := inputRegex.ReplaceAllString(text, "$1")
|
first, _ := strconv.Atoi(inputRegex.ReplaceAllString(text, "$1"))
|
||||||
first, _ := strconv.Atoi(firstString)
|
second, _ := strconv.Atoi(inputRegex.ReplaceAllString(text, "$2"))
|
||||||
secondString := inputRegex.ReplaceAllString(text, "$2")
|
passwords = append(passwords, &password{
|
||||||
second, _ := strconv.Atoi(secondString)
|
|
||||||
pw := &password{
|
|
||||||
first: first,
|
first: first,
|
||||||
second: second,
|
second: second,
|
||||||
letter: inputRegex.ReplaceAllString(text, "$3"),
|
letter: inputRegex.ReplaceAllString(text, "$3"),
|
||||||
password: inputRegex.ReplaceAllString(text, "$4"),
|
password: inputRegex.ReplaceAllString(text, "$4"),
|
||||||
}
|
})
|
||||||
passwords = append(passwords, pw)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
correct := 0
|
correct := 0
|
||||||
for _, pw := range passwords {
|
for _, pw := range passwords {
|
||||||
firstChar := string(pw.password[pw.first-1])
|
if (string(pw.password[pw.first-1]) == pw.letter) != (string(pw.password[pw.second-1]) == pw.letter) {
|
||||||
secondChar := string(pw.password[pw.second-1])
|
|
||||||
if (firstChar == pw.letter && secondChar != pw.letter) || (firstChar != pw.letter && secondChar == pw.letter) {
|
|
||||||
correct++
|
correct++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Reference in New Issue