Browse Source

Solved part1

Piotr Czajkowski 2 years ago
parent
commit
5597f7da5a
2 changed files with 27 additions and 1 deletions
  1. 26 1
      17/code.go
  2. 1 0
      17/input

+ 26 - 1
17/code.go

@@ -90,11 +90,36 @@ func findMinXVelocity(xPoint point) int {
 	return 0
 }
 
+func simulateY(v int, yPoint point) int {
+	y := 0
+	largestY := y
+	previousY := y
+	for {
+		previousY = y
+		if y <= yPoint.max {
+			break
+		}
+
+		y += v
+		if y > largestY {
+			largestY = y
+		}
+		v--
+	}
+
+	if previousY >= yPoint.min && previousY <= yPoint.max {
+		return largestY
+	}
+
+	return 0
+}
+
 func main() {
 	if len(os.Args) < 2 {
 		log.Fatal("Please provide a file name as argument")
 	}
 
 	input := readInput(os.Args[1])
-	fmt.Println(findMinXVelocity(input[0]))
+	//fmt.Println(findMinXVelocity(input[0]))
+	fmt.Println("Part1:", simulateY(0-input[1].min-1, input[1]))
 }

+ 1 - 0
17/input

@@ -0,0 +1 @@
+target area: x=217..240, y=-126..-69