31
\$\begingroup\$

Given a non-negative integer, print out an X that is that big. X is the output for input 0, and you will add slashes equal to the input in each direction to extend the X for larger inputs.

Test Cases

0

X

1

\ /
 X
/ \

2

\   /
 \ /
  X
 / \
/   \

...

10

\                   /
 \                 /
  \               /
   \             /
    \           /
     \         /
      \       /
       \     /
        \   /
         \ /
          X
         / \
        /   \
       /     \
      /       \
     /         \
    /           \
   /             \
  /               \
 /                 \
/                   \

Rules

You may either print the output, or return a string or list of string from a function. A trailing newline, as well as extra interior whitespace that does not affect appear, is allowed.

This is , so shortest answer in bytes wins!

\$\endgroup\$
6
  • \$\begingroup\$ Sandbox; related \$\endgroup\$
    – Stephen
    Commented Jun 8, 2017 at 18:16
  • 9
    \$\begingroup\$ ... I'm just gonna wait for the charcoal 1-byte solution. \$\endgroup\$
    – Leaky Nun
    Commented Jun 8, 2017 at 18:16
  • \$\begingroup\$ @LeakyNun I'd be surprised if Charcoal can easily deal with the X in the middle (part of why I added it) but who knows :D \$\endgroup\$
    – Stephen
    Commented Jun 8, 2017 at 18:17
  • \$\begingroup\$ Also related \$\endgroup\$
    – Value Ink
    Commented Jun 8, 2017 at 20:02
  • \$\begingroup\$ Related, related \$\endgroup\$
    – xnor
    Commented Jun 8, 2017 at 20:05

46 Answers 46

24
\$\begingroup\$

Charcoal, 6 bytes

PX⁺¹NX

Your nonsense ain't stopping me ;)

Try it online!

\$\endgroup\$
4
  • 2
    \$\begingroup\$ The TIO looks... interesting when you put a really big number into it \$\endgroup\$
    – Stephen
    Commented Jun 8, 2017 at 18:28
  • \$\begingroup\$ @StephenS Only because of wrapping. \$\endgroup\$
    – Okx
    Commented Jun 8, 2017 at 18:28
  • \$\begingroup\$ I know, it's just intuitive that all of the wrapped `\`s get left aligned (because spaces don't get wrapped) \$\endgroup\$
    – Stephen
    Commented Jun 8, 2017 at 18:29
  • 1
    \$\begingroup\$ 5 chars (postdates challenge) just to get that little bit closer to Canvas \$\endgroup\$
    – ASCII-only
    Commented Apr 6, 2018 at 7:10
18
\$\begingroup\$

JavaScript (ES6), 79 bytes

Uses a recursive function g that walks through a grid and builds the output character by character.

n=>(g=x=>`/\\ X
`[~x?x-y?x+y-w&&2:x-n?1:3:4]+(~y?g(~x--?x:y--&&w):''))(y=w=n*2)

How?

Both variables x and y iterate from 2n to -1, where n is the input.

For each position (x, y) in the grid, we pick one of these characters:

  • 0: /
  • 1: \
  • 2: space
  • 3: X
  • 4: newline

using the following tests:

  • ~x: Falsy if x == -1: we've reached an end of line.
  • x-y: Falsy if x == y: we're located on the anti-diagonal.
  • x+y-w: Falsy if x + y == w: we're located on the diagonal.
  • x-n: Falsy if x == n: because this test is only performed when x == y, this means that we're located in the exact center of the grid.

and the following decision tree:

decision tree

Demo

let f =

n=>(g=x=>`/\\ X
`[~x?x-y?x+y-w&&2:x-n?1:3:4]+(~y?g(~x--?x:y--&&w):''))(y=w=n*2)

console.log(f(0))
console.log(f(1))
console.log(f(4))

\$\endgroup\$
1
  • 6
    \$\begingroup\$ This is... JavaScript? What has happened to you, old friend. \$\endgroup\$
    – roberrrt-s
    Commented Jun 10, 2017 at 7:17
15
\$\begingroup\$

