| Bytes | Lang | Time | Link |
|---|---|---|---|
| 008 | Pip l | 210627T061342Z | DLosc |
| 067 | Python 3 | 210629T133117Z | Grysik |
| 065 | R | 210627T230615Z | Dominic |
| 007 | Pyth | 210627T230517Z | hakr14 |
| 007 | Canvas | 210627T230334Z | hakr14 |
| 006 | Jelly | 210626T152754Z | Jonathan |
| nan | JavaScript Node.js | 210626T092549Z | FZs |
| 017 | J | 210626T143540Z | Jonah |
| 043 | Octave / MATLAB | 210626T183029Z | Luis Men |
| 009 | Vyxal | 210626T072835Z | Undersla |
| 044 | Wolfram Language Mathematica | 210626T181404Z | att |
| 063 | Zsh | 210626T085304Z | pxeger |
| 051 | Ruby | 210626T164052Z | G B |
| 007 | Jelly | 210626T100145Z | caird co |
| 091 | Red | 210626T075107Z | Razetime |
| 007 | Japt R | 210626T090343Z | Shaggy |
| 005 | 05AB1E legacy | 210626T090311Z | ovs |
| 004 | Vyxal | 210626T075951Z | lyxal |
| 006 | Charcoal | 210626T075317Z | Neil |
| 018 | APLDyalog Unicode | 210626T072914Z | AviFS |
| 066 | Python 2 | 210626T072853Z | dingledo |
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)]
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
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``)}
Takes one-indexed input.
J, 17 bytes
[:|.@|:' x'#~,.&1
+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
,.&1Zip 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 pairsx x x x x x x x[:|.@|:Rotate left:x x x x x xx x
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
Vyxal, 11 9 bytes
-2 bytes through auto-vectorizing
ð*×+ðÞṪṘ⁋
ð* # vectorised n spaces
×+ # append "*"
ðÞṪ # transpose with space as filler
Ṙ⁋ # reverse and join by newline
Wolfram Language (Mathematica), 44 bytes
Print@@@Table[" "Unitize[#+i],{i,-Max@#,0}]&
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
-3 thanks to JoKing, but still probably too long.
Explanation:
${${(On)@}[1]}: get the maximum inputs=${(l/*#/)}: construct a string of spaces which is (number of inputs) × (maximum of inputs) in lengthfor x;s[++i+$#s-#*x]=.: set the correct index of the string to a.for each elementfold -$#<<<$s: line-wrap the string at (number of inputs) in length
Jelly, 7 bytes
Ṭ€z0Ṛo⁶
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]]
-6 bytes from Galen Ivanov.
Japt -R, 7 bytes
1-indexed, using " for the peaks.
£QùXÃÕÔ
£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»
$ # 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§
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
Python 2, 66 bytes
a=input()
n=max(a)
while~n:print''.join(' x'[x==n]for x in a);n-=1