Well, turns out Doorknob's username on GitHub, Reddit, and other sites is KeyboardFire. That gives me an idea...
You work at KeyboardFire Inc., a company that makes special keyboards. And, by "special", I mean that, whenever you press a key, something in your house lights on fire! With the new KeyboardFire Doorknob series, the objects that light on fire are doorknobs.
However, because of stupid government regulations, your users need to know which doorknobs in their house wil light on fire.
Consider this ASCII art of a portion of a QWERTY keyboard:
1|2|3|4|5|6|7|8|9|0 q|w|e|r|t|y|u|i|o|p a|s|d|f|g|h|j|k|l z|x|c|v|b|n|m
|'s represent the boundaries between keys.)
We can treat this exact ASCII drawing as a "graph" of sorts, where each character in the range
has an x (horizontal) and y (vertical) index, where
1. For instance,
d has the coordinates
(2,6) (pipes and spaces are included in the coordinate calculation).
Now let's think about each user's house. Every house can be drawn top-down view as
a 20x4 ASCII art (in this world where it's legal to sell destructive keyboards,
every house is the same size). We can use
D's to mark the positions of each
doorknob in the house. Here's an example:
D D D D D D D
We'll call this the "house map". (Yes, that's a lot of doorknobs!)
Pressing any key will light the nearest doorknob on fire. For instance, if we take the previous coordinates of the letter
d, the nearest doorknob (by Manhattan distance) is at
(1,4). This is the doorknob that will light on fire when the
d is hit. If we were to mark the flaming doorknob with an
F, the result
D D D D F D D
Your program will take two inputs:
- A string that matches the pattern
- A house map. This can be a string, a list of strings, or something equivalent.
You need to go through each letter of the string and light the respective
doorknob on fire (change its letter to an
F). If the nearest doorknob is already
on fire, leave it as-is. If there is more than 1 doorknob that could be lit on fire
using the this method, you can light whichever one you want.
After the whole string is processed in this manner, you need to print the resulting house map.
Code-golf, so shortest program wins. Standard loopholes banned as usual.
D D D D D D D
F F F D F D F
F D F D F D F
F F D D F F F
F D D D F F F
EDIT: Uh...is there a reason I have one answer, even with a +50 bounty? If you find the directions complicated/vague, I'd be glad if you posted in the comments or something...or of I'm doing anything wrong...
EDIT 2: Bounty expires in under a day! Post something else! Please! PLEASE!!!! :(
d's coords (2, 6) and not (2, 2)? 2) Why does the example have so many possible answers? 3) When you explain how things will light on fire, why are you even talking about
d? Why not just straight up say that pressing
awill light some house on fire? Does
ddo it, too? \$\endgroup\$