diff --git a/internal/2016/DayTwo/code.go b/internal/2016/DayTwo/code.go new file mode 100644 index 0000000..f599db7 --- /dev/null +++ b/internal/2016/DayTwo/code.go @@ -0,0 +1,57 @@ +package daytwo + +import ( + "advent-of-code/internal/registry" + "os" + "strings" +) + +func init() { + registry.Register("2016D2", ParseInput, PartOne, PartTwo) +} + +func ParseInput(filepath string) []string { + content, _ := os.ReadFile(filepath) + return strings.Split(string(content), "\n") +} + +func PartOne(instructions []string) int { + row, column := 1, 1 + + keypad := [3][3]int{ + {1, 2, 3}, + {4, 5, 6}, + {7, 8, 9}, + } + code := 0 + + for _, line := range instructions { + for _, move := range line { + switch move { + case 'U': + if row > 0 { + row-- + } + case 'D': + if row < 2 { + row++ + } + case 'L': + if column > 0 { + column-- + } + case 'R': + if column < 2 { + column++ + } + } + } + code = code*10 + keypad[row][column] + } + + return code +} + +func PartTwo(data []string) int { + return 0 +}