-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathp144.cpp
More file actions
38 lines (34 loc) · 874 Bytes
/
Copy pathp144.cpp
File metadata and controls
38 lines (34 loc) · 874 Bytes
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
#include <iostream>
#include "euler/cartesian.hpp"
#include "euler.h"
BEGIN_PROBLEM(144, solve_problem_144)
PROBLEM_TITLE("Multiple reflections of a laser beam")
PROBLEM_ANSWER("354")
PROBLEM_DIFFICULTY(1)
PROBLEM_FUN_LEVEL(2)
PROBLEM_TIME_COMPLEXITY("N")
PROBLEM_SPACE_COMPLEXITY("1")
PROBLEM_KEYWORDS("geometry")
END_PROBLEM()
using namespace euler::cartesian2d;
static void solve_problem_144()
{
ellipse<double> e(5.0, 10.0);
point<double> p0(0.0, 10.1), p1(1.4, -9.6);
int reflections = 1;
for (; ; ++reflections)
{
point<double> p2 = mirror(p0, normal_line(e, p1));
line<double> l(p1, p2);
intersect(l, e, p0, p1);
if (verbose())
{
std::cout << "Reflection: " << p1.x << ", " << p1.y << std::endl;
}
if (p1.y > 0 && fabs(p1.x) < 0.01)
{
break;
}
}
std::cout << reflections << std::endl;
}