MATL, 16 bytes

'\/X 'iEQXytEP+)

Try it online!

Consider input 2 as an example. The stack is shown here upside down, i.e. lower elements are the ones most recently pushed.

'\/X '  % Push this string
        %   STACK: '\/X '
iEQ     % Input a number, n. Multiply by 2, add 1: gives 2*n+1
        %   STACK: '\/X '
                   5
Xy      % Identity matrix of that size
        %   STACK: '\/X '
                   [1 0 0 0 0;
                    0 1 0 0 0;
                    0 0 1 0 0;
                    0 0 0 1 0;
                    0 0 0 0 1]
tEP     % Duplicate, multiply each entry by 2, flip vertically
        %   STACK: '\/X '
                   [1 0 0 0 0;
                    0 1 0 0 0;
                    0 0 1 0 0;
                    0 0 0 1 0;
                    0 0 0 0 1]
                   [0 0 0 0 2;
                    0 0 0 2 0;
                    0 0 2 0 0;
                    0 2 0 0 0;
                    2 0 0 0 0]
+       % Add the two matrices
        %   STACK: '\/X '
                   [1 0 0 0 2;
                    0 1 0 2 0;
                    0 0 3 0 0;
                    0 2 0 1 0;
                    2 0 0 0 1]
)       % Index into the string. Indexing is 1-based and modular, so 1 picks
        % the first character ('\'), ..., 0 picks the last (space)
        %   STACK: ['\   /';
                    ' \ / ';
                    '  X  ';
                    ' / \ ';
                    '/   \']
        % Implicit display
\$\endgroup\$
3
  • \$\begingroup\$ I wanted to do something similar in Octave, but you beat me to it and in MATL it is even shorter than Octave, so great work! \$\endgroup\$
    – Michthan
    Commented Jun 9, 2017 at 8:48
  • \$\begingroup\$ @Michthan Thanks! An Octave version would definitely be worth posting too. My atempt is at 38 bytes, what's yours? \$\endgroup\$
    – Luis Mendo
    Commented Jun 9, 2017 at 11:50
  • \$\begingroup\$ I have been thinking about it all weekend and couldn't find a more efficient way than the one you are using here.. So all credits should go to you for an octave version. \$\endgroup\$
    – Michthan
    Commented Jun 12, 2017 at 7:12
14
\$\begingroup\$

Canvas, 3 bytes

╵\┼

Try it here!

half of the size of the Charcoal answer :D

╵    increment the input
 \   create a diagonal that long
  ┼  and quad-palindromize, mirroring what's required, with 1 overlap;
     This overlaps the `/` and `\`, resulting in `X`
\$\endgroup\$
6
  • \$\begingroup\$ Dang that is short. \$\endgroup\$
    – dylnan
    Commented Apr 5, 2018 at 20:55
  • \$\begingroup\$ :||||||| +1 for golfiness \$\endgroup\$
    – ASCII-only
    Commented Apr 6, 2018 at 5:51
  • \$\begingroup\$ also i wonder if stack-based languages basically always outgolf other languages? \$\endgroup\$
    – ASCII-only
    Commented Apr 6, 2018 at 7:59
  • \$\begingroup\$ @ASCII-only jelly \$\endgroup\$
    – Okx
    Commented Apr 6, 2018 at 8:19
  • \$\begingroup\$ @Okx *stack-based/tacit \$\endgroup\$
    – ASCII-only
    Commented Apr 6, 2018 at 8:38
6
\$\begingroup\$

C, 108 106 104 bytes

a;g(n){for(int b=2*n,i=1,c=47;a+=i;!b?i=-i,c=92:puts(""),b-=2*i)printf("%*c%*c",a,b?c^115:88,b,b?c:10);}

Try it online!

(−2 golfing thanks to MD XF)

(−1 golfing thanks to ceilingcat)

It prints two characters (at first, c = 47, which is a slash, and c + 45, which is a backslash; then they are swapped) with a dynamic field width.

The field widths start at 1 and 2n, and at each iteration, the first width is incremented by 1, and the second one is decremented by 2.

When the second field width becomes 0, it outputs 'X' and a newline instead of the regular characters, and reverses the direction of increments (i). A newline is printed for all other lines separately (puts("")).

\$\endgroup\$
3
  • \$\begingroup\$ 106 bytes: a,b,i=1,c;g(n){for(b=2*n,c=47;a+=i;b?puts(""):(i=-i,c=92),b-=2*i)printf("%*c%*c",a,b?c+45*i:88,b,b?c:10);} Try it online! \$\endgroup\$
    – MD XF
    Commented Jun 10, 2017 at 2:56
  • \$\begingroup\$ Thanks for the idea! I only used a part of it to make sure the code can be called twice. \$\endgroup\$
    – anatolyg
    Commented Jun 10, 2017 at 14:49
  • \$\begingroup\$ Thanks for the suggestion. Removing unneeded parentheses is always great! \$\endgroup\$
    – anatolyg
    Commented May 20, 2020 at 9:56
5
\$\begingroup\$

shortC, 111 bytes

s(x){Wx--)R" ")}j;f(x){O;j<x;j++)s(j),P92),s((x-j)*2-1),R"/\n");s(x);R"X\n");Wj--)s(j),P47),s((x-j)*2-1),R"\\\n

Based on my C answer. Conversions:

  • R -> printf(
  • P -> putchar(
  • W -> while(
  • O -> for(
  • Auto-inserted closing ");}

This also uses ASCII codes for \ and /.

Try it online!

\$\endgroup\$
5
\$\begingroup\$

Python 2, 81 bytes

r=range(2*input()+1)
for i in r:print''.join(' \/X'[i==j::2][r[~i]==j]for j in r)

Try it online!

\$\endgroup\$
5
\$\begingroup\$

C, 168 155 150 bytes

-5 thanks to Computronium

#define p printf(
s(x){while(x--)p" ");}j;f(x){for(;j<x;j++)s(j),p"\\"),s((x-j)*2-1),p"/\n");s(x);p"X\n");while(j--)s(j),p"/"),s((x-j)*2-1),p"\\\n");}

Can certainly be golfed; I'm doing so. Try it online!

Ungolfed:

int space(int x)
{
    while (x--)
        putchar(' ');
}

int f(int x)
{
    for (int j = 0; j < x; j++) {
        space(j);
        printf("\\");
        space((x-j)*2-1);
        printf("/\n");
    }

    space(x);
    puts("X");

    while (j--) {
        space(j);
        putchar('/');
        space((x-j)*2-1);
        printf("\\\n");
    }
}
\$\endgroup\$
1
  • 2
    \$\begingroup\$ You can lose 5 characters by defining p to be "printf(" instead of "printf". \$\endgroup\$ Commented Jun 9, 2017 at 10:17
4
\$\begingroup\$

V, 21 bytes

éXÀñ>HÄÒ r\Á/YGpr/$r\

Try it online!

Hexdump:

00000000: e958 c0f1 3e48 c4d2 2072 5cc1 2f59 4770  .X..>H.. r\./YGp
00000010: 722f 2472 5c                             r/$r\

Explanation:

éX                      " Insert an 'X'
  Àñ                    " Arg1 times:
    >H                  "   Add a space to every line.
                        "   Conveniently, this also puts us on the first line
      Ä                 "   Duplicate this line
       Ò                "   And replace the whole line with spaces
         r\             "   Replace the first char with '\'
           Á/           "   Append a '/' char
             Y          "   Yank this line
              G         "   Move to the last line
               p        "   And paste the line we yanked
                r/      "   Replace the first character with a '/'
                  $     "   Move to the end of the line
                   r\   "   And replace the last character with a '\'

Essentially, we have Insert an X, n times extend the slashes.

But it's not quite that simple because we also have to add the slashes the first time. If the slashes were already there, we could write extend the slashes as:

>HÄX2pGÙX2p

Which would save us 6 bytes.

\$\endgroup\$
4
\$\begingroup\$

///, 223 bytes

/|/\\\\//i///& /  &// &///> /^b|b^v|v^^$|+^
f|fvv&i|||^$|-^^$|-^$|+^^<|$^<-|$>|->vv&i||||
^^<-|$^<|$^^f|f| ^ f|f^^>|->| ^ >|->^^f|fv|v^||||^^>|->v|v^|||^^^v|v  ^ b|b^>//^/\///b\/>/b\/\/$|+\/\/\/<|$\/\///>$+//>i$+
iX/<$//
<$

Try it online!

Seems like a fitting language for the challenge. (suck it, sed)

Input is given in unary spaces, after /i/:

/|/\\\\//i/<spaces here>//& /  &// &///...

Explanation: don't ask me, I only programmed it ;)

sorta commented version, lightly ungolfed version

I didn't save the pregolfed code, and I don't understand it enough anymore to take it apart again (or maybe just laziness, who knows)

\$\endgroup\$
4
\$\begingroup\$

APL (Dyalog), 25 bytes

Requires ⎕IO←0 which is default on many systems.

' \/X'[(⊢+2×⌽)∘.=⍨⍳1+2×⎕]

Try it online!

' \/X'[] index the string with

 get input

 multiply by two

1+ add one

 that many integers

∘.=⍨ equality table (i.e. identity matrix; NW-SE diagonal)

() apply the following tacit function on that

   the argument

  + plus

   two times

   the horizontally mirrored argument (i.e. NE-SW diagonal)

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

C#, 157 122 120 bytes

_=d=>"".PadLeft(d)
a=>{var s=_(a)+"X\n";for(int i=0;++i<=a;)s=$@"{_(a-i)}\{_(i*2-1)}/
{s+_(a-i)}/{_(i*2-1)}\
";return s;}

Ungolfed version:

 Func<int, string> _ = (d) =>"".PadLeft(d);
        Func<int, string> func = a => {

            var s = _(a) + "X\n";

            for (int i = 0; ++i <= a;) {

                s = $@"{_(a - i)}\{_(i * 2 - 1)}/
{s + _(a - i)}/{_(i * 2 - 1)}\
";

            }
            return s;
        };
\$\endgroup\$
6
  • 1
    \$\begingroup\$ You can move the other anonymous function out of the first and then include it as _=d=>new string(' ',d); (note no need for the braces around d). You can remove the curly braces around the for loop. Make use of a verbatim string with so you don't need to escape all of the backslashes. If you set i=0 then you can do ++i<a+1 and remove the i++. \$\endgroup\$ Commented Jun 9, 2017 at 8:41
  • \$\begingroup\$ Also with verbatim strings you don't need to include \n an actual line feed will work, though I'm not sure if you will then be able to remove the braces around the for loop, you would have to try. \$\endgroup\$ Commented Jun 9, 2017 at 8:42
  • 1
    \$\begingroup\$ After applying the first suggestion by TheLethalCoder, you can also replace the ++i<a+1 for ++i<=a EDIT You can also save 4 more bytes by changing the Func from new string(' ',d) to "".PadLeft(d) \$\endgroup\$
    – auhmaan
    Commented Jun 9, 2017 at 8:54
  • \$\begingroup\$ Thanks for suggestions, @TheLethalCoder am I allowed to declare 2 functions like that, wouldn't that make a lot of C# golfing shorter if we can do that? \$\endgroup\$
    – LiefdeWen
    Commented Jun 9, 2017 at 9:22
  • 1
    \$\begingroup\$ @StefanDelport There's a meta discussion about it somewhere but as it stands I believe you can as long as you show the functions name. In this case _. \$\endgroup\$ Commented Jun 9, 2017 at 9:36
3
\$\begingroup\$

Mathematica, 71 bytes

(Partially inspired by Jenny_mathy's 104-byte solution)

""<>#&/@(#"\\"+Reverse@#"/"&@IdentityMatrix[2#+1]/.{0->" ",a_+_->"X"})&

Returns a list of strings.

Explanation: IdentityMatrix[2#+1] makes a matrix of the right size with 1s along the diagonal and 0s elsewhere. Next, we multiply it by "\\" (an escaped backslash), which makes it a matrix with backslashes along the diagonal and 0s elsewhere, since of course 1 times backslash is backslash and 0 times backslash is 0. We add this to "/" times its reverse to make the X shape. We're nearly done, except there are still 0s everywhere, and the middle is "\\" + "/". We fix these two things by substituting " " for 0 and "X" for a_+_, which matches any sum of two things (like _+_ should, except Mathematica is too clever for its own good and interprets that as 2 times _). Finally, ""<>#&/@ turns this into a list of strings.

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

Java (OpenJDK 8), 135 bytes

i->{int k=0,j,l=2*i+1;String[]s=new String[l];for(;k<l;k++)for(s[k]="",j=0;j<l;j++)s[k]+=j==k?j==i?"X":"\\":j==l-1-k?"/":" ";return s;}

Lambda expression that takes and integer and returns an array of Strings

Try it online!

Ungolfed:

i->{
    int k=0,j,l=2*i+1;                // Some variables to be used
    String[]s=new String[l];            // Return array (size 2*i+1)
    for(;k<l;k++)                       // For each array entry
        for(s[k]="",j=0;j<l;j++)        // Set each character to 
            s[k]+=j==k?j==i?"X":"\\"    // \ or X if it's the jth character of the jth row
                 :j==l-1-k?"/"          // / if it's the opposite char
                 :" ";                  // else blank
    return s;
}
\$\endgroup\$
3
\$\begingroup\$

T-SQL, 201 bytes

DECLARE @ INT SELECT @=a FROM t DECLARE @i INT=@
WHILE @>0BEGIN PRINT SPACE(@i-@)+'\'+SPACE(2*@-1)+'/'SET @-=1 END
PRINT SPACE(@i)+'X'WHILE @<@i BEGIN SET @+=1 PRINT SPACE(@i-@)+'/'+SPACE(2*@-1)+'\'END

Formatted:

DECLARE @ INT 
SELECT @=a FROM t 
DECLARE @i INT=@
WHILE @>0
    BEGIN
        PRINT SPACE(@i-@)+'\'+SPACE(2*@-1)+'/'
        SET @-=1 
    END
PRINT SPACE(@i)+'X'
WHILE @<@i 
    BEGIN 
        SET @+=1 
        PRINT SPACE(@i-@)+'/'+SPACE(2*@-1)+'\'
    END

Input is via column a in named table t, per our guidelines.

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

Ruby, 66 bytes

Recursive function.

f=->x{?X[x]||"\\#{s=' '*(2*x-1)}/
#{f[x-1].gsub /^/,' '}
/#{s}\\"}

Try it online!

Explanation

f=->x{                  # Start of recursive function named `f`
      ?X[x]||           # Return 'X' if x==0, otherwise the following:
"\\#{s=' '*(2x-1)}/     #  Top edge of the cross. Save no. of spaces needed
#{f[x-1]                #  Get result of f[x-1]
        .gsub /^/,' '}  #  Regex sub to left-pad every line w/ a space
/#{s}\\"                #  Bottom edge of cross (insert saved no. of spaces)
\$\endgroup\$
3
\$\begingroup\$

Jelly, 24 17 bytes

Ḥ‘=þ`µḤ+Uị“/\x ”Y

Try it online!

How it Works

Ḥ‘=þ`µḤ+Uị“/\x ”Y   main link, input a
Ḥ‘                  input doubled and incremented
   þ                Make a table: Apply  
  =                 "equals"/ to      
    `               each element in range(2a+1) cartesian multiplied with itself.
                      eg. For input 1: [1=1,1=2,1=3],[2=1,2=2,2=3],[3=1,3=2,3=3]      
     µ              on this array:
       +            add: 
      Ḥ             double of it to
        U           its reverse (changes south-east to north-west)
         ị“/\x ”    index into the string "/\x " to get the right characters
                Y   join by newlines for the final output.

-6 bytes thanks to @LeakyNun and -1 byte with an additional improvement

\$\endgroup\$
1
  • \$\begingroup\$ 18 bytes \$\endgroup\$
    – Leaky Nun
    Commented Jun 13, 2017 at 14:05
3
\$\begingroup\$

Perl 5 + -M5.10.0 -pla, 78 bytes

@n=($")x$F[0]--,$_=$"x--$_."\\@n/",say,$\=$/.y'/\\'\/'r.$\for 1..$_;$_=$"x$_.X

Try it online!

Explanation

Loops for 1..$_ (implicit line from STDIN - n - from the implicit -n from -p). Each iteration sets @n to a list of n, decrementing ($F[0]--, $F[x] accesses the xth index of @F which is implicitly set, by -a, to the input, split on whitespace, which is only ever the one value, n), spaces ($"), then sets $_ the concatenation of the current loop value, less one, spaces, the interpolated string "\\@n/" where @n is expanded with a space between each element (which is also space) making n*2-1 spaces for each iteration. say outputs $_ by default and $\ is then prepended with a newline ($/) and the /result of transliterating (y''') all slashes to their opposite.

Outside of the loop $_ is set to n spaces and a literal X.

Because of -p $_ is automatically printed, followed by $\.


Some very similar alternatives that might be easier to golf further (all 78 bytes too):

$_=$"x--$_."\\@{[($\")x$F[0]--]}/",say,$\=$/.y'/\\'\/'r.$\for 1..$_;$_=$"x$_.X
map{@n=($")x$F[0]--;say$_=$"x--$_."\\@n/";$\=$/.y'/\\'\/'r.$\}1..$_;$_=$"x$_.X
map{say$_=$"x--$_."\\@{[($\")x$F[0]--]}/";$\=$/.y'/\\'\/'r.$\}1..$_;$_=$"x$_.X

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

Raku (Perl 6) (rakudo), 85 73 bytes

{for $_ ->\y {say [~] .map({' \\/X'.comb[2*!(y+$_)+(y==$_)]})}}o{-$_..$_}

Attempt This Online!

\$\endgroup\$
2
\$\begingroup\$

Batch, 201 bytes

@echo off
set s= /
for /l %%i in (2,1,%1)do call set s=  %%s%%
set s=\%s%
for /l %%i in (-%1,1,%1)do call:c
exit/b
:c
echo %s%
set s=%s:\ = \%
set s=%s:X =/\%
set s=%s:\/=X %
set s=%s: /=/ %

Starts by building up the top line, then after printing each line, moves the \ right one space and the / left once space, making sure that they make an X in the middle.

\$\endgroup\$
2
\$\begingroup\$

PHP, 115 bytes

for(;$i<$c=1+2*$argn;$b?:$t[$i-1]="\\".!$t[$c-$i]="/",$o.="$t\n")$t=str_pad(" X"[$b=$argn==+$i++],$c," ",2);echo$o;

Try it online!

\$\endgroup\$
2
\$\begingroup\$

Retina, 74 bytes

.+
$* X
+`^ ( *).( *)
$1\  $2/¶$&
+`¶ ( *).( *).?$
$&¶$1/  $2\
m` (\W)$
$1

Try it online! Explanation:

.+
$* X

Place the X.

+`^ ( *).( *)
$1\  $2/¶$&

Starting at the X, working upwards, place a \ diagonally to the left each time. Also place a / two more spaces after the / than last time.

+`¶ ( *).( *).?$
$&¶$1/  $2\

Starting at the X, working downwards, place a / diagonally to the left each time. Also place a \ two more spaces after the / than last time.

m` (\W)$
$1

The number of spaces between the two diagonals needs to be odd, so the last space on each line (except the original X line) is deleted.

\$\endgroup\$
2
\$\begingroup\$

Mathematica, 131 bytes

(F[x_,y_]:=Table[x<>StringJoin@Table[" ",i]<>y,{i,1,#*2,2}];Column[Join[Reverse@F["\\","/"],{"X"},F["/","\\"]],Alignment->Center])&


Mathematica, 104 bytes

here is another approach using Grid

(S=DiagonalMatrix[Table["\\",r=2#+1]];Table[S[[r+1-i,0+i]]="/",{i,r}];S[[#+1,#+1]]="X";Grid@S/. 0->" ")&
\$\endgroup\$
2
\$\begingroup\$

Bash, 138 bytes

for i in `seq $1;seq $[$1-1] -1 1`
{ $[a++]
printf "%*c%*s\n" `echo ' '$i $[a>$1?1:2] $[($1-i)*2]' '$[a<$1?1:2]`
}|sed 's/22/X/'|tr 12 /\\

Try it online!

Really long, bash heates '\ and /'

Less golfed

 for i in {1..10} {9..1};{
   $[a++];                      #argument as padding, prints 1 for \ and 2 for /
   printf "%*c%*s\n" `echo ' '$i $[a>$1?1:2] $[($1-i)*2]' '$[a<$1?1:2]`;
  }|sed 's/22/X/g' | tr 12 /\\
\$\endgroup\$
2
\$\begingroup\$

Python 2, 95 84 bytes

-10 bytes thanks to @FelipeNardiBatista

f=lambda s,i='\n':i+(s and'\\'+'  '*~-s+' /'+f(s-1,i+' ')+i+'/'+'  '*~-s+' \\'or'X')

Try it online!

\$\endgroup\$
2
  • 1
    \$\begingroup\$ 85 bytes: TIO \$\endgroup\$ Commented Jun 9, 2017 at 14:10
  • \$\begingroup\$ @FelipeNardiBatista thanks a lot \$\endgroup\$
    – ovs
    Commented Jun 9, 2017 at 15:02
2
\$\begingroup\$

05AB1E, 21 bytes

F'\Nú}'X¹ú).B€.∞ø€.∞»

Try it online!

\$\endgroup\$
2
\$\begingroup\$

C (gcc), 99 85 bytes

f(x,h,t){for(h=2*x+2,t=h*h-h;t--;putchar(t^h*x-~x?t%h?~-t%~h?t%~-h?32:47:92:10:88));}

-14 bytes, Thanks to ceilingcat

Try it online!

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

brainfuck, 285 276 bytes

+++++++++++[>+>>++++++++>++++>++++++++>+++<<<<<<-]>->>++++>+++>>->>>,[>>-<<[<<[<.>->+<]<[<]>.[>]>>[<<++>>->+<]<<-[<.>-]<<<.<<<.>>[>]+>[<+>-]>>-[<+>-]<]<<[<.>->>+<<]<<.<<<<.>>[>]>>[->+<[<<<.>>+>-]<<<<<.>>>>[>+<-]>>[<<<++>+>>-]<<[>>+<<-]<-[<.>-]<<[<]>.<<.>>[>]>>]]>>+[<<<<<<.>>]

Try it online!

Input uses bytes. So 1 is \x01

Alternative Version which supports numbers (366 313 bytes)

\$\endgroup\$
2
\$\begingroup\$

05AB1E, 15 bytes

>I'\×'X«3.Λ.º.∊

Try it online.

Explanation:

Step 1: Draw the top-left to bottom-right line:

>            # Increase the (implicit) input-integer by 1
 I'\×       '# Push a string with the input amount of "\"
     'X«    '# Append a "X" to that string
        3    # Push a 3
         .Λ  # Use the Canvas builtin with these three arguments

Try just the first step online.

Step 2: Mirror with overlap in both directions:

.º           # Intersected mirror horizontally
  .∊         # Intersected mirror vertically
             # (after which the result is output implicitly)
\$\endgroup\$
2
\$\begingroup\$

Uiua SBCS, 22 21 bytes

⊏+⇌×2.⊞=.⇡+1×2:$  \/X

Try it!

-1 thanks to noodle man!

It turns out the method I used is the exact one used in Adám's APL answer. I didn't look though, I swear.

\$\endgroup\$
2
  • \$\begingroup\$ You don’t need rows \$\endgroup\$ Commented Apr 8 at 11:51
  • \$\begingroup\$ @noodleman Good catch, thanks! \$\endgroup\$
    – chunes
    Commented Apr 8 at 17:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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