Given a set of two strings guaranteed to be the same length, print their criss cross.

The criss cross of two strings is obtained as follows.

  1. Yield the second character of the second string, then the first character of the first string.
  2. Yield the first character of the second string, then the second character of the first string.
  3. Discard the first character of each string.
  4. If the strings have more than one character each, go back to step 1.

For example, if the two strings are


the criss cross is


as illustrated in the following diagram.


Each color represents a different iteration of criss-crossing. The numbers show the corresponding character's indices in the output.

  • \$\begingroup\$ You shouldn't accept an answer until at the very least around a week has passed, it might be beaten at any time. \$\endgroup\$ – Pavel Jul 2 '17 at 6:26
  • \$\begingroup\$ @Phoenix okay I'll keep that in mind next time (this was my first question on this stackexchange) \$\endgroup\$ – K Split X Jul 2 '17 at 19:52

Jelly, 10 8 bytes


Try it online!

How it works

żṚj@¥2\U  Main link. Arguments: s, t (strings)

          Arguments:    "Truck", Tower"
ż         Ziphwith; create all pairs of corresponding characters.
          Return value: ["TT", "ro", "uw", "ce", "kr"].
     2\   Reduce each pair of adjacent strings by the quicklink to the left.
    ¥       Combine the two links to the left into a dyadic chain.
 Ṛ            Reverse the left string.
  j@          Join the second string, using the previous result as separator.
          Map:          "TT", "ro" -> join("ro", "TT") -> "rTTo"
                        "ro", "uw" -> join("uw", "or") -> "uorw"
          Return value: ["rTTo", "uorw", "cwue", "kecr"]
       U  Upend; reverse each string.
          Return value: ["oTTr", "wrou", "euwc", "rcek"]
          (implicit) Flatten and print.
  • \$\begingroup\$ Wow thats pretty amazing \$\endgroup\$ – K Split X Jun 30 '17 at 22:53
  • \$\begingroup\$ Explanation, please? \$\endgroup\$ – Shaggy Jun 30 '17 at 23:24
  • \$\begingroup\$ @Shaggy I've edited my answer. \$\endgroup\$ – Dennis Jun 30 '17 at 23:38

JavaScript (ES6), 51 bytes



console.log(f("Truck", "Tower"))


Python 3, 56 bytes

f=lambda s,t:s[1:]and t[1]+s[0]+t[0]+s[1]+f(s[1:],t[1:])

Try it online!


Haskell, 44 38 bytes

Crossed out 44 is still 44


Slightly less golfed / maybe a little more readable:

[_]      # [_]      = ""
(a:b:bs) # (x:y:ys) = y:a:x:b:((b:bs) # (y:ys))
  • 1
    \$\begingroup\$ Fun Fact: On my browser at least, crossed out 44 is no longer 44 in the header :o \$\endgroup\$ – HyperNeutrino Jun 30 '17 at 23:42

PHP>=7.1, 64 bytes


PHP Sandbox Online


C++14, 115 112 bytes

As unnamed lambda, parameters should be like std::string:

#define P putchar(
[](auto A,auto B){for(int i=0;++i<A.size()&&i<B.size();P B[i]),P A[i-1]),P B[i-1]),P A[i]));}

Ungolfed and usage:


using namespace std;

#define P putchar(
auto f=
[](auto A,auto B){
 for(int i=0;
     ++i<A.size() && i<B.size();
     P B[i]),
     P A[i-1]),
     P B[i-1]),
     P A[i]));

int main(){
 string A="Truck",B="Tower";

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.