Browse Source

You won't solve it by brute force

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

+ 16 - 2
14/code.go

@@ -76,7 +76,7 @@ func countElements(template string) (int, int) {
 	return smallest, largest
 }
 
-func part1(template string, input map[string]string) int {
+func part1(template string, input map[string]string) (string, int) {
 	result := template
 	for i := 0; i < 10; i++ {
 		result = process(result, input)
@@ -84,6 +84,17 @@ func part1(template string, input map[string]string) int {
 
 	smallest, largest := countElements(result)
 
+	return result, largest - smallest
+}
+
+func part2(template string, input map[string]string) int {
+	result := template
+	for i := 0; i < 30; i++ {
+		result = process(result, input)
+	}
+
+	smallest, largest := countElements(result)
+
 	return largest - smallest
 }
 
@@ -93,5 +104,8 @@ func main() {
 	}
 
 	template, input := readInput(os.Args[1])
-	fmt.Println("Part1:", part1(template, input))
+	var diff int
+	template, diff = part1(template, input)
+	fmt.Println("Part1:", diff)
+	fmt.Println("Part1:", part2(template, input))
 }