In this competition, you are given a random room with one candle inside. The goal is to write the shortest program (this is golf) that determines what parts of the room are illuminated by the candle, by replacing the dark spots with
@'s. The program should take a room from STDIN, with the output printed to STDOUT.
+------+ | C | | +--+ | \ | +---------+
The candle is represented with a
C, and the walls/mirrors are represented with
\. The walls themselves are mirrors. The corners of the room are represented with a
Rooms will never have diagonal walls, and light will never be able to escape out of the room.
Also, the first character on a line is always going to be part of the wall off the room. The absolute last character on each line is going to be the opposite wall of the room. No characters between these two are going to be outside of the room.
Light and Reflection
The candle emits eight (laser-like) beams of light in eight basic directions: N, S, E, W, NE, SE, SW, and NW. These rays of light bounce off of the mirrors as described below:
Old Direction of Travel | Mirror | New Direction N S E W NE SE SW NW / E W N S -- -- -- -- N S E W NE SE SW NW \ W E S N -- -- -- -- N S E W NE SE SW NW | - - - - NW SW NE SW N S E W NE SE SW NW - - - - - SE NE SW NE
- represents the light being absorbed. Light is always absorbed by C's or +'s. It is important to note that the lights reflects off of a mirror only when it is occupying the same space as the mirror. These rules are much easier to understand when you draw the reflection out on paper.
As output, the program should print an image of the illuminated room, with dark spots written as an
@, light spots left blank, and mirrors unaffected. For the above example, the output would be:
+------+ | C | |@ @ +--+ | @\ | +---------+
This means that, if you drew out the beams of light, they will never reach the spaces marked with
Input: +-----+ | | | | | C | | | | | +-----+ Output: +-----+ | @ @ | |@ @| | C | |@ @| | @ @ | +-----+ Input: +-----+ | \ | |/ C \+-+ | | | \ - ++ +------+ Output: +-----+ | \ @| |/ C \+-+ | @| | @\ -@++ +------+