From 3f49055c82a8885e108d1bac3226654f156fad58 Mon Sep 17 00:00:00 2001 From: Julien Dessaux Date: Sun, 19 Dec 2021 21:28:34 +0100 Subject: Added solutions for 17th day: target practice --- 2021/17/second.go | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 2021/17/second.go (limited to '2021/17/second.go') diff --git a/2021/17/second.go b/2021/17/second.go new file mode 100644 index 0000000..49eb9cb --- /dev/null +++ b/2021/17/second.go @@ -0,0 +1,54 @@ +package main + +import ( + "bufio" + "fmt" + "os" + "strconv" + "strings" +) + +type vector struct { + x, y int +} + +func main() { + scanner := bufio.NewScanner(os.Stdin) + scanner.Scan() + line := scanner.Text() + elts := strings.Split(line, "..") + eltsx1 := strings.Split(elts[0], "=") + x1, _ := strconv.Atoi(eltsx1[1]) + eltsx2 := strings.Split(elts[1], ",") + x2, _ := strconv.Atoi(eltsx2[0]) + eltsy1 := strings.Split(elts[1], "=") + y1, _ := strconv.Atoi(eltsy1[1]) + y2, _ := strconv.Atoi(elts[2]) + + possible := 0 + for nextVx := 0; nextVx <= x2; nextVx++ { + out: + for nextVy := y1; nextVy < 1000; nextVy++ { + vx := nextVx + vy := nextVy + x := 0 + y := 0 + for { + if x >= x1 && x <= x2 && y >= y1 && y <= y2 { + possible++ + continue out + } + if x > x2 || y < y1 { + break + } + if vx >= 0 { + x += vx + vx-- + } + y += vy + vy-- + } + } + } + fmt.Println(possible) +} -- cgit v1.2.3