Walk Across a Keyboard
up vote
7
down vote
favorite
Given a word (or any sequence of letters) as input, you must interpolate between each letter such that each adjacent pair of letters in the result is also adjacent on a QWERTY keyboard, as if you typed the input by walking on a giant keyboard. For example, 'yes' might become 'ytres', 'cat' might become 'cxzawert'.
Rules:
This is the keyboard format you should use:
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
Any pair of keys which is touching in this layout is considered adjacent. For instance, 's' and 'e' are ajacent, but 's' and 'r' are not.
- The input "word" will consist of any sequence of letters. It will have only letters, so you don't have do deal with special characters.
- The input can be in any convenient form: stdin, a string, a list, etc. Letter case does not matter; you can take whatever is more convenient.
- The output can be in any convenient form: stdout, a string, a list, etc. Letter case does not matter, and it does not need to be consistent.
- Any path across the keyboard is valid, except that you cannot cross the previous letter again before getting to the next letter. For example, 'hi' could become 'hji' or 'hjnbgyui', but not 'hbhui'.
- A letter is not ajacent with itself, so 'poll' cannot become 'poll'. Instead it would need to become something like 'polkl'.
- No output letters are allowed before or after the word. For example, 'was' cannot become 'trewas' or 'wasdfg'.
This is code golf, the shortest answer in bytes wins.
code-golf keyboard
add a comment |
up vote
7
down vote
favorite
Given a word (or any sequence of letters) as input, you must interpolate between each letter such that each adjacent pair of letters in the result is also adjacent on a QWERTY keyboard, as if you typed the input by walking on a giant keyboard. For example, 'yes' might become 'ytres', 'cat' might become 'cxzawert'.
Rules:
This is the keyboard format you should use:
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
Any pair of keys which is touching in this layout is considered adjacent. For instance, 's' and 'e' are ajacent, but 's' and 'r' are not.
- The input "word" will consist of any sequence of letters. It will have only letters, so you don't have do deal with special characters.
- The input can be in any convenient form: stdin, a string, a list, etc. Letter case does not matter; you can take whatever is more convenient.
- The output can be in any convenient form: stdout, a string, a list, etc. Letter case does not matter, and it does not need to be consistent.
- Any path across the keyboard is valid, except that you cannot cross the previous letter again before getting to the next letter. For example, 'hi' could become 'hji' or 'hjnbgyui', but not 'hbhui'.
- A letter is not ajacent with itself, so 'poll' cannot become 'poll'. Instead it would need to become something like 'polkl'.
- No output letters are allowed before or after the word. For example, 'was' cannot become 'trewas' or 'wasdfg'.
This is code golf, the shortest answer in bytes wins.
code-golf keyboard
So we're outputting any valid 'walk' per input? This seems like it'd be better as given two inputs, determine if it's a valid walk.
– Veskah
6 hours ago
It seems likedewqwerty
is a valid path fordy
. Could you confirm that?
– Arnauld
5 hours ago
@Arnauld yes, it is.
– Vaelus
5 hours ago
@Veskah That's right; output any valid walk for an input. This is to allow for optimizations which might not be possible if, for instance, it had to be a shortest walk.
– Vaelus
5 hours ago
add a comment |
up vote
7
down vote
favorite
up vote
7
down vote
favorite
Given a word (or any sequence of letters) as input, you must interpolate between each letter such that each adjacent pair of letters in the result is also adjacent on a QWERTY keyboard, as if you typed the input by walking on a giant keyboard. For example, 'yes' might become 'ytres', 'cat' might become 'cxzawert'.
Rules:
This is the keyboard format you should use:
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
Any pair of keys which is touching in this layout is considered adjacent. For instance, 's' and 'e' are ajacent, but 's' and 'r' are not.
- The input "word" will consist of any sequence of letters. It will have only letters, so you don't have do deal with special characters.
- The input can be in any convenient form: stdin, a string, a list, etc. Letter case does not matter; you can take whatever is more convenient.
- The output can be in any convenient form: stdout, a string, a list, etc. Letter case does not matter, and it does not need to be consistent.
- Any path across the keyboard is valid, except that you cannot cross the previous letter again before getting to the next letter. For example, 'hi' could become 'hji' or 'hjnbgyui', but not 'hbhui'.
- A letter is not ajacent with itself, so 'poll' cannot become 'poll'. Instead it would need to become something like 'polkl'.
- No output letters are allowed before or after the word. For example, 'was' cannot become 'trewas' or 'wasdfg'.
This is code golf, the shortest answer in bytes wins.
code-golf keyboard
Given a word (or any sequence of letters) as input, you must interpolate between each letter such that each adjacent pair of letters in the result is also adjacent on a QWERTY keyboard, as if you typed the input by walking on a giant keyboard. For example, 'yes' might become 'ytres', 'cat' might become 'cxzawert'.
Rules:
This is the keyboard format you should use:
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
Any pair of keys which is touching in this layout is considered adjacent. For instance, 's' and 'e' are ajacent, but 's' and 'r' are not.
- The input "word" will consist of any sequence of letters. It will have only letters, so you don't have do deal with special characters.
- The input can be in any convenient form: stdin, a string, a list, etc. Letter case does not matter; you can take whatever is more convenient.
- The output can be in any convenient form: stdout, a string, a list, etc. Letter case does not matter, and it does not need to be consistent.
- Any path across the keyboard is valid, except that you cannot cross the previous letter again before getting to the next letter. For example, 'hi' could become 'hji' or 'hjnbgyui', but not 'hbhui'.
- A letter is not ajacent with itself, so 'poll' cannot become 'poll'. Instead it would need to become something like 'polkl'.
- No output letters are allowed before or after the word. For example, 'was' cannot become 'trewas' or 'wasdfg'.
This is code golf, the shortest answer in bytes wins.
code-golf keyboard
code-golf keyboard
asked 6 hours ago
Vaelus
225110
225110
So we're outputting any valid 'walk' per input? This seems like it'd be better as given two inputs, determine if it's a valid walk.
– Veskah
6 hours ago
It seems likedewqwerty
is a valid path fordy
. Could you confirm that?
– Arnauld
5 hours ago
@Arnauld yes, it is.
– Vaelus
5 hours ago
@Veskah That's right; output any valid walk for an input. This is to allow for optimizations which might not be possible if, for instance, it had to be a shortest walk.
– Vaelus
5 hours ago
add a comment |
So we're outputting any valid 'walk' per input? This seems like it'd be better as given two inputs, determine if it's a valid walk.
– Veskah
6 hours ago
It seems likedewqwerty
is a valid path fordy
. Could you confirm that?
– Arnauld
5 hours ago
@Arnauld yes, it is.
– Vaelus
5 hours ago
@Veskah That's right; output any valid walk for an input. This is to allow for optimizations which might not be possible if, for instance, it had to be a shortest walk.
– Vaelus
5 hours ago
So we're outputting any valid 'walk' per input? This seems like it'd be better as given two inputs, determine if it's a valid walk.
– Veskah
6 hours ago
So we're outputting any valid 'walk' per input? This seems like it'd be better as given two inputs, determine if it's a valid walk.
– Veskah
6 hours ago
It seems like
dewqwerty
is a valid path for dy
. Could you confirm that?– Arnauld
5 hours ago
It seems like
dewqwerty
is a valid path for dy
. Could you confirm that?– Arnauld
5 hours ago
@Arnauld yes, it is.
– Vaelus
5 hours ago
@Arnauld yes, it is.
– Vaelus
5 hours ago
@Veskah That's right; output any valid walk for an input. This is to allow for optimizations which might not be possible if, for instance, it had to be a shortest walk.
– Vaelus
5 hours ago
@Veskah That's right; output any valid walk for an input. This is to allow for optimizations which might not be possible if, for instance, it had to be a shortest walk.
– Vaelus
5 hours ago
add a comment |
3 Answers
3
active
oldest
votes
up vote
2
down vote
Python 2, 83 bytes
lambda s:re.findall('.*?'.join(s),'qwertyuioplkmnjhbvgfcxdsza'*len(s))[0]
import re
Try it online!
Walks the entire keyboard until the word is written.
add a comment |
up vote
0
down vote
JavaScript (ES6), 70 bytes
Same strategy as TFeld.
s=>'qazsxdcfvgbhnjmklpoiuytrew'.repeat(s.length).match(s.join`.*?`)[0]
Try it online!
add a comment |
up vote
0
down vote
Japt -g
, 24 bytes
;D·ÎÔ+D·Årí)pUl)fU¬q".*?
Try it online!
Takes input in all caps. Very similar to the other answers otherwise.
Explanation:
; :Set D to the keyboard layout
D·Î :Get the first row of keys
Ô :Reversed
+ :Concat
D·Å :The other two rows
rí) :Interleaved
p :Repeat that string
Ul) : A number of times equal to the length of the input
f :Get the substrings that match
U : The input
¬ : split into characters
q".*? : and joined back with ".*?"
:Implicitly output just once of the matches
add a comment |
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
Python 2, 83 bytes
lambda s:re.findall('.*?'.join(s),'qwertyuioplkmnjhbvgfcxdsza'*len(s))[0]
import re
Try it online!
Walks the entire keyboard until the word is written.
add a comment |
up vote
2
down vote
Python 2, 83 bytes
lambda s:re.findall('.*?'.join(s),'qwertyuioplkmnjhbvgfcxdsza'*len(s))[0]
import re
Try it online!
Walks the entire keyboard until the word is written.
add a comment |
up vote
2
down vote
up vote
2
down vote
Python 2, 83 bytes
lambda s:re.findall('.*?'.join(s),'qwertyuioplkmnjhbvgfcxdsza'*len(s))[0]
import re
Try it online!
Walks the entire keyboard until the word is written.
Python 2, 83 bytes
lambda s:re.findall('.*?'.join(s),'qwertyuioplkmnjhbvgfcxdsza'*len(s))[0]
import re
Try it online!
Walks the entire keyboard until the word is written.
answered 5 hours ago
TFeld
13.8k21239
13.8k21239
add a comment |
add a comment |
up vote
0
down vote
JavaScript (ES6), 70 bytes
Same strategy as TFeld.
s=>'qazsxdcfvgbhnjmklpoiuytrew'.repeat(s.length).match(s.join`.*?`)[0]
Try it online!
add a comment |
up vote
0
down vote
JavaScript (ES6), 70 bytes
Same strategy as TFeld.
s=>'qazsxdcfvgbhnjmklpoiuytrew'.repeat(s.length).match(s.join`.*?`)[0]
Try it online!
add a comment |
up vote
0
down vote
up vote
0
down vote
JavaScript (ES6), 70 bytes
Same strategy as TFeld.
s=>'qazsxdcfvgbhnjmklpoiuytrew'.repeat(s.length).match(s.join`.*?`)[0]
Try it online!
JavaScript (ES6), 70 bytes
Same strategy as TFeld.
s=>'qazsxdcfvgbhnjmklpoiuytrew'.repeat(s.length).match(s.join`.*?`)[0]
Try it online!
answered 3 hours ago
Arnauld
70.6k688298
70.6k688298
add a comment |
add a comment |
up vote
0
down vote
Japt -g
, 24 bytes
;D·ÎÔ+D·Årí)pUl)fU¬q".*?
Try it online!
Takes input in all caps. Very similar to the other answers otherwise.
Explanation:
; :Set D to the keyboard layout
D·Î :Get the first row of keys
Ô :Reversed
+ :Concat
D·Å :The other two rows
rí) :Interleaved
p :Repeat that string
Ul) : A number of times equal to the length of the input
f :Get the substrings that match
U : The input
¬ : split into characters
q".*? : and joined back with ".*?"
:Implicitly output just once of the matches
add a comment |
up vote
0
down vote
Japt -g
, 24 bytes
;D·ÎÔ+D·Årí)pUl)fU¬q".*?
Try it online!
Takes input in all caps. Very similar to the other answers otherwise.
Explanation:
; :Set D to the keyboard layout
D·Î :Get the first row of keys
Ô :Reversed
+ :Concat
D·Å :The other two rows
rí) :Interleaved
p :Repeat that string
Ul) : A number of times equal to the length of the input
f :Get the substrings that match
U : The input
¬ : split into characters
q".*? : and joined back with ".*?"
:Implicitly output just once of the matches
add a comment |
up vote
0
down vote
up vote
0
down vote
Japt -g
, 24 bytes
;D·ÎÔ+D·Årí)pUl)fU¬q".*?
Try it online!
Takes input in all caps. Very similar to the other answers otherwise.
Explanation:
; :Set D to the keyboard layout
D·Î :Get the first row of keys
Ô :Reversed
+ :Concat
D·Å :The other two rows
rí) :Interleaved
p :Repeat that string
Ul) : A number of times equal to the length of the input
f :Get the substrings that match
U : The input
¬ : split into characters
q".*? : and joined back with ".*?"
:Implicitly output just once of the matches
Japt -g
, 24 bytes
;D·ÎÔ+D·Årí)pUl)fU¬q".*?
Try it online!
Takes input in all caps. Very similar to the other answers otherwise.
Explanation:
; :Set D to the keyboard layout
D·Î :Get the first row of keys
Ô :Reversed
+ :Concat
D·Å :The other two rows
rí) :Interleaved
p :Repeat that string
Ul) : A number of times equal to the length of the input
f :Get the substrings that match
U : The input
¬ : split into characters
q".*? : and joined back with ".*?"
:Implicitly output just once of the matches
answered 1 hour ago
Kamil Drakari
2,686416
2,686416
add a comment |
add a comment |
If this is an answer to a challenge…
…Be sure to follow the challenge specification. However, please refrain from exploiting obvious loopholes. Answers abusing any of the standard loopholes are considered invalid. If you think a specification is unclear or underspecified, comment on the question instead.
…Try to optimize your score. For instance, answers to code-golf challenges should attempt to be as short as possible. You can always include a readable version of the code in addition to the competitive one.
Explanations of your answer make it more interesting to read and are very much encouraged.…Include a short header which indicates the language(s) of your code and its score, as defined by the challenge.
More generally…
…Please make sure to answer the question and provide sufficient detail.
…Avoid asking for help, clarification or responding to other answers (use comments instead).
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f177096%2fwalk-across-a-keyboard%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
So we're outputting any valid 'walk' per input? This seems like it'd be better as given two inputs, determine if it's a valid walk.
– Veskah
6 hours ago
It seems like
dewqwerty
is a valid path fordy
. Could you confirm that?– Arnauld
5 hours ago
@Arnauld yes, it is.
– Vaelus
5 hours ago
@Veskah That's right; output any valid walk for an input. This is to allow for optimizations which might not be possible if, for instance, it had to be a shortest walk.
– Vaelus
5 hours ago