What if we have a corridor comprised of two parallel mirrors?
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
Now, we shine a laser down it...
| \ |
| \ |
| \ |
| \ |
| \ |
| \ |
| \ |
| \|
| /|
| / |
Oh, look. It bounced, towards the end, there.
What if we draw two lasers BUT going in the opposite direction?
| \ / |
| \ / |
| \/ |
| /\ |
| / \ |
| / \ |
| / \ |
|/ \|
|\ /|
| \ / |
Hmm, they didn't seem to meet, there. That's convenient. What happens if both lasers take up the same space?
| \ / |
| \ / |
| \ / |
| X |
| / \ |
| / \ |
| / \ |
| / \|
|/ /|
|\ / |
I guess that was pretty obvious, huh?
Drawing these diagrams by hand is pretty laborious (trust me on this). Perhaps some code could do it for us?
- Write some code to output two parallel mirrors, with two bouncing, intersecting lasers.
- Input (all integers):
- The width of the corridor
- The length of the corridor
- Starting position of the right-going laser (zero-indexed, must be less than width)
- Starting position of the left-going laser (zero-indexed, must be less than width)
- Process
- If a laser is right going, it will be drawn one space to the right on the following line.
- If a laser is left going, it will be drawn one space to the left on the following line.
- If a laser can not take it's sideways step, it will change it's direction, but not it's position.
- If both laser are at the same index, print an upper-case X at that index.
- Output
- A string with multiple lines
- Each line starts and ends with a pipe character (|)
- Right-going laser are denoted by a back slash (\)
- Left-going laser are denoted by a forward slash (/)
- The intersection of two lasers is denoted by an upper-case X.
- Any language
- I'd like to see TIO links
- Attempt to fix it in the smallest number of bytes
Test cases
width: 6 length: 10 right-going: 1 left-going: 4
| \ / |
| \/ |
| /\ |
| / \ |
|/ \|
|\ /|
| \ / |
| \/ |
| /\ |
| / \ |
width: 6 length: 10 right-going: 0 left-going: 1
|\/ |
|/\ |
|\ \ |
| \ \ |
| \ \ |
| \ \|
| \/|
| /\|
| / /|
| / / |
width: 4 length: 10 right-going: 2 left-going: 0
|/ \ |
|\ \|
| \ /|
| X |
| / \|
|/ /|
|\ / |
| X |
|/ \ |
|\ \|
width: 20 length: 5 right-going: 5 left-going: 15
| \ / |
| \ / |
| \ / |
| \ / |
| \ / |
width: 5 length: 6 right-going: 2 left-going: 2
| X |
| / \ |
|/ \|
|\ /|
| \ / |
| X |
width: 1 length: 2 right-going: 0 left-going: 0
|X|
|X|