# Simulate my keyboard wave light!

(The word frame in the following text does not mean an actual frame, it is used as a placeholder for an undefined time unit)

# The task

Imagine you have a keyboard layout with only letters like so:

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

Whenever you press a key, for example f, the keyboard lights up the keys around it each frame like this (unordered, each line is a separate frame):

F
RTGVCD
YHBXSE
UJNWAZ
IKMQ
OL
P

As you can see, each frame lights up the keys around the ones that were lit previously, but not the ones that have already been lit up before.

After you have determined which keys need to be pressed each frame, you need to visualise them. For each frame, you print out the default keyboard layout (with all of the whitespace), but with the lit up keys uppercased. In our example:

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

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

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

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

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

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

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

# Rules

1. Input will be a single letter, you can choose whether it will be capitalised or not.

2. Output can be either:

a. An array of multiline strings representing each second of the visualised keyboard

b. A single multiline string with each frame of the visualised keyboard separated by at least one newline

3. You can output a trailing newline or/and the final keyboard visualisation when no keys are lit anymore

# Test cases

Input: F
Output:
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

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

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

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

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

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

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

Input: Q
Output:

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

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

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

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

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

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

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

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

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

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

Input: Z
Output:
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

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

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

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

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

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

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

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

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

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
• I like that! Maybe you could use frame or step instead of second? – AZTECCO Oct 28 '20 at 7:38
• @AZTECCO sure, will change – Dion Oct 28 '20 at 7:39
• Do we have to include the spaces you have in your example outputs or not? – Jonathan Allan Oct 28 '20 at 18:06
• @JonathanAllan yes, it is part of the visualisation step. will clarify – Dion Oct 28 '20 at 18:29
• "You can output [...] the final keyboard visualisation when no keys are lit anymore" Does this have to be consistent, or can we output the final visualisation only for some cases? – ovs Oct 29 '20 at 9:18

