Skip to content

Latest commit

 

History

History

176-ray-of-light

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 

Ray of Light

Challenge Description:

You are given a plan of a room with 10×10 cells size. The walls in the room are marked with a number sign ‘#’. They are specular and they reflect light. If a ray hits a corner of the room, its distribution stops:

-------    -------
-#####-    -#####-
-  /\#-    -   /#-
- / /#-    -  / #-
-/ / #-    - /  #-
/------    -/-----

There can be columns and prisms in the room at a distance at least 1 cell from the walls.

The columns are marked with the ‘o’ symbol. They absorb light. If a ray hits a column, its distribution stops:

-------
-     -
-  o  -
- /   -
-/    -
/------

The prisms are marked with an asterisk ‘*’. They split a ray into three parts. One of them goes in the same direction as the original ray, two others are turned by ±90°:

------
- \ /-
-  * -
- / \-
-/   -
/-----

There is a hole in one of the walls. A ray of light is let into the room through the hole at an angle aliquot to 45° to the walls:

##########
#        #
#  o  o  #
#    o o #
# o   *o #
# o o    #
# * * *o #
#        #
#        #
###/######

Show the path of light distribution using pseudo-graphics. Use slash ‘/’ to show the fragment turned to 45° or 225°, backslash ‘\’ to show the fragment turned to 315° or 135°, and ‘X’ symbol to show the fragment where two rays are crossed:

##########
#\   /\  #
# \o/ o\ #
#  X o o\#
# o \ *o/#
# o o\ / #
# * * *o #
#    / \ #
#   /   \#
###/######

The maximum distance of light distribution is 20 cells, including the first and the last cells, but excluding the cells with prisms.

Input sample:

The first argument is a file with test cases. Each line contains serialized plan of a room, starting from the upper-left cell.

For example:

###########        ##  o  o  ##    o o ## o   *o ## o o    ## * * *o ##        ##        ####/######
###########        ##    *   ## *      ##    *   ##   *    ##     ** ##     ** ##        ####/######
###########        ##    * o ##  o     #/    o   ## o *    ##        ##        ##        ###########

Output sample:

Show the path of light distribution on the plan, using pseudo-graphics. Print the result to stdout in a serialized way similarly to the input.

For example:

###########\   /\  ## \o/ o\ ##  X o o\## o \ *o/## o o\ / ## * * *o ##    / \ ##   /   \####/######
###########\ /\/X\ ## X /* \\##/*X/ \ X##\//\* X/##/X *\//\##X \ /**/##\\ X/** ## \X/\/ \####X######
###########  /\ /\ ## /  * o\##/ o/ \ /#/  / o X ## o * / \##/ \ /  /##\  X  / ## \/ \/  ###########

Constraints:

  1. A room size is 10×10 cells.
  2. The maximum distance of light distribution is 20 cells, including the first and the last cells, but excluding the cells with prisms.
  3. There are 40 test cases in the input.