# Character Cross

I was expecting to post something more complex as my first puzzle in PCG, but a particular, uh... homework question on Stack Overflow inspired me to post this. They want to:

print the following pattern for any given word that contains odd number of letters:

P           M
R       A
O   R
G
O   R
R       A
P           M


Notice that letters are a knight's move apart in the pattern you need to print. So, every other column is empty. -- (Thanks xnor for pointing this out.)

## Rules

1. Using C++ is prohibited. As I may link this question there.
2. You may use stdout, or any means of quickly outputting a string (e.g. alert() in JavaScript).
3. As always, shortest code wins.
• This is in the related posts on stack overflow: stackoverflow.com/q/5508110 – Level River St Oct 29 '14 at 11:26
• @flawr I think it means odd, as in not an even number. – NinjaBearMonkey Oct 29 '14 at 14:28
• God I am stupid, I thought it was kind of an obscure computer scientist abbreviation=) – flawr Oct 29 '14 at 14:34
• @jpjacobs: Bytes, unless the question explicitly says otherwise. – Dennis Oct 29 '14 at 17:20
• Whole program or just a function? (real smart of me to answer first and make this question later...) – Rodolfo Dias Oct 29 '14 at 20:23

# K (oK), 31 bytes

Solution:

c$a||a:(2*#x)$(-1-2*!#x)$,:'x:  Try it online! Explanation: Generate the diagonal, and or with the reverse of the diagonal c$a||a:(2*#x)$(-1-2*!#x)$,:'x: / the solution
x: / save input as x
,:'   / enlist (,:) each-both (')
$/ pad (negative is right-pad) ( ) / do this together #x / count (#) length of x ! / range (!) 0..this count 2* / double it -1- / subtract from -1$                 / pad
(    )                  / do this together
#x                   / count (#) length of x
2*                     / multiply by 2
a:                        / save as a
|                          / reverse (|) it
a|                           / or (|) with a
c$/ cast to characters  # K4, 26 bytes Solution: a||a:(2*#x)$(-1-2*!#x)$$x:  Explanation: Similar to my oK answer but a little shorter: a||a:(2*#x)(-1-2*!#x)$$x: / the solution
x: / save input as x
$/ string ($) breaks into char lists
$/ cast ($)
(        )     / do this together
#x      / count (#) length of x
!        / range (!) 0..this count
2*         / double it
-1-           / subtract from -1
$/ pad ( ) / do this together #x / count (#) length of x 2* / multiply by 2 a: / save as a | / reverse (|) it a| / or (|) with a  # Stax, 13 bytes â┤▼iS╙£≥»u5V╓  Run and debug it Unpacked, ungolfed, and commented, it looks like this. { begin block for mapping characters of input ]i^) left-pad each character to length (i+1) where i is the index m map using block r reverse the array; this produces the southwest-northeast diagonal m map using the rest of the program, implicitly output result i iteration index xi@ get the i'th character of the original input, where i is the iteration & assign element to array at index 0\ join with spaces  Run this one # Powershell, 78 bytes +8 bytes thanks @streetster param($s)$s|% t*y|%{$r=,' '*$s.length;$r[+$i++]=$_;$r[-$i]=$s[-$i];$r-join' '}  Explaned test script: $f = {

param($s) # declare a parameter$s stores a word
$s|% t*y|%{ # split$s into chars https://codegolf.stackexchange.com/a/168174/80745
$r=,' '*$s.length   # create an array of spaces with length equal length of the word
$r[$i++]=$_ # set first char$r[-$i]=$s[-$i] # set last char$r-join' '          # join the array to string
}

}

&$f PROGRAM '' &$f sword
''
&$f uhm '' &$f o
''
&$f codegolf # It works with word that contains even number of letters  # Powershell, 70 bytes (if a word can be represented by an array of chars) +8 bytes thanks @streetster ($s=$args)|%{$r=,' '*$s.count;$r[+$i++]=$_;$r[-$i]=$s[-$i];$r-join' '}  Test script: $f = {

($s=$args)|%{$r=,' '*$s.count;$r[+$i++]=$_;$r[-$i]=$s[-$i];$r-join' '}

}

