Piotr Czajkowski 2 years ago
parent
commit
a10c4ecf41
1 changed files with 5 additions and 2 deletions
  1. 5 2
      14/code.go

+ 5 - 2
14/code.go

@@ -36,7 +36,7 @@ func readInput(file string) (map[string]int, map[string][]string) {
 			log.Fatal("Invalid line: ", line)
 		}
 
-		input[parts[0]] = []string{fmt.Sprintf("%s%s", parts[0][0], parts[1]), fmt.Sprintf("%s%s", parts[0][1], parts[1])}
+		input[parts[0]] = []string{fmt.Sprintf("%c%s", parts[0][0], parts[1]), fmt.Sprintf("%s%c", parts[1], parts[0][1])}
 	}
 
 	return template, input
@@ -66,11 +66,14 @@ func countElements(template map[string]int) (int, int) {
 
 func part1(template map[string]int, input map[string][]string) (map[string]int, int) {
 	for i := 0; i < 10; i++ {
+		newTemplate := make(map[string]int)
 		for k, v1 := range template {
 			for _, v2 := range input[k] {
-				template[v2] += v1
+				newTemplate[v2] += v1
 			}
 		}
+
+		template = newTemplate
 	}
 
 	smallest, largest := countElements(template)