|
@@ -9,6 +9,8 @@ import (
|
|
|
|
|
|
|
|
var path []byte = []byte{'r', 'o', 'y', 'g', 'b', 'v'}
|
|
var path []byte = []byte{'r', 'o', 'y', 'g', 'b', 'v'}
|
|
|
|
|
|
|
|
|
|
+const startFrom byte = 'r'
|
|
|
|
|
+
|
|
|
func getDistances() map[byte]map[byte]int {
|
|
func getDistances() map[byte]map[byte]int {
|
|
|
distances := make(map[byte]map[byte]int)
|
|
distances := make(map[byte]map[byte]int)
|
|
|
|
|
|
|
@@ -30,7 +32,7 @@ func getDistances() map[byte]map[byte]int {
|
|
|
|
|
|
|
|
func part1(program []byte, distances map[byte]map[byte]int) int {
|
|
func part1(program []byte, distances map[byte]map[byte]int) int {
|
|
|
var distance int
|
|
var distance int
|
|
|
- var current byte = 'r'
|
|
|
|
|
|
|
+ current := startFrom
|
|
|
|
|
|
|
|
for i := range program {
|
|
for i := range program {
|
|
|
distance += distances[current][program[i]]
|
|
distance += distances[current][program[i]]
|
|
@@ -42,7 +44,7 @@ func part1(program []byte, distances map[byte]map[byte]int) int {
|
|
|
|
|
|
|
|
func part2(program []byte, distances map[byte]map[byte]int) int {
|
|
func part2(program []byte, distances map[byte]map[byte]int) int {
|
|
|
var distance int
|
|
var distance int
|
|
|
- var current byte = 'r'
|
|
|
|
|
|
|
+ current := startFrom
|
|
|
|
|
|
|
|
moves := make(map[byte]int)
|
|
moves := make(map[byte]int)
|
|
|
for i := range program {
|
|
for i := range program {
|