# House of cards (version 1)

Version 2 here.

Simple challenge: given an integer, draw a house of cards with the given number of stories. If the number is negative, draw the house upside-down. Examples:

Input: 2
Output:

/\
--
/\/\

Input: 5
Output:

/\
--
/\/\
----
/\/\/\
------
/\/\/\/\
--------
/\/\/\/\/\

Input: 0
Output: <empty, whitespace or newline>

Input: -3
Output:

\/\/\/
----
\/\/
--
\/


Input can be numeric or a string. Output must be exactly as shown, with leading and/or trailing spaces and newlines allowed.

This is , so may the shortest program/function for each language win!

• This comes from the sandbox. Commented Jul 10, 2017 at 11:30
• Are leading newlines allowed? Commented Jul 10, 2017 at 11:35
• @Shaggy yes, you can also have leading whitespaces and newlines, as long as you draw the house of cards exactly as shown. I don't mind if it is not aligned to the left of the screen. Commented Jul 10, 2017 at 11:36
• Can we thrown and error on input=0?
– Rod
Commented Jul 10, 2017 at 11:45
• @Rod If that produces empty output it's allowed by default Commented Jul 10, 2017 at 11:47

# Python 2, 979594 92 bytes

-2 bytes thanks to Luka
This version produces an exception on n=0,but without printing anything

n=input()*2
m=abs(n)
for i in range(2,m+1)[::n/m]:print(i/2*'/-\-'[i%2::2][::n/m]).center(m)


Try it online!

### Non-error version, Python 2, 94 bytes

n=input()*2
x=n>0 or-1
for i in range(2,x*n+1)[::x]:print(i/2*'/-\-'[i%2::2][::x]).center(n*x)


Try it online!

• x=n>0 or-1 => x=n>0or-1 Commented Jul 10, 2017 at 17:38
• @Zacharý doesn't work, 0or will be interpreted as an octa number
– Rod
Commented Jul 10, 2017 at 17:42
• Cut 2 more bytes: m=abs(n). Then, instead of x put n/m, instead of x*n put m
– Luka
Commented Jul 10, 2017 at 20:44

# 05AB1E, 3029 24 bytes

ÄF„--N×„/\N>×}).C∊2ä¹0‹è


Try it online!

Explanation

ÄF                         # for N in [0 ... abs(input-1)] do:
„--N×                    # push the string "--" repeated N times
„/\N>×              # push the string "/\" repeated N+1 times
}             # end loop
)            # wrap stack in a list
.C          # pad strings on both sides to equal length
∊         # vertically mirror the resulting string
2ä       # split in 2 parts
¹0‹    # push input < 0
è   # index into the the list with the result of the comparison


# PHP, 125 bytes

input positive trailing newline

for($s=str_pad;++$i<$b=2*abs($argn);)$t.=$s($s("",2*ceil($i/2),["-","/\\"][1&$i]),$b," ",2)."
";echo$argn>0?$t:$t=strrev($t);


Try it online!

# PHP, 130 bytes

