Building spikes

Your task is simple, given a positive integer n, output the spiked building to size n

Testcases

1
->
^
/|\
/.|.\
/..|..\
_______

2
->
^  ^
/|\/|\
/.|..|.\
/..|..|..\
__________

7
->
^  ^  ^  ^  ^  ^  ^
/|\/|\/|\/|\/|\/|\/|\
/.|..|..|..|..|..|..|.\
/..|..|..|..|..|..|..|..\
_________________________


Trailing spaces are allowed

You are to output the string with newlines

This is , so shortest code wins!

• What should it look like for 0? Should we just not output anything? Mar 10 at 7:29
• 0 is a nonvalid input @Lecdi Mar 10 at 7:45
• You said "nonnegative integer" in the challenge, which includes 0. Maybe change that to "positive integer" Mar 10 at 8:21

JavaScript (Node.js), 80 bytes

n=>   ^
/|\\
/.|.\\
/..|..\\
___.replace(/.[_|^]./g,'$&'.repeat(n))+'____'  Try it online! • brilliant! this is a really smart solution :D Mar 10 at 5:46 Python 3.8 (pre-release), 81 bytes lambda n:f" {' ^'*n}\n "+'/|\\'*n+'\n /'+(d:='.|.'*n)+rf'\ /.{d}.\ _'+'_'*3*-~n  Try it online! Thanks @UnrelatedString for -3 bytes, by teaching me about the rf string literal. Thanks @AidenChow for -1 byte, by adding another f-string. Thanks @tsh for -1 byte. Wow, looks like this has become a bit of a community effort. • You, my friend, are a genius of python 3.8! Mar 10 at 8:07 • ...this is the first I've ever even thought about this, but looks like raw string literals handle backslash-newline perfectly here Mar 10 at 8:16 • @UnrelatedString Wow, I've never seen rf string literals before. You learn something new every day... Mar 10 at 8:20 • 82 bytes using another f-string at the beginning. Mar 10 at 8:29 • '+'_'*(3*n+4) could be _'+'_'*3*-~n – tsh Mar 10 at 8:47 Vyxal, 30 bytes »ε¥»₄τ2?»øƒ≈»₇τẋṀf|^/\.τ\_+§  Try it Online! Modified port of the Jelly answer. »ε¥»₄τ # [2, 14, 19, 3] 2 Ṁ # Insert at position 2... »øƒ≈»₇τ # [74, 125, 99] ? ẋ # Repeated <input> times f # Flatten the whole thing |^/\.τ # Decompress each from base with the key "|^/\." \_+ # Append an underscore to each § # Transpose, fill and join by newlines.  Old version below because I thought it was quite elegant. VyxalC, 42 bytes  ^ /| .| .| __øM↵* / /. __øṀ↵½Zƛ÷$j


Try it Online!

This is quite elegant but somewhat messy approach. I'm unsatisfied with the last bit, vj should work but it doesn't.

The first bit produces the string

 ^
/|\
.|.
.|.
___


Then repeats each row of that by the input.

Then, it creates



/\
/..\
____


by mirroring half of each line, and inserts the previous into that. Finally, the whole thing is centered.

Jelly, 30 bytes

“\ɓ^‘ẋ“£×“Œ¥‘jṃ“|/.\^””_;Ɱz⁶ṚY


Try it online!

How?

“\ɓ^‘ẋ“£×“Œ¥‘jṃ“|/.\^””_;Ɱz⁶ṚY - Main Link: integer, N
“\ɓ^‘                          - Code-page indices = [92, 155, 94]
ẋ                         - repeat N times
“£×“Œ¥‘                  - Code-page indices = [[2, 17], [19, 4]]
j                 - join -> [2, 17, 92, 155, 94, ..., 92, 155, 94, 19, 4]
“|/.\^”         - list of characters = "|/.\^"
ṃ                - convert to base 5 using "|/.\^" in place of the digits 12340
Ɱ     - map across these lists of characters with:
”_;      -   concatenate to an '_' character
z⁶   - transpose with space characters as filler
Ṛ  - reverse
Y - join with newlines
- implicit print


Charcoal, 30 bytes

_/¶_./¶×“ ∧σ¿⊘=8G℅H«⊙”Ｎ_.\¶_\⟲


Try it online! Link is to verbose version of code. Explanation:

_/¶_./¶


Print the first two columns.

×“ ∧σ¿⊘=8G℅H«⊙”Ｎ


Print the middle columns repeated the appropriate number of times.

_.\¶_\


Print the last two columns.

⟲


Rotate to orient the output correctly.

Python 3, 124 91 90 88 bytes

lambda n:[print(('   /_  /._'+' /.._^|||_ \.._'*n+'  \._   \_')[i::5])for i in range(5)]


Try it online!

• 91: lambda n:[print((' /_ /._'+' /.._^|||_ \\.._'*n+' \\._ \\_')[i::5])for i in range(5)]
– tsh
Mar 10 at 6:25
• Save one more byte with an r-string Mar 10 at 8:19

APL+WIN, 88 73 bytes

Prompts for spikes.

Original

l←5 2⍴¯10↑'//.__'⋄c←5 3⍴' ^ /|\.|..|.___'⋄r←5 2⍴¯10↑'\ .\__'⋄⊃⊂[2]⍎'l,',((2×⎕)⍴'c,'),'r'


A simpler iindexing solution

m←5 7⍴'   ^     /|\   /.|.\ /..|..\_______'⋄m[;⍳2],m[;(3×⎕)⍴2+⍳3],m[;6 7]


Try it online! Thanks to Dyalog APL Classic

Ruby, 69 bytes

