| Bytes | Lang | Time | Link |
|---|---|---|---|
| 131 | C clang | 241011T144557Z | jdt |
| 140 | AWK | 241029T160703Z | xrs |
| 133 | Python 3.8 prerelease | 241013T192901Z | Klumpy7 |
| 027 | Vyxal | 241011T224200Z | emanresu |
| 029 | 05AB1E | 241014T082958Z | Kevin Cr |
| 091 | JavaScript ES6 | 241011T145424Z | Arnauld |
| 033 | Jelly | 241011T212613Z | Jonathan |
| 029 | Charcoal | 241011T210710Z | Neil |
| 122 | APL+WIN | 241011T183056Z | Graham |
C (clang), 139 136 134 131 bytes
i,t;f(*a,n){for(i=t=0;i<n;)t^=a[i++]%2;for(puts(t?"__F_":"_F__");n--;)for(;a[n]--;t^=1)printf("|%s|\n",L"彜䑜⽟⽄"+!a[n]+2*t);}
- -6 bytes thanks to ceilingcat!
AWK, 140 bytes
{for(b=1;++i<=NF;){a[b]=b%2?"|█/|":"|\\█|"
for(j=0;++j<=$i;)a[++b]=b%2?"|\\_|":"|_/|"}a[b]=b%2?"_⚑__":"__⚑_"
for(;b>0;)print a[b--]}
Python 3.8 (pre-release), 171 133 bytes
Probably can be made shorter, this is my first submission, and I'm surprised I could get it this short! I couldn't figure out how to squish it all into one line and a lambda function with less bytes. I'm open to improvements!
def T(a):
o=[n for i in a.split()for n in["|D/|"]+(int(i)-1)*["|_/|"]]+["_F__"]
print(*[o[i][::1-(l:=i%2)*2].replace(l*'/',l*'\\')for i in range(len(o))][::-1],sep="\n")
Shorter code from comments:
lambda a:[print(v[::i%2*2-1].replace(i%2*'\\',i%2*'/'))for i,v in enumerate(["_F__"]+[f"|{c}\|"for i in a[::-1]for c in~-i*"_"+"D"])]
Vyxal, 30 27 bytes
ʁ†f‛_Dİv`|Π/|`‛_F4eJ‡øṀ∷ẇṘ⁋
Try it Online! -3 bytes inspired by Kevin Cruijssen's 05AB1E answer.
ʁ # For each, range from 0 to n-1
† # Logical NOT of each, giving 1s as first items in subarrays
f # Flatten, giving a list of 0/1 bits representing doors/floors
İ # And map 0, 1 to
‛_D # _, D
v`|Π/|` # Insert each into "|[char]/|" (this is legitimately the shortest way I could find to do this)
J # And append
‛_F4e # "_F__"
‡---ẇ # To every other line
øṀ # Mirror it, flipping slashes,
∷ # And take the second half, flipping it vertically
Ṙ⁋ # Reverse the result and join by newlines
05AB1E, 29 bytes
L˜Θ„_Dsè„|\ì…__Fª€Ć2Å€º2äθ}R»
Try it online or verify all test cases.
Explanation:
L # Map each value in the (implicit) input-list to a [1,value]-ranged list
˜ # Flatten this list of lists
Θ # Check for each value whether it equals 1 (1 if 1; 0 otherwise)
„_D # Push string "_D"
sè # 0-based index the earlier 1s/0s into this
„|\ì # Prepend "|\" before each character in the list
…__Fª # Append "__F" to the list
€Ć # Enclose each string; appending its own head
2Å€ } # Apply to every 0-based index where index%2==0:
º # Mirror the current string
2ä # Split it into two equal-sized parts
θ # Pop and only leave the second mirrored part
R # Then reverse the entire list of strings
» # And join it by newlines
# (after which the string is output implicitly as result)
JavaScript (ES6), 91 bytes
f=(a,r,c=([h,...a]=a,"D"))=>h--?f(a,!r,"_")+`
|${r?"\\"+c:c+"/"}|`:h?f(a,r):r?`__F_`:`_F__`
Commented
f = ( // f is a recursive function taking:
a, // a[] = input array
r, // r = a flag that is truthy when the door or the
// flat surface must appear on the right
c = ( // c = initialized to 'D', then set to '_'
[h, ...a] = a, // h = height of current floor, extracted from a[]
"D" // when f is called with c undefined
) //
) => //
h-- ? // if h is defined and not 0 (decrement it afterwards):
f(a, !r, "_") + // do a recursive call with r inverted and c = '_'
`\n|${ // append a new line and a '|' followed by:
r ? "\\" + c // either '\' and c if r is truthy
: c + "/" // or c and '/' if r is falsy
}|` // append another '|'
: // else:
h ? // if h is not NaN:
f(a, r) // do a recursive call for the next floor
// with r unchanged and c undefined
: // else (end of recursion):
r ? `__F_` // append the roof with the flag on the right ...
: `_F__` // ... or on the left, according to r
Jelly, 35 34 33 bytes
ÄŻ‘Ṭ~JḂṭ;ƭ"ƊØ2jⱮṚ‘Ṡ’$1¦ị“\/|FD_”Y
How?
ÄŻ‘Ṭ~JḂṭ;ƭ"ƊØ2jⱮṚ‘Ṡ’$1¦ị“\/|FD_”Y - Link: list of floor heights, H
Ä - cumulative sums of {H}
Ż - prefix {that} with a zero
‘ - increment
Ṭ - untruth -> list of door/floor bits
~ - bitwise not of {that} (vectorises)
-> -2 for doors (D); -1 for floor (_)
Ɗ - last three links as a monad -f(X=that):
J - [1..length(X)]
Ḃ - mod two -> [1,0,1,0,...]
(representing "\/\/...")
" - zip {that} and {X} with:
ƭ - alternate between:
ṭ - tack
; - concatenate
Ø2jⱮ - [2,2] joined with each of those
(representing the "||")
Ṛ - reverse
‘ - increment (vectorises)
(now -1:D 0:_ 1:\ 2:/ 3:|
but the roof is like any other level)
1¦ - apply to the first (the roof):
Ṡ’$ - sign and then decrement
-> takes -1 (D) to -2 (F),
and 1,2,3 (\/|) to 0 (_)
ị“\/|FD_” - index (1-indexed & modular) into "\/|FD_"
Y - join with newline characters
Charcoal, 29 bytes
_F__¶F⮌⭆A⭆ι§_D¬λ«M³→‖T⟦⪫||⁺ι/
Try it online! Link is to verbose version of code. Explanation:
_F__¶
Output the flag.
F⮌⭆A⭆ι§_D¬λ«
Convert the list of floors into a list of Ds and _s depending on where the doors should be, and work down from the top floor.
M³→‖T
Reflect the tower so far, turning any /s into \s and vice versa as necessary.
⟦⪫||⁺ι/
Draw the next floor of the tower. This ensures that the bottom floor is always |D/|.
APL+WIN, 122 bytes
Prompts for a vector of floor heights.
m←((i←+/n←⎕),4)⍴' '⋄m[;1 4]←'|'⋄m[;2]←i⍴'_\'⋄m[;3]←i⍴'/_'⋄m[(2|d)/d←1,¯1↓1++\n;2]←'D'⋄m[(~2|d)/d;3]←'D'⋄((-2|i)⌽'_F__')⍪⊖m