The Wayback Machine - https://web.archive.org/web/20210831162149/https://github.com/TheAlgorithms/Python/pull/4280
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added solution for Project Euler problem 144 #4280

Merged
merged 4 commits into from Jul 8, 2021

Conversation

@fpringle
Copy link
Contributor

@fpringle fpringle commented Mar 20, 2021

Problem 144: Investigating multiple reflections of a laser beam

In laser physics, a "white cell" is a mirror system that acts as a delay line for the laser beam. The beam enters the cell, bounces around on the mirrors, and eventually works its way back out.

The specific white cell we will be considering is an ellipse with the equation 4x2 + y2 = 100

The section corresponding to −0.01 ≤ x ≤ +0.01 at the top is missing, allowing the light to enter and exit through the hole.

The light beam in this problem starts at the point (0.0,10.1) just outside the white cell, and the beam first impacts the mirror at (1.4,-9.6).

Each time the laser beam hits the surface of the ellipse, it follows the usual law of reflection "angle of incidence equals angle of reflection." That is, both the incident and reflected beams make the same angle with the normal line at the point of incidence.

In the figure on the left, the red line shows the first two points of contact between the laser beam and the wall of the white cell; the blue line shows the line tangent to the ellipse at the point of incidence of the first bounce.

The slope m of the tangent line at any point (x,y) of the given ellipse is: m = −4x/y

The normal line is perpendicular to this tangent line at the point of incidence.

The animation on the right shows the first 10 reflections of the beam.

How many times does the beam hit the internal surface of the white cell before exiting?

  • Add an algorithm?
  • Fix a bug or typo in an existing algorithm?
  • Documentation change?

Checklist:

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized.
  • I know that pull requests will not be merged if they fail the automated tests.
  • This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms.
  • All new Python files are placed inside an existing directory.
  • All filenames are in all lowercase characters with no spaces or dashes.
  • All functions and variable names follow Python naming conventions.
  • All function parameters and return values are annotated with Python type hints.
  • All functions have doctests that pass the automated testing.
  • All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation.
  • If this pull request resolves one or more open issues then the commit message contains Fixes: #{$ISSUE_NO}.
Copy link
Member

@L3str4nge L3str4nge left a comment

Please resolve conflicts.

Copy link
Member

@dhruvmanila dhruvmanila left a comment

Small nitpick and then this will be good to go. Thanks for doing this :)

project_euler/problem_144/sol1.py Outdated Show resolved Hide resolved
@stale
Copy link

@stale stale bot commented Jun 2, 2021

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Jun 2, 2021
@fpringle fpringle force-pushed the fpringle:problem_144 branch from 35765c6 to 6e686ec Jun 4, 2021
@stale stale bot removed the stale label Jun 4, 2021
@stale
Copy link

@stale stale bot commented Jul 8, 2021

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Jul 8, 2021
@XmenchoX
Copy link

@XmenchoX XmenchoX commented Jul 8, 2021

@stale stale bot removed the stale label Jul 8, 2021
@dhruvmanila dhruvmanila dismissed L3str4nge’s stale review Jul 8, 2021

Conflicts resolved.

@dhruvmanila dhruvmanila merged commit 8c13a77 into TheAlgorithms:master Jul 8, 2021
@fpringle fpringle deleted the fpringle:problem_144 branch Jul 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
4 participants