Tap here to switch tabs
Problem
Submissions

Problem: Mirror Reflection

med
30 min
Try to solve the Mirror Reflection problem.

Statement

There is a square room with walls of length p. Each of the corners, except for the starting corner, contains a receptor:

  • Receptor 00 is located at (‘p‘,0)(`p`, 0)

  • Receptor 11 is located at (‘p‘,‘p‘)(`p`, `p`)

  • Receptor 22 is located at (0,‘p‘)(0, `p`)

A laser ray originates from the southwest corner (0,0)(0, 0) and travels in a straight line until it first hits the opposite wall at coordinates (‘p‘,‘q‘)(`p`, `q`). The ray continues to bounce off the walls according to the law of reflection until it strikes one of the receptors.

Return the identifier of the receptor (00, 11, or 22) that the ray encounters first.

Note: It is guaranteed that the ray will eventually strike a receptor.

Constraints:

  • 1≤1 \leq q ≤\leq p ≤1000\leq 1000

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Mirror Reflection

med
30 min
Try to solve the Mirror Reflection problem.

Statement

There is a square room with walls of length p. Each of the corners, except for the starting corner, contains a receptor:

  • Receptor 00 is located at (‘p‘,0)(`p`, 0)

  • Receptor 11 is located at (‘p‘,‘p‘)(`p`, `p`)

  • Receptor 22 is located at (0,‘p‘)(0, `p`)

A laser ray originates from the southwest corner (0,0)(0, 0) and travels in a straight line until it first hits the opposite wall at coordinates (‘p‘,‘q‘)(`p`, `q`). The ray continues to bounce off the walls according to the law of reflection until it strikes one of the receptors.

Return the identifier of the receptor (00, 11, or 22) that the ray encounters first.

Note: It is guaranteed that the ray will eventually strike a receptor.

Constraints:

  • 1≤1 \leq q ≤\leq p ≤1000\leq 1000