34
0
Your challenge is to write a program or function that, when given two strings of equal length, swaps every other character and outputs/returns the resulting strings in either order.
Examples
"Hello," "world!" --> "Hollo!" "werld,"
"code" "golf" --> "codf" "gole"
"happy" "angry" --> "hnpry" "aagpy"
"qwerty" "dvorak" --> "qvertk" "dworay"
"1, 2, 3" "a, b, c" --> "1, b, 3" "a, 2, c"
"3.141592653589" "2.718281828459" --> "3.111291623489" "2.748582858559"
"DJMcMayhem" "trichoplax" --> "DrMcMoylex" "tJichapham"
"Doorknob" "Downgoat" --> "Doonkoot" "Dowrgnab"
"Halloween" "Challenge" --> "Hhlloeegn" "Caallwnee"
Rules
- The strings will only contain ASCII chars (32-126).
- The strings will always be the same length, and will never be empty.
- You may accept input in any suitable format: separate parameters, items in an array, separated by one or more newlines, even concatenated. The only restriction is that one string must come fully before the other (e.g.
a1\nb2\nc3for"abc", "123"is invalid). - The output may be in either order (i.e. you can start swapping from the first or the second char), and in any valid format mentioned above. (2-item array, separated by newline(s), concatenated, etc.)
Scoring
This is code-golf, so the shortest code in bytes for each language wins.
11+1 for
DrMcMoylex. :D – James – 9 years ago3"Dowrgnab" anagrams to "Downgrab" ( ͡° ͜ʖ ͡°) – Mama Fun Roll – 9 years ago
You should point out explicitly that the "in either order" rule means swapping can begin from the first character or the second. – DLosc – 9 years ago
@DrMcMoylex Take the code, golf example. If we swap starting from second character, we get: codf, gole. Starting from first character: gole, codf. – DLosc – 9 years ago