aboutsummaryrefslogtreecommitdiff
path: root/2021/17/second.go
blob: 49eb9cb3885aa9668e067ffeeebed4fae567e8ec (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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)
}