[Question]
  [
Take an array of nonnegative integers, such as `[1, 0, 0, 1, 2, 4, 2, 0]`. Then, draw that as a mountain where the integers represent altitude:
```
     x  
        
    x x 
x  x    
 xx    x
```
You may use any printable non-whitespace character in place of `x`, and adding padding or whitespace after lines or the output is fine (but not required). You may optionally take one indexed inputs. Transposing the output is not allowed, but returning an array of lines is fine.
This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so shortest answer (in bytes) per language wins.
  
[Answer]
# [Vyxal](https://github.com/Lyxal/Vyxal), 4 bytes
```
×꘍R§
```
[Try it Online!](https://lyxal.pythonanywhere.com?flags=&code=%C3%97%EA%98%8DR%C2%A7&inputs=%5B1%2C%200%2C%200%2C%201%2C%202%2C%204%2C%202%2C%200%5D&header=&footer=)
That's right, it's flagless.
## Explained
```
×꘍    # [(n * " ") + "*" for n in input]
  R   # [x[::-1] for x in ^]
   §  # vertically join (rotate) ^
```
Using the `L` flag would make it 3 bytes.
[Answer]
# [Python 2](https://docs.python.org/2/), 66 bytes
```
a=input()
n=max(a)
while~n:print''.join(' x'[x==n]for x in a);n-=1
```
[Try it online!](https://tio.run/##HcbBCkBAFEbhvae4u5kphKzoPoksZkGu@GfSyNh49SF1@jr@DotDk5JlgT@DNhl4t1Fbk12LbNODzh@CoFS5OoFWFNUQmTHO7qBIArKmR8F1SkOdU/X3TZNT@1uNLw "Python 2 – Try It Online")
[Answer]
# [05AB1E (legacy)](https://github.com/Adriandmen/05AB1E/tree/fb4a2ce2bce6660e1a680a74dd61b72c945e6c3b), 5 bytes
```
$úζR»
```
[Try it online!](https://tio.run/##MzBNTDJM/f9f5fCuc9uCDu3@/z/aUEfBAIyADCMdBRMwaRALAA "05AB1E (legacy) – Try It Online")
```
$        # push "1" and the input
 ú       # for each integer in the input,
         # pad "1" with this many spaces in the front
  ζ      # tranpose, padding with spaces
   R     # reverse, the mountains should not be upside down
    »    # join by newlines
```
[Answer]
# [Zsh](https://www.zsh.org/), ~~66~~ 63 bytes
```
s=${(l/${${(On)@}[1]}*#/)}
for x;s[++i+$#s-#*x]=.
fold -$#<<<$s
```
[Attempt This Online!](https://ato.pxeger.com/run1=m724qjhjwYKlpSVpuhY37YttVao1cvRVqoGUf56mQ220YWytlrK-Zi1XWn6RQoV1cbS2dqa2inKxrrJWRaytHlA4J0VBV0XZxsZGpRhiDNS0HdFGOgqGYARkGOsomIJJw1ioPAA)
-3 thanks to JoKing, but still probably too long.
Explanation:
* `${${(On)@}[1]}`: get the maximum input
* `s=${(l/*#/)}`: construct a string of spaces which is (number of inputs) × (maximum of inputs) in length
* `for x;s[++i+$#s-#*x]=.`: set the correct index of the string to a `.` for each element
* `fold -$#<<<$s`: line-wrap the string at (number of inputs) in length
[Answer]
# [APL(Dyalog Unicode)](https://dyalog.com), 18 bytes [SBCS](https://github.com/abrudz/SBCS)
```
{⊖⍉⍕⍪'x',¨⍨⍵⍴¨' '}
```
```
{          ⍝ Open function
⊖⍉         ⍝ Flip diagonally and then vertically
⍕          ⍝ Make table into multiline string
⍪           ⍝ Display one element per row
'x',¨⍨      ⍝ Append an 'x' to each element
⍵⍴¨' '      ⍝ Duplicate each space 'input' times
}           ⍝ Close function
```
[Try it on online!](https://razetime.github.io/APLgolf/?h=AwA&c=q37UNe1Rb@ej3qmPelepV6jrHFrxqBeItj7q3XJohbqCei0A&f=e9Q39VHbhDQFQwUDIDRUMFIwAWIDAA&i=AwA&r=tio&l=apl-dyalog&m=dfn&n=%E2%8E%95)
[Answer]
# [Red](http://www.red-lang.org), 91 bytes
```
func[a][i: last sort copy a until[forall a[prin either a/1 = i[1][sp]]print""0 > i: i - 1]]
```
[Try it online!](https://tio.run/##FYyxCsMwDAX3fsUje6hdMgXaj@gqNIjEoQLHNrYy9Otdl@Omg6th7@@wE99OW/txpY2ESVdEaYaWq2HL5QvBlUwjHblKjBAqVROC2idUyN3jCSXP1ArzP9k0ObwwRooZnrmfBvJwA48HlqHj/gM "Red – Try It Online")
-6 bytes from Galen Ivanov.
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 7 bytes
```
Ṭ€z0Ṛo⁶
```
[Try it online!](https://tio.run/##y0rNyan8///hzjWPmtZUGTzcOSv/UeO2/48aZhxuj/x/dNLDnTP@RxvqKBiAEZBhpKNgAiYNYgE "Jelly – Try It Online")
Outputs a list of lines. +1 byte (append `Y`) if unacceptable.
Takes input 1 indexed, uses `1` as the mountain character
## How it works
```
Ṭ€z0Ṛo⁶ - Main link. Takes a list L on the left
 €      - Over each element in L:
Ṭ       -   Untruthy; Map each n to [0, 0, ..., 1] with n-1 zeros
  z0    - Transpose, padding with zeros
    Ṛ   - Reverse
     o⁶ - Replace 0s with spaces
```
[Answer]
# [J](http://jsoftware.com/), 17 bytes
```
[:|.@|:' x'#~,.&1
```
[Try it online!](https://tio.run/##y/qvpKeepmBrpaCuoKNgoGAFxLp6Cs5BPm7/o61q9BxqrNQVKtSV63T01Az/a3L5OekpOObk5heXKJTnF2UX6ygklZYo5OWD9FeoV9fZxljV6XFxpSZn5CukKRgCjQQjIMNIR8EETBr8BwA "J – Try It Online")
+6 thanks to Lynn for spotting a bug in the original solution: `' x'{~=\:~.` This approach can be made to work but it's no longer golfy: `' x'{~]=/~[:i.1-@+>./`
## how
* `,.&1` Zip input with 1:
```
1 1
0 1
0 1
1 1
2 1
4 1
2 1
0 1
```
* `' x'#~` Duplicate `' x'` according to these pairs
```
 x   
x    
x    
 x   
  x  
    x
  x  
x
```
* `[:|.@|:` Rotate left:
```
     x  
    x x 
x  x    
 xx    x
```
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 6 [bytes](https://github.com/DennisMitchell/jelly/wiki/Code-page)
```
=ⱮṀṚo⁶
```
A monadic Link that accepts a list of positive integers (the 1-indexed option) and yields a list of lists of characters and integers (`1` being the choice for `x`).
**[Try it online!](https://tio.run/##y0rNyan8/9/20cZ1D3c2PNw5K/9R47b/h9sj//@PNtJRMAQjIMNYR8EUTBrGAgA "Jelly – Try It Online")** (The footer joins with newlines and then Jelly's implicit, smashing print produces the output.)
### How?
```
=ⱮṀṚo⁶ - Link: list of integer heights, H
  Ṁ    - maximum (H) -> M
 Ɱ     - map across (h in [1..M]) with:
=      -   (H) equals (h) (vectorises)
   Ṛ   - reverse -> X
     ⁶ - space character
    o  - (X) logical OR (' ') (vectorises)
```
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), 6 bytes
```
↑ＥＡ◧xι
```
[Try it online!](https://tio.run/##S85ILErOT8z5/z@gKDOvRMMqtEBHwTexQMMzr6C0RENTRyEgMcUnNa1EQ6lCSUchU1NT0/r//@hoIx0FQzACMox1FEzBpGFs7H/dshwA "Charcoal – Try It Online") Link is to verbose version of code. 1-indexed. Explanation:
```
  Ａ     Input array
 Ｅ      Map over elements
    x   Literal string `x`
   ◧    Left-padded to width
     ι  Current element
↑       Print rotated
```
[Answer]
# [Japt](https://github.com/ETHproductions/japt) [`-R`](https://codegolf.meta.stackexchange.com/a/14339/), 7 [bytes](https://en.wikipedia.org/wiki/ISO/IEC_8859-1)
1-indexed, using `"` for the peaks.
```
£QùXÃÕÔ
```
[Try it](https://petershaggynoble.github.io/Japt-Interpreter/?v=1.4.6&flags=LVI&code=o1H5WMPV1A&input=WzIsIDEsIDEsIDIsIDMsIDUsIDMsIDFd)
```
£QùXÃÕÔ     :Implicit input of array
£           :Map each X
 Q          :  Quotation mark
  ùX        :  Left pad with spaces to length X
    Ã       :End map
     Õ      :Transpose
      Ô     :Reverse
            :Implicit output joined with newlines
```
[Answer]
# [Ruby](https://www.ruby-lang.org/), 51 bytes
```
->a{(-a.max..0).map{|y|a.map{|x|x==-y ??x:' '}*''}}
```
[Try it online!](https://tio.run/##KypNqvyfZvtf1y6xWkM3US83sUJPz0ATSBdU11TWJEIYFTUVtra6lQr29hVW6grqtVrq6rW1/wtKS4oV0qKjDXUUDMAIyDDSUTABkwaxsf8B "Ruby – Try It Online")
[Answer]
# [Python 3](https://docs.python.org/3/), 67 bytes
```
lambda x:[[v==i and'*'or' 'for v in x]for i in range(max(x),-1,-1)]
```
[Try it online!](https://tio.run/##K6gsycjPM/6fZhvzPycxNyklUaHCKjq6zNY2UyExL0VdSz2/SF1BPS2/SKFMITNPoSIWxMwEMYsS89JTNXITKzQqNHV0DYFIM/Y/XDZNI9pQR8EAjIAMIx0FEzBpEKtpxaUABAVFmXklGpma/wE "Python 3 – Try It Online")
`for i in range(max(x),-1,-1)` -> identify how high the mountain will be, max value is first line (top), so start from max, iterate to 0
`[v==i and'*' or' ' for v in x]` -> for every integer in input set it as \* if height matches current line, set it whitespace otherwise.
[EDIT] as per @hyper-neutrino suggestion to get 3 bytes less, and wrapped in lambda as per @Razetime comment
[Answer]
# [Vyxal](https://github.com/Lyxal/Vyxal), ~~11~~ 9 bytes
-2 bytes through auto-vectorizing
```
ð*×+ðÞṪṘ⁋
```
```
ð*            # vectorised n spaces
  ×+          # append "*"
     ðÞṪ      # transpose with space as filler
        Ṙ⁋    # reverse and join by newline
```
[Try it Online!](https://lyxal.pythonanywhere.com?flags=&code=%C6%9B%C3%B0*%C3%97%2B%3B%C3%B0%C3%9E%E1%B9%AA%E1%B9%98%E2%81%8B&inputs=%5B1%2C%200%2C%200%2C%201%2C%202%2C%204%2C%202%2C%200%5D&header=&footer=)
[Answer]
# [JavaScript (Node.js)](https://nodejs.org), ~~77~~ ~~74~~ ~~73~~ 70 bytes
-1 thanks to @RecursiveCo.  
-3 thanks to @m90's idea
```
a=>{for(i=Math.max(...a);i;i--)console.log(a.map(e=>i^e&&' ').join``)}
```
[Try it online!](https://tio.run/##JYtRCsIwEESvsl9tgs3Sin8luYEnEKVLTXRLzZY2iCCePdYKw/Bg3gz0pKWfeUomytXnXuKSIICFTNa9g8yK7ZHSHR/0UohIuuWWjdE/U0aPo9wUreukvHV88UVRQqlxEI5dpz85qFNTQb1lhX0Fh63r8/8E1oHfNVrnLw "JavaScript (Node.js) – Try It Online")
Takes one-indexed input.
[Answer]
# [R](https://www.r-project.org/), 65 bytes
```
function(a)for(i in max(a):0)cat(c(' ','x')[1+(a==i)],'
',sep='')
```
[Try it online!](https://tio.run/##NY2xCsMwDER3f4U2SVSDUzIV9CWlgzANaIgcUgfy964JBI7j3fJu72s9opmH9uWI0rwGGS91JwcPWO0c85W5WKNCCCh4Ir@nB5mq80cwofy@myJyNy00CeQrA54C89WZ0/0zdKn/AQ "R – Try It Online")
[Answer]
# [Wolfram Language (Mathematica)](https://www.wolfram.com/wolframscript/), 44 bytes
```
Print@@@Table[" "Unitize[#+i],{i,-Max@#,0}]&
```
[Try it online!](https://tio.run/##y00syUjNTSzJTE78n2b7P6AoM6/EwcEhJDEpJzVaSUEpNC@zJLMqNVpZOzNWpzpTR9c3scJBWcegNlbtf5pDtaGOARAa6hjpmACxQe1/AA "Wolfram Language (Mathematica) – Try It Online")
Prints the mountain, using `0` instead of `x`.
Remove the `Print@@@` for -8 bytes if an array of characters and numbers is acceptable output.
[Answer]
# [Octave](https://www.gnu.org/software/octave/) / MATLAB, 43 bytes
```
@(x)flip([accumarray([x find(x)],3)+32 ''])
```
Anonymous function that inputs a 1-based column vector and outputs a char matrix with `#` and 
[**Try it online!**](https://tio.run/##y08uSSxL/Z9mq6en999Bo0IzLSezQCM6MTm5NDexqCixUiO6QiEtMy8FKBWrY6ypbWykoK4eq/k/TSPayFrBEIyADGNrBVMwaQiUAwA "Octave – Try It Online")
[Answer]
# [Pip](https://github.com/dloscutoff/pip) `-l`, 10 bytes
```
R:sXg.0ZDs
```
Takes the integers as command-line arguments. Outputs using `0` in place of `x`. [Try it here!](https://replit.com/@dloscutoff/pip) Or, here's an 11-byte equivalent in Pip Classic: [Try it online!](https://tio.run/##K8gs@P8/KMyqOCJdzyDKpfj/f0MuAyA05DLiMgFig/@6RTkA "Pip – Try It Online")
### Explanation
```
            g is list of cmdline args; s is space (implicit)
  sXg       Convert each arg to a string of that many spaces
     .0     Append 0 to each string of spaces
       ZDs  Transpose, extending shorter strings with a default value of space
R:          Reverse the resulting list
            Autoprint, one row per line (-l flag)
```
[Answer]
# [Canvas](https://github.com/dzaima/Canvas), 7 [bytes](https://github.com/dzaima/Canvas/blob/master/files/chartable.md)
```
｛ ×x＋］↶
```
[Try it here!](https://dzaima.github.io/Canvas/?u=JXVGRjVCJTIwJUQ3eCV1RkYwQiV1RkYzRCV1MjFCNg__,i=JTVCMSUyQyUyMDAlMkMlMjAwJTJDJTIwMSUyQyUyMDIlMkMlMjA0JTJDJTIwMiUyQyUyMDAlNUQ_,v=8)
[Answer]
# [Pyth](https://github.com/isaacg1/pyth), 7 bytes
```
_.tm+*;
```
[Try it here!](http://pythtemp.herokuapp.com/?code=_.tm%2B%2a%3B&input=%5B1%2C+0%2C+0%2C+1%2C+2%2C+4%2C+2%2C+0%5D&debug=0)
]