-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday02.go
36 lines (30 loc) · 832 Bytes
/
day02.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package day02
import (
"fmt"
"github.com/doniacld/adventofcode/internal/filereader"
"github.com/doniacld/adventofcode/puzzles/2020/02/policypasswd"
"github.com/doniacld/adventofcode/puzzles/solver"
)
func New(input string) solver.Solver {
return day02{input}
}
// day02 is the implementation of the first day!
type day02 struct {
fileName string
}
func (d day02) Solve() (string, error) {
lines, err := filereader.ExtractString(d.fileName)
if err != nil {
return "", err
}
occ, err := policypasswd.RetrieveValidPasswordsOccurrencePolicy(lines)
if err != nil {
return "", err
}
pos, err := policypasswd.RetrieveValidPasswordsPositionPolicy(lines)
if err != nil {
return "", err
}
out := fmt.Sprintf("Number of valid passwords for occurrency policy: %d & position policy: %d", occ, pos)
return out, nil
}