PowerShell v2+, 217 205 190 187 184 bytes
param($b)"_"*(($a=[math]::Abs($b))*4);$z,$y='/\'[($b=$b-lt0),!$b]
((($x=1..$a|%{($w=" "*($_-1))+$z+" "*(2*($a-$_))+$y+(' ','_')[$_-eq$a]*($a*2-1)+$y+$w})|%{-join$_[($a*4)..0]}),$x)[$b]
Takes input $b
as an integer. Note that if $b
is negative, you need to explicitly surround it with parens to cast it appropriately (see examples), else PowerShell will think it's a string.
Regardless of which direction the tent is facing, the first line is the same, a bunch of underscores; exactly 4*abs(input)
many of them, actually. That number is also stored into $a
for use later. Additionally, now that we have the absolute value of $b
stored into $a
, we turn $b
into a Boolean for its sign, and choose our slashes stored into $y
and $z
.
The next line is constructing and formulating the output, and it's a doozy, so let's break it down.
We're essentially indexing into an array of two elements, (big long calculations saved into $x)
or $x
, based on $b
.
The calculations are where the tent body is constructed. We loop from 1..$a|%{...}
. Each iteration we're constructing a line of the tent body. We start with a number of spaces equal to the line # we're on -1
, so that it's appropriately left-aligned. That's stored into $w
for later, and concatenated with the appropriate slash ($z, based on $b
), then the doorframe number of spaces, then the other slash $y
, then either underscores or spaces depending upon if we're on the bottom line or not, then another slash $y
, and finally the appropriate number of trailing spaces ($w
) to construct a rectangular string. That resulting array of strings is stored into $x
.
If the left half of the array is selected (i.e., $b
is False
since the input was positive), then we need to loop through $x
and reverse each line item -- this is where the trailing spaces come into play; it allows us to simply reverse the lines rather than re-calculate distances.
If $b
is True
, then the right half of the array $x
is selected instead.
In either case, the pipeline now contains an array of strings. Implicit output via Write-Output
happens at program completion, with default newline between elements.
Examples
PS C:\Tools\Scripts\golfing> .\print-upside-down-tent.ps1 (-5)
____________________
\ / /
\ / /
\ / /
\ / /
\/_________/
PS C:\Tools\Scripts\golfing> .\print-upside-down-tent.ps1 (4)
________________
\ \ /
\ \ /
\ \ /
\_______\/
1Are trailing spaces OK? Meaning, can we output four strings of 12 length (a rectangle) for input
3
for example? – AdmBorkBork – 2016-09-14T12:50:09.7101@TimmyD They are allowed. – user48538 – 2016-09-14T12:51:03.297
I first misread the title for Upside-Down-Ternet. Which might yield another interesting challenge...
– Tobias Kienzler – 2016-09-15T09:06:12.0971@Nathaniel I'm curious why you haven't close-voted Turtles, given the same reasoning. – AdmBorkBork – 2016-09-15T12:32:00.900
2@TimmyD sure, that one's probably a dupe of something else too, I'm not really sure where the chain starts. I just think we've seen enough of these by now. – Nathaniel – 2016-09-15T13:08:18.923
5I fail to see how the questions are even remotely similar. Sure, they're both [tag:ascii-art] challenges that take an number and have you output the n-th iteration of something, but that's where the similarity ends. If that's enough to close as dupe, we shouldn't take any more [tag:ascii-art] challenges at all. – James – 2016-09-15T16:25:32.500
2
@Nathaniel Our accepted guideline for two challenges being duplicates is whether answers from one can be reused (competitively) on the other with little or no modification. Whether challenges bring something novel to the table is not part of that guideline. Please use downvotes for challenges you want to discourage or just ignore them if they don't think they're interesting and let those who do enjoy them.
– Martin Ender – 2016-09-15T16:41:22.0801@MartinEnder I've asked a half-dozen times on meta why my questions were closed and was never once referred to an official guideline, despite explicitly asking for that. Instead I was told each time that I should just take my chances and suffer the consequences if five people happened not to like the idea. I am extremely in favour of having clear guidelines and enforcing close votes to meet them. If you're willing to delete my close votes on the basis of being against a guideline, would you please in future do the same when others VTC on my questions as well? Thanks. – Nathaniel – 2016-09-16T00:48:39.777
@MartinEnder by the way, I don't want to give the impression that I VTC'd this just to make these points. I did it because I'd been led to believe, based on my previous enquiries, that close-voting is the expected and encouraged action if you (a) don't much care for a challenge type, and (b) have a sort of general feeling that it's a bit duplicatey. I was trying to play along despite not feeling that's a fair way to do things, and I'm genuinely happy to hear that it's not encouraged after all. If this turns out not to be a double standard then I might be able to enjoy contributing after all. – Nathaniel – 2016-09-16T01:27:20.720