->n{'   ^
/|\
/.|.\
/..|..\
_______'.lines.each{|l|l[2,3]*=n}*''}


Try it online!

Lambda tacking n that multiplies inner substring n times for each line of the spike.

05AB1E, 4241 35 bytes

Y17•₅œ •₅вIи19Y·)˜"^|/.\"Åв'_δšζRJ»


-6 bytes porting @JonathanAllan's Jelly answer

See the previous revision for the original 42 and 41 bytes approaches.

Explanation:

Y              # Push 2
17             # Push 17
•₅œ •          # Push compressed 6021919
₅в        # Convert it to base-255 as list: [92,155,94]
Iи      # Repeat this list the input amount of times
19             # Push 19
Y·             # Push 4 (2 doubled)
)             # Wrap the stack into a list
˜            # Flatten
"^|/.\"Åв  "# Convert it to custom base-"^|/.\"
# (basically base-length, and then index into the string)
δ            # Map over each inner list:
'_ š          '#  Prepend a "_" to each
ζ          # Zip/transpose; swapping rows/columns, with a space " " as
# default filler
R         # Reverse the list of lists
J        # Join each inner list together to a string
»       # Join by newlines
# (after which the result is output implicitly)


See this 05AB1E tip of mine (section How to compress large integers? and How to compress integer lists?) to understand why •₅œ • is 6021919 and •₅œ •₅в is [92,155,94].

Retina, 64 63 bytes

.+
$&*$(  ^)¶  $&*$(/|\)¶ /$&*$(.|.)\¶/.$&*$(.|.).\¶__$&*3*___  Try it online! Link includes test cases. Explanation: Just an application of Retina 1's string repetition operator. Note that repetition has higher precedence than concatenation so the string to be repeated has to be grouped (except in the case of repeating three _s which is achieved via a second repetition). Regenerate, 61 bytes  ( ^ ){$~1}
(/\|\\){$~1} /((.\|.){$~1})\\
/.$3.\\ _{#3+4}  Attempt This Online! Explanation $~1 is the input number, and {$~1} repeats something that many times. So:  ( ^ ){$~1}


Two spaces, followed by  ^  N times.

  (/\|\\){$~1}  Two spaces, followed by /|\ N times.  /((.\|.){$~1})\\


 /, followed by .|. N times (and capture that result as group 3), followed by \.

/.$3.\\  /., followed by the contents of group 3 again, followed by .\. _{#3+4}  _ repeated len(group 3) + 4 times. • I think it's meant to be _ at the end? Mar 11 at 20:11 • @emanresuA Fixed, thanks. Mar 11 at 20:49 K (ngn/k), 76 66 bytes {0:+?[4 4#" / /. \\. \\";2;,/(x,3 4)#" /..^||| \\.."],'"_"}  Try it online! • ?[a;2;b] use splice to insert b into a at position 2 • 4 4#" / /. \\. \\" the initial array, representing the "sides" of the spiked building • ,/(x,3 4)#" /..^||| \\.." x copies of the spikes • ?[;;],"_" append a "_" to each slice • 0:+ transpose the above, and print to stdout Pip, 46 bytes FlRsX,4.:"/\"J'|WR'.X,3PE'^AE'_X7{(l2,5)X:aPl}  Attempt This Online! Explanation First, we generate this list [" ^" " /|\" " /.|.\" "/..|..\" "_______"]  as follows: RsX,4.:"/\"J'|WR'.X,3PE'^AE'_X7 ,3 ; Range(3): [0;1;2] '.X ; Repeat . that many times: ["";".";".."] '|WR ; Wrap | in each of those strings: ["|";".|.";"..|.."] "/\"J ; Insert each of those strings between / and \: ; ["/|\";"/.|.\";"/..|..\"] PE'^ ; Prepend "^" to the front of that list AE'_X7 ; and append "_______" to the end: ; ["^";"/|\";"/.|.\";"/..|..\";"_______"] ,4 ; Range(4): [0;1;2;3] sX ; Repeat space that many times: ["";" ";" ";" "] R ; Reverse: [" ";" ";" ";""] .: ; Concatenate those two lists itemwise: ; [" ^";" /|\";" /.|.\";"/..|..\";"_______"]  Then we loop over each line, repeat the center section, and print the result: Fl...{(l2,5)X:aPl} Fl { } ; For each line l ... ; in the above list: (l ) ; The section of l 2,5 ; at indices range(2,5) i.e. [2;3;4] (modular 0-based indexing) X: ; string-repeat in place a ; (program argument) times Pl ; Print (the modified version of) l with a trailing newline  Lua, 92 bytes print(([[ ^ /|\ /.|.\ /..|..\ ]]):gsub(".[_|^].",("%1"):rep(...))..('_'):rep(4+3*...))  Attempt This Online! I feel like it can go a bit lower but don't want to play with it right now. Basically? a port of tsh's answer but with the underscores outside the initial string. Retina 0.8.2, 70 bytes .+$&$*1¶$&$*2¶ /$&$*3\¶/.$&$*3.\¶__$&\$*4__
1
^
2
/|\
3
.|.
4
___


Try it online! Link includes test cases. Explanation: Since Retina 0.8.2 can only repeat characters, placeholder digits are used for the four different building parts which are then substituted in afterwards.

CJam, 66 bytes

ri:R;SSSa"^  "R*NSS"/|\\"R*NS'/".|.":QR*'\N"/."QR*".\\"N'_"___"R)*


Try it online! I haven't golfed for a while, and longer since CJam, so this probably has significant optimizations available, but I was in the mood to try something. It basically just constructs the result line by line, with a couple minor optimizations by saving the size as a variable, saving the ".|." construction as a variable since we re-use it, and using 3(n+1)+1 instead of 3n+4 to construct the bottom row.