A 2D board will contain the following objects:
^
,>
,v
, or <
: A laser emitter facing up, right, down, or left respectively. There may be more than one. Lasers will travel in a straight line in empty space (empty space is represented with a dot .
). Lasers do not pass through emitters.
*
: A target. Lasers pass through targets. There may be more than one.
The board may also contain the following objects:
@
: A solid wall. The laser will not pass through here.
\
: A left-leaning reflector. Changes the direction of lasers according to the following table:
Direction of laser before Direction of laser after hitting reflector
Up Left
Left Down
Down Right
Right Up
It should be pretty intuitive as to how the reflectors work. Just imagine them as an actual two-sided mirror and the directions should be clear.
/
: A right-leaning reflector. Changes the direction of lasers according to the following table:
Direction of laser before Direction of laser after hitting reflector
Up Right
Left Up
Down Left
Right Down
1
,2
,3
...9
: A portal. The number indicates the channel of the portal - there will be exactly two portals of the same channel (for instance, there won't be three 1
's). The portal changes the position of lasers to the position of the other portal of the same channel. For instance:
> 1 @ 1 *
The laser will hit the target because when it hits the first 1
, it is teleported to the second 1
on the other side. Lasers retain the same direction that they were in before.
A portal will not teleport the laser to a portal of a different channel (i.e. a 1
won't teleport the laser to a 9
.
Your program will recieve a 2D representation of the board as input. The board will always be rectangular shaped. The output should be True
if all the targets have lasers passing through them, or False
otherwise.
Here are some test cases:
Input
>....\
..*...
>./../
..*...
Output
True
Input
>..........\
1........../
2..........1
3..........2
4..........3
5..........4
6..........5
7..........6
8..........7
9..........8
*..........9
Output
True
Input
>.@............*
>..@...........*
>...@..........*
>....@.........*
>.....@........*
>...*..@........
>.......@......*
Output
False
Input
../\.
>./**
Output
False
Input
/.......*.......\/3.....
@..............//\.\....
*.............2\.1\/\...
\..............///.....<
.........*...//\\/.....\
>.............\.1.///.4.
4.......*/...\2\/3/\/..^
Output
True
Input
vvvvvvvvvvvvvvvvv
\\\\\\\\\\\\\\\\\
/////////////////
\\\\\\\\\\\\\\\\\
/////////////////
\\\\\\\\\\\\\\\\\
/////////////////
*****************
Output (note the target at the far right)
False