48
\$\begingroup\$

Write a program or function that takes in a positive integer (via stdin, command line, or function arg) and prints or returns a string of that many of these small triangles tiled together, alternating which way they point:

 /\ /__\ 

This sole triangle is the output if the input is 1.

If the input is 2, the output is

 ____ /\ / /__\/ 

If the input is 3, the output is

 ____ /\ /\ /__\/__\ 

If the input is 4, the output is

 ________ /\ /\ / /__\/__\/ 

And so on. Your program must support inputs up to 216 - 1 = 65535.

Details

  • The leftmost triangle always points upwards.
  • There may be trailing spaces but there may not be unnecessary leading spaces.
  • There may be an optional trailing newline.
  • Note that for 1 the output is two lines long but otherwise it's three. This is required.
  • The shortest submission in bytes wins.
\$\endgroup\$
0

32 Answers 32

1
2
0
\$\begingroup\$

C# (.NET Core), 151 bytes

Without LINQ - 3 string array.

Like most of these, this fails if the integer goes over the max char count per line for stdout.

p=>{var s=new string[3]{ " ","",""};for(var j=0;j< p;){if(j++%2<1){s[1]+=j==p-1?@" /":@" /\ ";s[2]+=j==p-1?@"/":@"/__\";}else s[0]+="____";}return s;} 

Try it online!

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

Retina, 88 bytes

K` ____¶ /\ /¶/__\/ %`....$ $+*$& %`(.+)\1$ $1 ( (____)*)__(¶.*) /(¶.*)/ $1$3$4 G`\S 

Try it online! Explanation:

K` ____¶ /\ /¶/__\/ 

Replace the input with a pair of triangles.

%`....$ $+*$& 

Multiply the triangles by the original input.

%`(.+)\1$ $1 

Divide the triangles by 2.

( (____)*)__(¶.*) /(¶.*)/ $1$3$4 

Remove the left-over half triangle.

G`\S 

Remove the first line if it is now blank.

\$\endgroup\$
1
2

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.