&$f P R O G R A M '' &$f s w o r d
''
&$f u h m '' &$f o
''
&$f c o d e g o l f # It works with word that contains even number of letters  Output for both cases: P M R A O R G O R R A P M s d w r o w r s d u m h u m o c f o l d o e g e g d o o l c f  • Since you can take input as a char-array (Meta post), that can save some bytes. – AdmBorkBork Aug 20 '18 at 13:21 • I'm not sure that the word in the rule print the following pattern for any given word that contains odd number of letters means an array of chars in a Powershell :) But I've updated post – mazzy Aug 20 '18 at 15:52 • Aren't you crossing the wrong way? – streetster Aug 21 '18 at 7:16 • @streetster, you are best! I've updated the post. – mazzy Aug 21 '18 at 8:27 • Oof, +8 bytes - sorry! – streetster Aug 21 '18 at 14:36 # Charcoal, 9717 10 bytes ↘Ｓ⟲ＯＯＬθＵＥ¹  +10 bytes because I missed the requirement of space-columns. -7 bytes thanks to @ASCII-only. Challenges like this is why Charcoal was made. Explanation: Print the input-string in a down-right direction: Print(:DownRight, InputString()); ↘Ｓ  Rotate it 90 degree counterclockwise, and shift it up the length of the input-string amount of times with overlap: RotateOverlapOverlap(Length(q)); ⟲ＯＯＬθ  Put a space gap of size 1 between every column: Extend(1); ＵＥ¹  • It's not exactly diagonal. There should be an empty column between characters. – sampathsris Aug 17 '18 at 7:50 • @Krumia Should be fixed now. – Kevin Cruijssen Aug 17 '18 at 8:09 • @KevinCruijssen 10 – ASCII-only Nov 19 '18 at 23:43 • @ASCII-only Thanks! Didn't knew about Extend, but it's just what was necessary here. – Kevin Cruijssen Nov 20 '18 at 7:36 • XD > try it only – ASCII-only Dec 5 '18 at 11:47 # R, 88 bytes n=ncol(m<-diag(u<-utf8ToInt(scan(,""))-32));diag(m[,n:1])=u;write(intToUtf8(m+32,T),1,n)  Try it online! • Nice! Like me, you can save 2 bytes by using pmax (originally Giuseppe's suggestion). – Robert Hacken Nov 24 '18 at 23:10 • This won't work with length 1 input. – Giuseppe Nov 24 '18 at 23:28 # Canvas, 6 bytes ＼：↶ｎ ＊  Try it here! # Explanation ＼ Create a diagonal with the input ： Duplicate the diagonal ↶ Rotate left ｎ Simple overlap ＊ Insert spaces on every line  • There is already a 5-byte Canvas answer, but nice approach regardless! :) – Kevin Cruijssen Apr 9 '20 at 8:12 • I see, the built-in is ｎ... – user92069 Apr 9 '20 at 8:38 # PHP, 81 bytes for($k=strlen($s=$argn);$k;$t[2*$i]=$s[$i++],$t[2*--$k]=$s[$k],print"$t
")\$t=" ";


Run as pipe with -nR or try it online.

# Python 3, 176 bytes

w=input();l=len(w);d=l//2;n=' ';x=range(d)
for i in x:print(n*i*2+w[i],n*(l+2-i*4),w[-1*i-1])
print(n*(l-1)+w[d])
for i in x:print(n*(l-i*2-3)+w[-1*(d+i+2)],n*(i*4+1),w[d+i+1])


Try it online!

This is super stupid, any improvements that you notice are welcome

# C++:

#include <iostream>
#include <string>

int main()
{
char a[] = {'P','R','O','G','R','A','M'};
int length = sizeof(a)/sizeof(a[0]);
int l = length - 1, i, j;
for (i=0; i <= l; i++) {
for (j=0; j <= l;j++) {
if (j == i)
std::cout<<a[i];
else if (i == l-j)
std::cout<<a[j];
else
std::cout<<"s";
}
std::cout<<"\n";
}
}
`
• Welcome to PPCG! This is code-golf which means that the goal is to solve the problem in as few bytes as code as possible. As per our help centre every answer should make a reasonable stab at the given winning criterion (within the limits of their language), which would mean at least removing unnecessary whitespace and using single-character variable names. You can always include a readable/"ungolfed" version in addition to the competitive one. Once you've done this, please also include the byte count of your code in the header. – Martin Ender Apr 7 '16 at 9:04
• And anyways, per the rules, using C++ is prohibited. – Zacharý Jun 23 '17 at 12:58