Display a chain of little mountains with an odd number on the top of it!
05AB1E, 19 15 14 12 bytes
05AB1E uses CP-1252 encoding.
Saved 4 bytes thanks to Adnan.
Saved 2 bytes thanks to carusocomputing
ÅÉðìDg…/ \×»
Try it online!
Explanation
ÅÉ # list of uneven number up to input
ðì # prepend a space to each
Dg # get length of list
…/ \ # push the string "/ \"
× # repeat the string length-list times
» # join rows by spaces and columns by newlines
Pyke, 16 bytes
S2%idm+dJil*"/ \
Try it here!
17 bytes and more awesome
S2%i`~Bd.:il*"/ \
Try it here!
This uses IMHO an AWESOME algorithm for making sure the first line is correctly aligned.
S - range(1, input+1)
2% - ^[::2]
i - i = ^
` - str(^)
~Bd.: - ^.translate("><+-.,[]", " ") <-- awesome bit here
il - len(i)
*"/ \ - ^ * "/ \"
This replaces all the characters in the stringified list with spaces. ~B
contains all the characters in the Brain**** language and this is the first time I've used this variable.
The program `~Bd.:
does this:
`~Bd.: - input = [1, 3, 5, 7]
` - str(input) # stack now ["[1, 3, 5, 7]"]
~B - "><+-.,[]" # stack now ["[1, 3, 5, 7]", "><+-.,[]"]
d - " " # stack now ["[1, 3, 5, 7]", "><+-.,[]", " "]
.: - translate() # stack now [" 1 3 5 7 "]
Python 2 3, 67 65 63 60 Bytes
Nothing too crazy here, I think the first section can probably be done shorter but I'm not quite sure how. I use the fact that in this case -~n/2
will work for ceil
.
lambda n:-~n//2*' %d '%(*range(1,n+1,2),)+'\n'+-~n//2*'/ \\'
Below are alternative 61 and 65 byte solutions in Python 2:
lambda n:-~n/2*' %d '%tuple(range(1,n+1,2))+'\n'+-~n/2*'/ \\'
lambda n:' '+' '.join(map(str,range(1,n+1,2)))+'\n'+-~n/2*'/ \\'
Thanks to Rod for saving 2 bytes and Artyer for saving another byte by switching version :)