diff options
Diffstat (limited to '2021/17/second.go')
-rw-r--r-- | 2021/17/second.go | 54 |
1 files changed, 54 insertions, 0 deletions
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) +} |