Browse Source

Works for small

Piotr Czajkowski 1 year ago
parent
commit
8f94079ebf
2 changed files with 15 additions and 1 deletions
  1. 15 1
      20/code.go
  2. 0 0
      20/input

+ 15 - 1
20/code.go

@@ -91,6 +91,19 @@ func mix(numbers []int) []int {
 	return mixed
 }
 
+func part1(mixed []int) int {
+	zeroIndex := indexOf(mixed, 0)
+	result := 0
+	size := len(mixed)
+
+	for i := 1; i < 4; i++ {
+		newIndex := establishNewIndex(size, zeroIndex, i*1000)
+		result += mixed[newIndex-1]
+	}
+
+	return result
+}
+
 func main() {
 	if len(os.Args) < 2 {
 		log.Fatal("You need to specify a file!")
@@ -104,5 +117,6 @@ func main() {
 	}
 
 	numbers := readInput(file)
-	fmt.Println(mix(numbers))
+	mixed := mix(numbers)
+	fmt.Println("Part1:", part1(mixed))
 }

+ 0 - 0
20/description.txt → 20/input