g | x | w | all
Bytes Lang Time Link
008Pip l210627T061342ZDLosc
067Python 3210629T133117ZGrysik
065R210627T230615ZDominic
007Pyth210627T230517Zhakr14
007Canvas210627T230334Zhakr14
006Jelly210626T152754ZJonathan
nanJavaScript Node.js210626T092549ZFZs
017J210626T143540ZJonah
043Octave / MATLAB210626T183029ZLuis Men
009Vyxal210626T072835ZUndersla
044Wolfram Language Mathematica210626T181404Zatt
063Zsh210626T085304Zpxeger
051Ruby210626T164052ZG B
007Jelly210626T100145Zcaird co
091Red210626T075107ZRazetime
007Japt R210626T090343ZShaggy
00505AB1E legacy210626T090311Zovs
004Vyxal210626T075951Zlyxal
006Charcoal210626T075317ZNeil
018APLDyalog Unicode210626T072914ZAviFS
066Python 2210626T072853Zdingledo

Pip -l, 10 8 bytes

RZJsXg.0

Takes the integers as command-line arguments. Outputs using 0 in place of x. Attempt This Online!

Explanation

RZJsXg.0
          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
 ZJ       Transpose, padding to a rectangle with spaces
R         Reverse the resulting list
          Autoprint, one row per line (-l flag)

Python 3, 67 bytes

lambda x:[[v==i and'*'or' 'for v in x]for i in range(max(x),-1,-1)]

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

R, 65 bytes

function(a)for(i in max(a):0)cat(c(' ','x')[1+(a==i)],'
',sep='')

Try it online!

Pyth, 7 bytes

_.tm+*;

Try it here!

Canvas, 7 bytes

{ ×x+]↶

Try it here!

Jelly, 6 bytes

=ⱮṀṚ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! (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)

JavaScript (Node.js), 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!

Takes one-indexed input.

J, 17 bytes

[:|.@|:' x'#~,.&1

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

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!

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!

Wolfram Language (Mathematica), 44 bytes

Print@@@Table[" "Unitize[#+i],{i,-Max@#,0}]&

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.

Zsh, 66 63 bytes

s=${(l/${${(On)@}[1]}*#/)}
for x;s[++i+$#s-#*x]=.
fold -$#<<<$s

Attempt This Online!

-3 thanks to JoKing, but still probably too long.

Explanation:

Ruby, 51 bytes

->a{(-a.max..0).map{|y|a.map{|x|x==-y ??x:' '}*''}}

Try it online!

Jelly, 7 bytes

Ṭ€z0Ṛo⁶

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

Red, 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!

-6 bytes from Galen Ivanov.

Japt -R, 7 bytes

1-indexed, using " for the peaks.

£QùXÃÕÔ

Try it

£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

05AB1E (legacy), 5 bytes

$úζR»

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

Vyxal, 4 bytes

×꘍R§

Try it Online!

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.

Charcoal, 6 bytes

↑EA◧xι

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

  A     Input array
 E      Map over elements
    x   Literal string `x`
   ◧    Left-padded to width
     ι  Current element
↑       Print rotated

APL(Dyalog Unicode), 18 bytes 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!

Python 2, 66 bytes

a=input()
n=max(a)
while~n:print''.join(' x'[x==n]for x in a);n-=1

Try it online!