e=zip[0..]
x!y=abs$x-y k=e["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"] f c=filter(any(<"a").words)[unlines[[[z..]!!sum[32|z>'@',max(2*y!i)(y!i+x!j)/=d*2]|(x,z)<-e m]|(y,m)<-k]|(i,l)<-k,(j,h)<-e l,c==h,d<-[0..9]] Try it online! f takes an uppercase char argument and returns a list of multiline strings. It loops over the keyboard layout looking for (i,j), the position of the given character. When it finds it, for each d<-[0..9] it generates a string (unlines[…]) of the keyboard with all letters not d hex-steps away lowercased. It never takes longer than 10 steps for the wave to leave the keyboard, so this is OK. Finally, strings that don't contain any uppercase letters are filtered away from the result. I calculate the hex distance between two points on the keyboard as: $$\ \max\left(2|y_1-y_2|, |x_1-x_2|+|y_1-y_2|\right)\$$. Here are some distances around a point under this metric: 6666666 6 6 6 6 654444456 6 4 4 4 6 65432223456 6 4 2 2 4 6 6543210123456 --> on staggered grid: 6 4 2 0 2 4 6 65432223456 6 4 2 2 4 6 654444456 6 4 4 4 6 6666666 6 6 6 6 # Charcoal, 82 bytes ≔⪪”&±=Ｋ≕⦃Vj@η⟲.w\o:7➙1”¶υ≔⊟Φυ№ιθηΦＥχＥυ⁺× μ⪫⭆λ⎇⁼ι⌈↔⊟Ｅ⟦⟦⁻μ⌕υη⁻ξ⌕ηθ⟧⟧⊞ＯπΣπ↥νν ⊙ι⊙λ№αν Try it online! Link is to verbose version of code. Takes input in lower case. Explanation: ≔⪪”&±=Ｋ≕⦃Vj@η⟲.w\o:7➙1”¶υ Get the list qwertyuiop, asdfghjkl, zxcvbnm by splitting a compressed string. ≔⊟Φυ№ιθη Find the element of the above list that contains the input. Ｅχ Create a list of lists corresponding to each step away from the input on the staggered grid from 0 to 9. Ｅυ⁺× μ⪫⭆λ⎇⁼ι⌈↔⊟Ｅ⟦⟦⁻μ⌕υη⁻ξ⌕ηθ⟧⟧⊞ＯπΣπ↥νν Uppercase the letters that are the desired distance from the input on the staggered grid, then stagger the result by prefixing each line with an increasing number of spaces and double-spacing the letters. Φ...⊙ι⊙λ№αν Only print those lists that contain an uppercase letter. The formula I'm using for distance is the maximum of $$\|x_2-x_1|\$$, $$\|y_2-y_1|\$$ and $$\|x_2-x_1+y_2-y_1|\$$ their sum, where $$\y\$$ is the (0-indexed) row counting down and $$\x\$$ is the (skewed) column: 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 0 1 2 3 4 5 6 • @KevinCruijssen Actually, only keys on the middle row work. I'll have to work on the fix. – Neil Oct 28 '20 at 15:13 • @KevinCruijssen OK I think this is it, and it only cost me a byte after some severe golfing to add $x_2-x_1$ to $y_2-y_1$ without writing them out twice. – Neil Oct 28 '20 at 16:24 # 05AB1E, 5957 50 bytes Thanks to Kevin Cruijssen for -3 bytes! Input is in lowercase, the program prints the keyboards separated by empty lines. Outputs the final dark keyboard for some keys. Uses the distance metric from Lynn's answer. žVðæ.ιSðý©Ik19‰¸Þ2Ý18Ýâαε¬sO;‚à}>ZFD®sÅÏu}19ô»,¶?< Try it online! Commented: # keyboard creation žV # push ["qwertyuiop", "asdfghjkl", "zxcvbnm"] ð # push a space æ # push the powerset ["", " "] .ι # interleave both lists S # split into a list of characters δý # join with spaces © # store this value in the register I # push the input k # the index of the input in the keyboard string 19‰ # divmod by 19 to get [y, x]-coordinates ¸Þ # cycle this value forever 2Ý # push [0..2] 18Ý # push [0..18] â # cartesian product to get a list of all coordinates α # take the element-wise difference [dy, dx] for each coord # apply distance metric ε } # map over the absolute differences: ¬ # get the first element dy s # swap back to [dy, dx] O # sum it ; # halve it ‚ # pair into a list [dy, (dy+dx)/2] à # take the maximum > # increment every value # so that the input position has value 1 (only truthy value) # generate the outputs Z # take the maximum of the distances F # iterate that many times: D # duplicate the distance list ® # push the keyboard string s # swap to the distance list ÅÏ } # apply where truthy (==1) u # uppercase 19ô # split into groups of 19 » # join by newlines , # print ¶? # print a newline <# decrement distance list • Also, » joins all inner lists by spaces and then each string by newlines, which might make the ðý possibly obsolete. It does require a major change to the current formulas though.. Just some food for thought. – Kevin Cruijssen Oct 29 '20 at 9:46 • Another -2 by changing žSžTðžUJS to žVðæ.ιS. – Kevin Cruijssen Oct 29 '20 at 9:51 • @KevinCruijssen thanks again! Somehow I missed žV comletely. I'm not sure about removing the spaces, they make everything line up nicely right now. Especially the second row would be problematic without them. – ovs Oct 29 '20 at 10:06 • Yeah, I noticed that as well when I was trying some things. It would save some bytes on the ðý and changing the 19s to Ts, but it indeed uses a space from the join by spaces you have now in the second row, which would give too much issues to fix to benefit a golf I'd imagine. Ah well. And there are indeed multiple qwerty builtins: žSžTžU you've used in your earlier version; žV you use now; and žW for a single joined string. – Kevin Cruijssen Oct 29 '20 at 10:29 # Jelly, 64 bytes “¤Äı’b3’s2 +Ɱ¢ẎfØqŒṪ¤Q ḢØqœiWÇƬḟ"ṖẎ$Ƥ$LƇœịØqżŒu$µyⱮØqK€2Żẋ@⁶¤;")

A monadic Link accepting a list of 1 character which yields a list of keyboards, each keyboard being a list of lists of characters (including the spacing given in the examples).

Try it online! (Footer joins the resulting keyboards with newline characters and joins the result with pairs of newline characters to display like the examples.)