7
The Challenge
The game Light Up! is a simple puzzle game where the objective is to light up every cell in an n-by-n array with light bulbs. However, there are blocks in the way that will prevent light from traveling, and no lightbulb can be places such that another lightbulb shines light on it. Each light bulb has light coming from it in only the horizontal and vertical directions.
You must make a program that takes in an array of 5 numbers. Your program must convert each numbers into a 5-bit binary number, which will define at what places in the array there are blocks. If there is a 1, there is a block at the spot, but if there is a 0, there is not a block. Each number converted to binary defines a row, like:
[5,6,5,6,5] -> [00101, 00110, 00101, 00110, 00101] ->
. . B . B
. . B B .
. . B . B
. . B B .
. . B . B
Where B = blocks that block light
Your program must take this array and find the solutions (places where you need to put light) and give it back as an array of 5 numbers.
Example:
Input: [1,5,9,13,17]
Which translates to [00001, 00101, 01001, 01101, 10001]
Making the array:
. . . . B
. . B . B
. B . . B
. B B . B
B . . . B
A solution for this array is
L ~ ~ ~ B
~ L B ~ B
~ B ~ L B
~ B B ~ B
B L ~ ~ B
~ = Light L = Lightbulb
Which gives the binary array of lights [10000, 01000, 00010, 00000, 01000]
And translates back to [16, 8, 2, 0, 8]
Output: [16, 8, 2, 0, 8]
Rules
- Two lightbulbs can not be in the same row or column if there is no block between them.
- A lightbulb's light can only travel horizontally and vertically, and will stop if there is a block in the way
- Your program must take in an array
[a,b,c,d,e]
and output in the same form - If there are no way the array can be solved, your program must not give output or state "No Output."
- This is a [code-golf] challenge, lowest amount in bytes wins!
I think the example solution is wrong, you have two L in the column two. – Roman Mik – 2015-10-19T20:53:21.837
@RomanMik Thank you for telling me that! I should have specified it's ok if they're in the same column as long as a block is between them. – Meow Mix – 2015-10-19T20:54:42.187
ok, should the solution with the fewest light bulbs used be the best solution too ? – Roman Mik – 2015-10-19T21:04:59.990
I presume that a light can't be placed on top of a block? – Peter Taylor – 2015-10-19T21:07:17.247
@RomanMik no, it does not have to be, as long as each solution follows the rules. – Meow Mix – 2015-10-19T21:08:53.227
@PeterTaylor no, a light can't be placed on a block. – Meow Mix – 2015-10-19T21:08:56.207