SQL, 182 175 173 187 bytes
Not that this'll ever be the shortest, but it's still amusing to try to minimize sql ;) lol I did this in Oracle 11, however, these should be basic SQL. [edit] as pointed out, I didn't apply the when input = 1 rule - only show 2 lines. can't think of a better way to do it, however, I did save a couple bytes by modifying the v logic ;) adding 2 ahead of time saves a couple bytes by not having to repeat it later [/edit]
select decode(&i,1,'',rpad(' ',v,'____')||z)||rpad(' /',v,'\ /')||decode(y,1,'\')||z||rpad('/',v-1,'__\/')||decode(y,1,'__\')from(select 2+floor(&i/2)*4v,mod(&i,2)y,chr(10)z from dual);
[edit1] removed some unnecessary spaces[/edit1] [edit2] changed &&i to just &i. It cuts down 2 chars, but forces user to input the # of triangles twice ... :P I realized my "good coding habits" using &&i were costing be 2 bytes!! The horror!! [/edit2]
Explanation (note: I use &&1 in this explanation so it only prompts once, the &1 above saves code space, but prompts multiple times ;) )
select -- line 1 decode(&&1,1,'', -- don't need line 1 if input is 1 rpad(' ',v,'____') || z ) || -- every pair of triangles -- line 2 rpad(' /',v,'\ /') || -- every pair of triangles decode(y,1,'\') || z || -- add the final triangle, input: 1,3,5 etc. -- line 3 rpad('/',v-1,'__\/') || -- every pair of triangles decode(y,1,'__\') -- add the final triangle, input: 1,3,5 etc. from (select 2+floor(&&i/2)*4 v, -- common multiplier. 4 extra chars for every triangle pair mod(&&i,2) y, -- Flag for the final triangle (odd inputs, 1,3,5, etc) chr(10) z -- CR, here to save space. from dual);
Output
SQL> accept i 1 SQL> / /\ /__\ SQL> accept i 2 SQL> / ____ /\ / /__\/ SQL> accept i 3 SQL> / ____ /\ /\ /__\/__\ SQL> accept i 12 SQL> / ________________________ /\ /\ /\ /\ /\ /\ / /__\/__\/__\/__\/__\/__\/ SQL>