2
\$\begingroup\$

This question already has an answer here:

Mayube recently posted Garble that string. However, humans aren't too good at checking whether a string is actually garbled or not. (Actually, that's an understatement, we are really bad at it.) So, let's save some time making test cases, and see if a string is actually garbled.

Input

Two strings, containing only lowercase, or only uppercase letters, your choice.

Output

Truthy/falsey based on if the second string is a garbled version of the first one (or vice-versa, I believe).

A string is garbled if (same as original challenge):

  • No character is in it's original position
  • No character is adjacent to a character that it was originally adjacent to

Note that duplicate characters keep rules from all other copies of them.

Adjacency also wraps from one end to the other, so for abcd, a is considered adjacent to d.

Test Cases

I really hope these are right. Mostly copied from the other challenge.

mayube, euabmy truthy
aabcdeffghij, dbfhjfigaeca truthy
abcde, badce falsey
abcde, dbeca falsey
aaa, aaa falsey
stephen, nhseept falsey
stephens, nhseespt truthy
helowi, ioewlh falsey
\$\endgroup\$

marked as duplicate by Rɪᴋᴇʀ, Sriotchilism O'Zaic, mbomb007, ovs, user62131 Jun 8 '17 at 20:45

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • \$\begingroup\$ don't forget to mention that adjacency wraps, meaning the 2 ss in stephens are adjacent \$\endgroup\$ – Skidsdev Jun 8 '17 at 16:08
  • \$\begingroup\$ @Mayube thanks :) \$\endgroup\$ – Stephen Jun 8 '17 at 16:09
  • 4
    \$\begingroup\$ This is a borderline duplicate of the other challenge—the bulk of the code for that challenge implements this, so answers can be trivially modified and posted here by removing the "shuffle repeatedly" or "generate permutations and filter" part. \$\endgroup\$ – Doorknob Jun 8 '17 at 16:25
  • \$\begingroup\$ @Doorknob that's very possible - the community can decide. Personally, I'd prefer that at least one answer came in so that it's there to validate the test cases for the other challenge, but it's not up to me. \$\endgroup\$ – Stephen Jun 8 '17 at 16:27