Skip to main content
Tweeted twitter.com/#!/StackCodeGolf/status/509626272449052672
derp
Source Link
absinthe
  • 8.6k
  • 2
  • 33
  • 82
  • @: 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 beforeis travelling     Direction of laser after hitting reflector
     Up                                Left
     LeftRight                             Down
     Down                              Right
     RightLeft                              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 beforeis travelling     Direction of laser after hitting reflector
     Up                                Right
     LeftRight                             Up
     Down                              Left
     RightLeft                              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.

  • @: 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.

  • @: 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 laser is travelling     Direction of laser after hitting reflector
     Up                                Left
     Right                             Down
     Down                              Right
     Left                              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 laser is travelling     Direction of laser after hitting reflector
     Up                                Right
     Right                             Up
     Down                              Left
     Left                              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.

Source Link
absinthe
  • 8.6k
  • 2
  • 33
  • 82

Laser Mirror Portal Party

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:

  1. Input

    >....\
    ..*...
    >./../
    ..*...
    

    Output

    True
    
  2. Input

    >..........\
    1........../
    2..........1
    3..........2
    4..........3
    5..........4
    6..........5
    7..........6
    8..........7
    9..........8
    *..........9
    

    Output

    True
    
  3. Input

    >.@............*
    >..@...........*
    >...@..........*
    >....@.........*
    >.....@........*
    >...*..@........
    >.......@......*
    

    Output

    False
    
  4. Input

    ../\.
    >./**
    

    Output

    False
    
  5. Input

    /.......*.......\/3.....
    @..............//\.\....
    *.............2\.1\/\...
    \..............///.....<
    .........*...//\\/.....\
    >.............\.1.///.4.
    4.......*/...\2\/3/\/..^
    

    Output

    True
    
  6. Input

    vvvvvvvvvvvvvvvvv
    \\\\\\\\\\\\\\\\\
    /////////////////
    \\\\\\\\\\\\\\\\\
    /////////////////
    \\\\\\\\\\\\\\\\\
    /////////////////
    *****************
    

    Output (note the target at the far right)

    False