-
Notifications
You must be signed in to change notification settings - Fork 1
/
Problem144.go
64 lines (45 loc) · 995 Bytes
/
Problem144.go
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
55
56
57
58
59
60
61
62
63
64
package main
import (
"fmt"
"math"
)
func getL(m float64, b float64) (x float64, y float64) {
x = (-b*m - 2*math.Sqrt(100-(b*b)+(25*m*m))) / (4 + m*m)
y = m*x + b
return
}
func getR(m float64, b float64) (x float64, y float64) {
x = (-b*m + 2*math.Sqrt(100-(b*b)+(25*m*m))) / (4 + m*m)
y = m*x + b
return
}
func normal(x float64, y float64) float64 {
return y / (4 * x)
}
func reflect(n float64, m float64) float64 {
return (2*n - m*(1-(n*n))) / (1 + (2 * m * n) - (n * n))
}
func findB(x float64, y float64, m float64) float64 {
return (-m * x) + y
}
func main() {
m := -(197.0 / 14.0)
b := 10.1
x, y := getR(m, b)
//fmt.Println("{", x, ",", y, "}, ")
count := 0
for math.Abs(x) > .01 || y < 0 {
m = reflect(normal(x, y), m)
b = findB(x, y, m)
l, _ := getL(m, b)
r, _ := getR(m, b)
if math.Abs(l-x) > math.Abs(r-x) {
x, y = getL(m, b)
} else {
x, y = getR(m, b)
}
//fmt.Println("{", x, ",", y, "}, ")
count++
}
fmt.Println(count)
}