6 kyu

Will The DVD Logo Hit The Corner? - Efficiency Version

33 of 43KyleMeyers

Description:

Will The DVD Logo Hit The Corner

You've probably seen the meme where people want the DVD logo to hit the corner. But it won't always hit it. When will it?

DVD Logo Gif

To simplify the problem, instead of a rectangular logo, it's a singular point on a graph. If at any point it hits the corners of a rectangular grid, it counts as "hitting the corner"

The logo will only move in 45° angles, changing direction similarly to the gif above.

Given the size of the "TV screen", the starting position of the "logo", and its direction, determine if it will hit the corner or not.

Input

The parameters are:

  • w and h: The size of the screen (positive integers)
  • x and y: The position of the logo (non negative integers), bottom left is (0, 0)
  • d: The direction the logo will initially go in ("NE", "SE", "SW", or "NW")
  • All inputs are valid

Output

  • True if it will hit the corner (at any point)
  • False if it will not hit the corner
  • If it starts in a corner, that counts as a "hit"

Efficiency

Efficiency is a must. You must be able to complete inputs up to w or h being 1e30 without timing out.

Hint: Don't just simulate the entire process, find a smarter solution ;)

If the perfect algorithm is found, it can be completed in under 10ms, with no significant increase in time from small to huge numbers.

Examples

w = 12, h = 8, x = 5, y = 3, d = "NE" --> False

w = 12, h = 8, x = 5, y = 3, d = "SE" --> True

Have fun!

Algorithms
Performance

Similar Kata:

Stats:

CreatedMar 6, 2024
PublishedMar 7, 2024
Warriors Trained337
Total Skips8
Total Code Submissions1538
Total Times Completed43
Python Completions33
JavaScript Completions11
C# Completions8
Total Stars19
% of votes with a positive feedback rating92% of 12
Total "Very Satisfied" Votes10
Total "Somewhat Satisfied" Votes2
Total "Not Satisfied" Votes0
Total Rank Assessments5
Average Assessed Rank
6 kyu
Highest Assessed Rank
5 kyu
Lowest Assessed Rank
6 kyu
Ad
Contributors
  • KyleMeyers Avatar
  • hobovsky Avatar
  • dfhwze Avatar
Ad