In this challenge, you are passed two words: Your job is to determine if they are adjacent.
Two letters are adjacent if:
- They are the same letter, or
- They are lexicographically adjacent.
For example, J is adjacent to I,J, and K only. Z is not adjacent to A
Two words are adjacent if:
- They are the same length, and
- Each letter is adjacent to a unique letter in the other word.
For example, CAT is adjacent to SAD, as C>D, A>A, T>S.
FREE is not adjacent to GRRD (each E needs a letter to pair with).
Input/Output
You are passed two strings, and you need to return a truthy value if they are adjacent, otherwise a falsy value. You should return within a minute for all test cases below.
You can assume that the strings will only contain uppercase, alphabetic letters.
The two strings can be passed as a list, or concatenated, with or without quotes.
Test Cases
Truthy:
A A
A B
C B
DD CE
DE FC
ABCD BCDE
AACC DBBB
DJENSKE FDJCLMT
DEFGHIJKL HJLEHMCHE
IKLIJJLIJKKL LJLJLJLJLJHI
ACEGIKMOQSUWY BLNPRDFTVHXJZ
QQSQQRRQSTTUQQRRRS PQTTPPTTQTPQPPQRTP
ELKNSDUUUELSKJFESD DKJELKNSUELSDUFEUS
Falsy:
A C
A Z
B J
JK J
CC BA
CE D
DJENSKE GDJCLMT
DEFGHIJKL HJLHMCHE
IJKLIJKLKIJL LIJLLHJLJLLL
AWSUKMEGICOQY RSHXBLJLNQDFZ
QQSQQRRQSTTUQQQRRS PQTTPPTTQTPQPPQRTT
ELKNSDUVWELSKJFESD DKJELKNSUELSDUFEUS
This is code-golf, so the shortest valid answer wins!
"A A"
? \$\endgroup\${'string1' 'string2'}
be acceptable as well? \$\endgroup\$