for(;++$i<$b=2*abs($a=$argn);)echo($s=str_pad)($s("",2*abs(($a<0?$a:$i&1)+($i/2^0)),["-",["/\\","\/"][0>$a]][1&$i]),b," ",2)." ";  Try it online! # MATL, 39 bytes |:"G|@-:~'/\'G0<?P]@E:)htg45*c]xXhG0<?P  Try it online! ### Explanation | % Implicitly input, N. Absolute value :" % For k from 1 to that G| % Push absolute value of N again @- % Subtract k : % Range [1 2 ... N-k] ~ % Convert to vector of N-k zeros '/\' % Push this string G0< % Is input negative? ? % If so P % Reverse that string (gives '\/') ] % End @E % Push 2*k : % Range [1 2 ... 2*k] ) % Index (modularly) into the string: gives '/\/\...' or '\/\/...' h % Horizontally concatenate the vector of zeros and the string. Zeros % are implicitly converted to char, and will be shown as spaces t % Duplicate g % Convert to logical: zeros remain as 0, nonzeros become 1 45*c % Multiply by 45 (ASCII for '=') and convert to char ] % End x % Delete (unwanted last string containing '=') Xh % Concatenate into a cell array G0< % Is input negative? ? % If so P % Reverse that cell array % Implicit end. Implicit display  • Man, that was fast!! I hope version 2 won't be so easy... :-) Commented Jul 10, 2017 at 11:41 # C (gcc), 169 171173160164 bytes #define F(A,B,C)for(i=A;B--;)printf(C); #define P puts("");F(y,i," ")F(abs(n)-y s,i,x,y;f(n){x=n<0;for(s=x?1-n:n;s--;){y=x?-n-s:s;P,i,x?"\\/":"/\\")y+=x;P,s>x&&i,"--")}}  +13 bytes for negative case bug. Try it online! Ungolfed (207 bytes after removing all spaces and newline): s, i, x, y; f(n) { x = n < 0; for (s = x ? 1 - n : n; s--;) { y = x ? - n - s : s; puts(""); for (i = y; i--;) printf(" "); for (i = abs(n) - y; i--;) printf(x ? "\\/" : "/\\");; y += x; puts(""); for (i = y; i--;) printf(" "); for (i = abs(n) - y; s > x && i--;) printf("--");; } }  • @officialaimm fixed! thanks Commented Jul 10, 2017 at 15:55 • Suggest L"尯⽜"+x instead of x?"\\/":"/\\" Commented Jul 10, 2020 at 16:54 ## Charcoal, 3128 27 bytes ＦＩ⊟⪪θ-«←ι↓→/…\/ι↙»‖Ｍ¿‹Ｎ⁰‖Ｔ↓  Try it online! Link is to verbose version of code. I had about 4 different 32 byte answers then found this. Edit: Saved 3 4 bytes by performing the abs using string manipulation. Explanation:  ⪪θ- Split the input (θ = first input) on - ⊟ Take the (last) element Ｉ Convert it to a number i.e. abs(θ) Ｆ « Repeat that many times ←ι Print half of the -s ↓ Position for the /\s →/ Print the first / …\/ι Print half of any remaining \/s ↙ Position for the next row of -s » End of the loop ‖Ｍ Mirror everything horizontally ¿‹Ｎ⁰ If the input was negative ‖Ｔ↓ Reflect everything vertically  • I knew that a Charcoal answer would end with ¿‹θ⁰‖Ｔ↓. :-) Commented Jul 10, 2017 at 12:12 • When Charcoal is beaten by 05AB1E on an ASCII-art challenge O_o Commented Jul 10, 2017 at 13:16 • @Gryphon I don't have a one-byte abs... – Neil Commented Jul 10, 2017 at 13:20 • True, it's just weird to see this though. Makes you wonder what the world's coming to. Commented Jul 10, 2017 at 13:33 • Yeah, this'd be 23 bytes with an abs builtin. (Congrats on 48K, btw) Commented Jul 10, 2017 at 16:24 # Japt, 40 38 bytes -2 bytes thanks to @Shaggy o½½@aXc)ç +"--/\\\\/"ò gYv *Ug)pXc aÃ·  Try it online! ## Explanation o½½@aXc)ç +"--/\\\\/"ò gYv *Ug)pXc aÃ· // implicit: U = input integer o.5,.5,XYZ{UaXc)ç +"--/\\\\/"ò gYv *Ug)pXc a} qR // ungolfed o.5,.5, // array [.5,U] with step size .5 XYZ{ } // mapped by the function: (X = value, Y = index) UaXc) // absolute diff between U and ceil(X) ç // " " times that value +"--/\\\\/"ò g ) // plus ["--","/\","\/"].get(... Yv // if Y is even, 1, else 0 *Ug // times sign(U) pXc a // repeated abs(ceil(X)) times qR // all that joined with newlines  • Commented Jul 11, 2017 at 16:37 # Gaia, 21 bytes :┅“/\\“--”×¦¦_€|ḣ¤ọ×ṣ  ### Explanation : Push 2 copies of the input ┅ Get the range to the input. If positive: [1 .. n]. If negative: [-1 .. n]. If zero: [0]. “/\\“--” Push ["/\", "--"] ×¦¦ Repeat both of those strings by each number in the range. Strings go in reverse order when repeated a negative number of times. _ Flatten the list €| Centre-align the rows of the list ḣ Remove the last row (the "--"s on the bottom) ¤ Swap (bring input back to the top) ọ Sign: -1 for negative, 0 for 0, 1 for positive × Repeat the list that many times; (-1 × list) reverses it ṣ Join with newlines and implicitly output  # Mathematica, 140 bytes (T=Table;z=Column;B[a_]:=""<>"/\\"~T~a;If[#>0,m=0,m=Pi];z[Join[z/@T[{B@i,""<>"--"~T~i},{i,Abs@#-1}],{B@Abs@#}],Alignment->Center]~Rotate~m)&  # Retina, 116111 105 bytes this got way too long :/ \d+*
+^~?( *1*)1
$1¶$&¶_$& .*$

+(_.*)1
$1-- 1 /\ Ts/\\\\/.*~.* +(.*)¶((.*¶)*)(~.*)$2$4¶$1
~|_



Try it online!

negative input is denoted as ~n

# Perl 5, 100 + 1 (-n) = 101 bytes

$/=$_>0?'/\\':'\\/';push@r,$_=$"x--$q.$/x$_,y|/\\|-|r for 1..($q=abs);pop@r;say for\$_<0?reverse@r:@r


Try it online!