9
\$\begingroup\$

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

Truck
Tower

the criss cross is

oTTrwroueuwcrcek

as illustrated in the following diagram.

diagram

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

\$\endgroup\$
  • \$\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
6
\$\begingroup\$

Jelly, 10 8 bytes

żṚj@¥2\U

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"
                        etc.
          Return value: ["rTTo", "uorw", "cwue", "kecr"]
       U  Upend; reverse each string.
          Return value: ["oTTr", "wrou", "euwc", "rcek"]
          (implicit) Flatten and print.
\$\endgroup\$
  • \$\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
6
\$\begingroup\$

JavaScript (ES6), 51 bytes

f=([G,...O],[L,...F])=>O[0]?F[0]+G+L+O[0]+f(O,F):''

f=([G,...O],[L,...F])=>O[0]?F[0]+G+L+O[0]+f(O,F):''

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

\$\endgroup\$
3
\$\begingroup\$

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!

\$\endgroup\$
3
\$\begingroup\$

Haskell, 44 38 bytes

Crossed out 44 is still 44

[_]#_=""
(a:b)#(x:y)=y!!0:a:x:b!!0:b#y

Slightly less golfed / maybe a little more readable:

[_]      # [_]      = ""
(a:b:bs) # (x:y:ys) = y:a:x:b:((b:bs) # (y:ys))
\$\endgroup\$
  • 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
2
\$\begingroup\$

PHP>=7.1, 64 bytes

for([,$a,$b]=$argv;$c=$b[++$i];)echo$c,$a[$i-1],$b[$i-1],$a[$i];

PHP Sandbox Online

\$\endgroup\$
0
\$\begingroup\$

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:

#include<iostream>
#include<string>

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";
 f(A,B);
}
\$\endgroup\$

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.