# Print me a Tower Block

Print a tower block with the shortest possible code.

Input:

The input defines how many floors the tower block has. One floor contains a window on either side of the door. The window is made up of 3x3 hashes.

An example of a 4 storey tower block is below:

=====================
)V V V V V V V V V V(
)V V V V V V V V V V V(
)V V V V V V V V V V V V(
)V V V V V V V V V V V V V(
~~~~~~~~~~~~~~~~~~~~~~~~~~~
: : : : : : : : : : : : : :
: : ### : : : : : : ### : :
: : ### : : : : : : ### : :
: : ### : : : : : : ### : :
: : : : : : : : : : : : : :
: : : : : : : : : : : : : :
: : ### : : : : : : ### : :
: : ### : : : : : : ### : :
: : ### : : : : : : ### : :
: : : : : : : : : : : : : :
: : : : : : : : : : : : : :
: : ### : : : : : : ### : :
: : ### : : : : : : ### : :
: : ### : : : : : : ### : :
: : : : : : : : : : : : : :
: : : : : _______ : : : : :
: : ### : I     I : ### : :
: : ### : I     I : ### : :
: : ### : I     I : ### : :
: : : : : I     I : : : : :

Update:

The input has to be one or greater.

Trailing spaces at the end of lines are allowed.

In my example, every line has three leading spaces. This isn't mandatory, just the tower block with the input is.

• Can the input be less than 1? – nmjcman101 Dec 23 '16 at 1:05
• Are trailing spaces at the end of lines allowed? – ngenisis Dec 23 '16 at 1:09
• Thanks for your questions - please see the update in my question. – Belfield Dec 23 '16 at 9:51

# V, 72 bytes

13iV r(É)3ñÄ¯lxñÄ21r=GÙÒ~Ù14R: ÙÄ2w3r#7w.3ÄkdGÀpG4k5w7r_bêojrIÎfIl5r

Try it online!

Here is a hexdump, since this contains unprintable characters:

00000000: 3133 6956 201b 7228 c929 33f1 c4af 6c78  13iV .r(.)3...lx
00000010: f1c4 3231 723d 47d9 d27e d931 3452 3a20  ..21r=G..~.14R:
00000020: 1bd9 c432 7733 7223 3777 2e33 c46b 6447  ...2w3r#7w.3.kdG
00000030: c070 4734 6b35 7737 725f 1662 ea6f 6a72  .pG4k5w7r_.b.ojr
00000040: 49ce 6649 6c35 7220                      I.fIl5r

I ran into a strange bug. The section in the middle: dGÀpG should have been: ÀäGG, but this does not work for inputs of 1, and I have no idea why. ¯\_(ツ)_/¯

## Mathematica, 301288 258 bytes

" "~(s=If[#2==0,"",#~StringRepeat~#2]&)~3<>{"="~s~21,"
",s[" ",12-#]<>{")","v "~s~#,"v(
"}&/@9~Range~12,"~"~s~27,"
",s[(x=(u=": ")~s~13<>":
")<>{y=u<>{z=": ### ",v=u~s~5,w=z<>": :
"},y,y,x},#-1],v,"_"~s~7," ",v,"
",m=u<>{z,u,n="I     I ",w},m,m,v,n,w}&

Pure function which takes a positive integer and outputs a string. The output string won't look right because Mathematica apparently doesn't display monospace fonts as monospace:

For reasons I don't quite understand, it does format as monospace if you Print the string:

Edit: Saved several bytes by not including " " at the beginning of each line. Changed the definition of s to handle the case where there is only one floor (StringRepeat doesn't like repeating a string 0 times).

Edit 2: Thanks to LegionMammal978 and the fact that StringJoin is Listable, this is now an incomprehensible nightmare of nested lists and also 30 bytes shorter.

• At least 26 bytes can be saved by replacing a<>b<>...<>x with a<>{b,...,x} in certain parts. – LegionMammal978 Dec 23 '16 at 21:25

# Python 2, 275270262246240 236 bytes

Saved a couple with a hint from @Flp.Tkc and by changing the first for loop.

16 saved with more help from @Flp.Tkc

a,h,b,c,w=' ',"I  ",": "," :","#"*3;d,e,j=b*2+w+a+b+h,b*5+h,[b*14]
print'\n'.join([a*3+'='*21]+[a*(4-x)+')'+'V '*(x+8)+'V('for x in 1,2,3,4]+['-'*27]+(j+[b*2+w+c*6+a+w+c*2]*3+j)*(input()-1)+[b*5+"_"*7+c*5]+[d+a+d[::-1]]*3+[e+a+e[::-1]])

Try it online!

Just builds each line of the tower as a string and adds it to an array them prints the array at the end. If anyone wants a full explanation I'll grudgingly give if I can remember how it works ☺

# PowerShell, 193 bytes

"   "+"="*21
3..0|%{" "*$_+")"+"V "*(12-$_)+"V("}
"~"*27
--$args[0]..0|%{($b=": "*5)+(($a=": "*4),'_______ ')[!$_]+$b;,(': : ### : '+($a,($c='I I '))[!$_]+': ### : :')*3;$b+($a,$c)[!$_]+$b} Try it online! (I feel there may still be a few bytes here or there. Sub-190 seems doable.) The first three lines form the roof, using string multiplication and concatenation, along with a loop 3..0|%{...} to get the correct number and sloping of Vs. The next line runs from the input pre-decremented --$args[0] down to 0 as a loop (the pre-decrement allows us to index using !$_ instead of$_-eq1 saving several bytes later). Each loop iteration, we're constructing a bunch of strings, setting variables $b and$a along the way. We're also using pseudo-ternaries (... , ...)[...] to choose the appropriate strings for the middle so we can get the doorway on the first floor correct.

Each of the strings are left individually on the pipeline, and the default Write-Output inserts newlines between, so we get those for free.

# T-SQL, 378372353331 325 bytes

Golfed:

DECLARE @ INT=3

,@h varchar(max)=REPLICATE('~',27)SELECT @h+='
: '+a+IIF(n>@*5-6,IIF(n%5=0,'_______ ','I     I '),t)+a+':'FROM(SELECT
IIF(n%5%4=0,t,': ### : ')a,*FROM(SELECT': : : : 't,number n,*FROM spt_values)x)y
WHERE type='P'and n<@*5SET @=0WHILE @<4SELECT
@h=SPACE(@)+')'+REPLICATE('V ',12-@)+'V(
'+@h,@+=1PRINT'   '+REPLICATE('=',21)+'
'+@h

Ungolfed:

DECLARE @ INT=3

,@h varchar(max)=REPLICATE('~',27)
SELECT @h+='
: '+a+IIF(n>@*5-6,IIF(n%5=0,'_______ ','I     I '),t)+a+':'
FROM
(SELECT IIF(n%5%4=0,t,': ### : ')a,*
FROM
(SELECT': : : : 't,number n,*
FROM spt_values)x)y
WHERE type='P'and n<@*5
WHILE @>=0
SELECT @h=SPACE(3-@)+')'+REPLICATE('V ',9+@)+'V(
'+@h,@-=1
PRINT'   '+REPLICATE('=',21)+'
'+@h

Try it out

# C, 409406 402 bytes

#define P(x)p(": ",x);
#define S(x)p(x,1);
#define L P(2)p("#",3);p(" :",6);S(" ###");S(" : :\n")
#define Q p("V ",i+++9)
p(s,n)char*s;{printf(s,--n?p(s,n):0);}i;t(n){p(" ",3);p("=",21);S("\n   )")Q;S("V(\n  )")Q;S("V(\n )")Q;S("V(\n)")Q;S("V(\n")p("~",27);S("\n")for(;--n;){P(13)S(":\n")L;L;L;P(13)S(":\n")}P(5)p("_",7);p(" :",5);S("\n")p(": : ### : I     I : ### : :\n",3);P(5)S("I     I")p(" :",5);}

Call with:

int main()
{
t(4);
}

## Batch, 373 bytes

@echo off
set s=###
echo    %s:#========%
for %%s in ("   )" "  )V " " )V V " ")V V V ")do echo %%~sV%s:#= V V V%(
echo %s:#=~~~~~~~~~%
set t=: : ### : I     I : ### : :
set s=%t:I     I=: : : :%
for /l %i in (2,1,%1)do echo %s:###=: :%&echo %s%&echo %s%&echo %s%&echo %s:###=: :%
set s=%t:###=: :%
echo %s:I     I=_______%
echo %t%
echo %t%
echo %t%
echo %s%

Builds the ridge and gutter by noticing that they are multiples of 3, which shaves off a few bytes. Builds the roof by noticing that the suffix is the same for each line (and again includes some threefold repetition). Builds the walls by starting with the most interesting line of wall, which is the ground floor window, and removing details to generate the other parts of the wall.

# Javascript, 335 bytes

y=z=>{a="   "+"=".repeat(21);for(b=9;13>b;b++)a+="\n"+" ".repeat(12-b)+")"+"V ".repeat(b)+"V(";a+="\n"+"~".repeat(27);b="\n"+": ".repeat(14);c=": : ### : : : : : : ### : :";for(d=0;d<z-1;d++)a+=b+"\n"+c+"\n"+c+b;a+="\n: : : : : _______ : : : :\n"+": : ### : I     I : ### : :\n".repeat(3)+": : : : : I     I : : : : :";console.log(a)};

Creates a function y() with argument z, such that y(z) produces the desired output.

# Example Usage:

y=z=>{a="   "+"=".repeat(21);for(b=9;13>b;b++)a+="\n"+" ".repeat(12-b)+")"+"V ".repeat(b)+"V(";a+="\n"+"~".repeat(27);b="\n"+": ".repeat(14);c=": : ### : : : : : : ### : :";for(d=0;d<z-1;d++)a+=b+"\n"+c+"\n"+c+b;a+="\n: : : : : _______ : : : :\n"+": : ### : I     I : ### : :\n".repeat(3)+": : : : : I     I : : : : :";console.log(a)};

console.log(y(3));

I'm transitioning from normal JavaScript to code-golf JS. Any tips would be greatly appreciated.

# Canvas, 62 61 bytes

⁶=⁵×V７× ＊ )×４＊∔／‾²ｍ~７«× ×∔│８ ×:＊５＊#３３＊６２╋│⁸＊∔ｌ４－_７× ５×Iｅ４＊∔╋╋

Try it here! Input 0 works as expected even though that's not required.

• hey, how is the height of the house modified using this script ? – t-clausen.dk Jan 2 '19 at 13:34
• My old eyes missed the number in the right box – t-clausen.dk Jan 2 '19 at 13:45