[Question]
  [
For golfing practice, I have been doing the assignments in my girlfriend's Intro to Python class. I found that for this assignment, there were multiple strategies that came very close in character count, and I'm sure people here can find even better ways. Although I am most interested in ways to do this in Python, I would like to know the most golfed this program can get, therefore this is code golf and shortest answer wins.
## The Rules:
The assignment is outlined below. The user should be asked to input twice, although the prompts don't have to say anything, and can be in a different order.
Standard loopholes apply.
---
### Assignment 3: Arrows
Write a program that prompts the user for a number of columns, and them prints the pattern as seen below. You can assume that the user will supply positive numbers. Your program should handle both left and right arrows. Here are a few sample runnings:
```
How many columns? 3
Direction? (l)eft or (r)ight: r
*
 *
  *
 *
*
How many columns? 5
Direction? (l)eft or (r)ight: l
    *
   *
  *
 *
*
 *
  *
   *
    *
```
  
[Answer]
# Pyth, 23 bytes
~~May or may not be valid, based on the answer to [this comment](https://codegolf.stackexchange.com/questions/59874/simple-printing-arrows#comment144045_59874). Regardless, I found this neat, and, if it is invalid, the other Pyth answers are also invalid. ;)~~ Well, [it's valid](https://codegolf.stackexchange.com/questions/59874/simple-printing-arrows?noredirect=1#comment144046_59874), because I apparently missed the blatantly obvious. :/
**EDIT:** I WON!!!! YESSS!!!! First time ever! :D
```
j+_J_Wqz\r.e+*dkb*\*QtJ
```
[Live demo.](https://pyth.herokuapp.com/?code=j%2B_J_Wqz%5Cr.e%2B%2adkb%2a%5C%2aQtJ&input=l%0A5&test_suite=1&test_suite_input=r%0A3%0Al%0A5&debug=1&input_size=2)
[Answer]
# Pyth, 27
```
j<tQ_Wqz\l++Jm+*\ d\*Q_PJtJ
```
[Try it online](http://pyth.herokuapp.com/?code=j%3CtQ_Wqz%5Cl%2B%2BJm%2B%2A%5C%20d%5C%2AQ_PJtJ&input=r%0A5&debug=0)
The basic idea here is to build one string that, for say 5, looks like this:
```
*
 *
  *
   *
    *
   *
  *
 *
*
 *
  *
   *
    *
```
And then flip it upside down if we get `l` as our input. Then we take all but the last `input-1` lines of this string and print it out.
[Answer]
# Python 2, ~~81~~ 79 bytes
```
c=input()
r=1
l=0
exec"print' '*(%sabs(c-r))+'*';r+=1;"%("c+~"*input())*(2*c-1)
```
Might still be golfable, but we'll see :)
[Answer]
# Pyth, ~~30~~ ~~28~~ 27 bytes
```
VtyQ+*+*tQJqz\r_WJ.a-hNQd\*
```
[Try it online.](https://pyth.herokuapp.com/?code=VtyQ%2B*%2B*tQJqz%5Cr_WJ.a-hNQd%5C*&input=r%0A3&debug=0)
Apparently I'm currently tied with [FryAmTheEggman](https://codegolf.stackexchange.com/a/59884/30164) with a completely different approach. (I think that one is ingenious.)
### Example
```
$ python pyth.py spa.p
r
3
*
 *
  *
 *
*
$ python pyth.py spa.p
l
5
    *
   *
  *
 *
*
 *
  *
   *
    *
```
### Explanation
```
 tyQ                              (columns * 2) - 1
V                               loop N through range(the above)
        tQ                                columns - 1 (maximum number of spaces)
       *                                multiplied by
           qz\r                           1 if direction == "r" else 0
          J                               also save that 1 or 0 to J
      +                               plus
                  .a-hNQ                    abs(N - columns + 1)
               _WJ                      negate that if direction == "r"
     *                  d           that many spaces
    +                    \*       add the star and print
```
[Answer]
# PowerShell, ~~91~~ ~~85~~ 102 Bytes
```
$c=(Read-Host)-1;if(!$c){"*";exit}(@(0..$c+($c-1)..0),@($c..0+1..$c))[(Read-Host)-eq'l']|%{" "*$_+"*"}
```
* Gets the columns, stores it in `$c`. We subtract one because each column also has an `*` and we're only interested in how many spaces are required.
* If the entered value was a `1`, print `*` and exit - rest of the script doesn't make a difference.+
* The next section first gets the direction and tests whether it's `-eq`ual to `l`, then creates an array based on indexing into an array of dynamically generated arrays based on the value of `$c`. Magic. Essentially, this is how many spaces per line we need.
* For example, for `5 r` this collection would hold `(0,1,2,3,4,3,2,1,0)`.
* Takes the array and pipes it into a Foreach-Object `%` loop, where we output a string of X number of spaces, then the `*`
### Example usage:
```
PS C:\Tools\Scripts\golfing> .\simple-printing-arrows.ps1
6
r
*
 *
  *
   *
    *
     *
    *
   *
  *
 *
*
```
Edit - removed variable `$e` by piping the collection directly  
Edit2 - correctly accounts for 1 column, now
+ If it's still mandatory to take input for direction for 1-column arrows (I contend it is not), we can swap the positioning of the `Read-Host` and lose a couple more bytes by re-introducing the `$d` variable, for **106**:
```
$c=(Read-Host)-1;$d=Read-Host;if(!$c){"*";exit}(@(0..$c+($c-1)..0),@($c..0+1..$c))[$d-eq'l']|%{" "*$_+"*"}
```
[Answer]
## TI-BASIC, ~~75~~ ~~65~~ ~~57~~ ~~54~~ ~~50~~ 47 Bytes
Thanks to @ThomasKwa for the correct byte calculation and golfing **10 bytes**.
Tested on my **TI-84+ Silver Edition.**
First TI-BASIC submission, golfing suggestions welcome (I don't know many tricks yet). If name plays a factor in memory shown, this one's was 3 characters instead of 1 (I looked at the byte count on my calculator itself). This program is limited by the `output` function's restrictions (I think to arrows of length 4), but I could probably switch to `text`, which displays graphically if that is too low of a length.
```
Prompt L,Str1
Str1="R
For(I,1,2L-1
Output(I,(1-2Ans)abs(I-L)+AnsL+1,"*
End
```
Note that this also doesn't clear the screen or pause it.
I really feel like the equation I'm using can be golfed more. It also feels so wrong to exclude the ending quotation mark.
[Answer]
# Python 2, 89 bytes
```
c=input()-1
d=raw_input()>'l'
for j in range(2*c+1):print' '*(d*c-(2*d-1)*abs(c-j))+'*'
```
Works almost identically to my Pyth answer, just calculating the correct number of spaces on the fly.
[Answer]
### PowerShell, 104 102 97 bytes
```
# 97 version:
$o=@(($c=(read-host)-1))[(read-host)-eq'l'];($j=2*$c)..0|%{' '*[Math]::Abs($o++%($j+!$j)-$c)+'*'}
3
r
*
 *
  *
 *
*
# Previous 102 version:
$o=@(($c=(read-host)-1))[(read-host)-eq'l'];(2*$c)..0|%{
' '*[Math]::Abs($o++%(2*($c+(!$c+0)))-$c)+'*'}
```
NB. if you want to run it again, open a new PowerShell, or `rv o` to reset the variable state.
Compared to how terse the others are, this hurts. [Hurts less at 97 than it did at 122]. Two parts to it, neither of them very surprising; reads a number of columns, uses an array-index-ternary-operator-substitute to get an offset, and runs through a [wave function](https://stackoverflow.com/questions/1073606/is-there-a-one-line-function-that-generates-a-triangle-wave) starting at the offset (and a tweak so it doesn't fall over doing `mod 0`).
(And ouch did I spend ages on that wave function, unable to spot my misunderstanding, and typing all the it's-not-LISP-,honest parens).
[Answer]
# Python 2, ~~98~~ 89 bytes
```
f=[' '*n+'*'for n in range(input())]
if'l'==input():f=f[::-1]
print'\n'.join(f+f[-2::-1])
```
A little more lengthy.
---
# Usage
```
$ python2 test.py
3
"l"
  *
 *
*
 *
  *
```
[Answer]
## Perl, 85 bytes
```
($-,$_)=<>;$,=$/;@}=map$"x$_.'*',0..--$-;@}=reverse@}if/l/;print@},map$}[$--$_],1..$-
```
Usage:
```
perl 59874.pl <<< '6
r'
```
[Answer]
# PHP, 156 Bytes
```
<?for($c=1+fgets(STDIN);--$c;$s[-$c]=$t[]=sprintf("%{$c}s","*"));arsort($s);$a=fgetc(STDIN)==r?$s+$t:$t+$s;array_splice($a,count($a)/2,1)?><?=join("
",$a);
```
Creates two arrays, like this:
```
$t = [
    0 => "  *"
    1 => " *"
    2 => "*"
]
$s = [
    -1 => "*"
    -2 => " *"
    -3 => "  *"
]
```
then uses array union `$s+$t` or `$t+$s` to combine them and `array_splice` to remove the element in the middle. Finally output using `<?=join()`
[Answer]
# Python 2, ~~111~~ ~~109~~ 104 bytes
Pretty simple solution. I'm sure it can be golfed more. For those who don't know, `~x+n` is the same as `n-1-x`.
```
n=input()
r=range(n)
r+=r[-2::-1]
for i in[r,[~x+n for x in r]]['r'>raw_input()]:print"*".rjust(i+1," ")
```
**[Try it online](http://ideone.com/bon4JR)**
**Edit**: This was golfed into the last line:
```
if'r'>d:r=[~x+n for x in r]
for i in r:print"*".rjust(i+1," ")
```
[Answer]
# Matlab, ~~109~~ ~~105~~ 96 bytes
*Thanks to @beaker for saving me 9 bytes*.
```
x=eye(input(''));if(input('','s')<114),x=fliplr(x);end
x=x*10+32;disp(char([x;x(end-1:-1:1,:)]))
```
[Answer]
# [Vyxal](https://github.com/Lyxal/Vyxal) `j`, 14 bytes
```
ƛ×⁰\l=[↲¹]↳;øm
```
[Try it Online!](http://lyxal.pythonanywhere.com?flags=j&code=%C6%9B%C3%97%E2%81%B0%5Cl%3D%5B%E2%86%B2%C2%B9%5D%E2%86%B3%3B%C3%B8m&inputs=5%0Al&header=&footer=)
[11 if 1/0 is allowed](http://lyxal.pythonanywhere.com?flags=j&code=%C6%9B%C3%97%E2%81%B0%5B%E2%86%B2%C2%B9%5D%E2%86%B3%3B%C3%B8m&inputs=5%0Al&header=&footer=)
```
ƛ          ;   # Map to...
 ×             # Asterisk
  ⁰\l=[  ]     # If left...
       ↲¹      # Left justify, then push size to right-just by
          ↳    # Right-justify
            øm # Palindromise
```
[Answer]
# Ruby, 118 bytes
```
2.times{l,d=gets.split;l=l.to_i;a=(d=="r"?(0..l-1):(l-1).downto(0)).to_a;(a+a[0..-2].reverse).each{|x| puts "#{' '*x}*"}}
```
`2.times{` -- twice, of course...
`l,d=gets.split;` -- get the input
`l=l.to_i;` -- change length to an integer
`a=(d=="r"?(0..l-1):(l-1).downto(0)).to_a;` -- create an array from the range of 0 to the length
`(a+a[0..-2].reverse).each{|x| puts "#{' '*x}*"}` -- iterate, turn into the strings to make the arrows
Not exactly the greatest golf ever, but, hey.
[Answer]
# PowerShell, ~~98~~ 94 Bytes
```
$c=(Read-Host)-1;$d=Read-Host;if($c){$c..0+1..$c|%{if($d-eq'r'){$_=$c-$_}' '*$_+'*'}}else{'*'}
```
If I could find a way to put the Read-Host for direction inside the foreach-object loop but only prompt for it once I might be able to save a few bytes.
Edit: 94 bytes. Instead of testing for left, test for right (simplifies the loop).
Original 98 byte:
```
$c=(Read-Host)-1;$d=Read-Host;if($c){0..$c+($c-1)..0|%{if($d-eq'l'){$_=$c-$_}' '*$_+'*'}}else{'*'}
```
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 15 bytes
```
=”ro⁹ạŒḄ}⁶ẋp”*Y
```
[Try it online!](https://tio.run/##ATwAw/9qZWxsef//PeKAnXJv4oG54bqhxZLhuIR94oG24bqLcOKAnSpZ/8OnImrigb7CtsK2//8icmwi/zMsIDU "Jelly – Try It Online")
If we can use any values instead of `l` and `r`, then [this](https://tio.run/##ATQAy/9qZWxsef//b@G6ocWS4biEfeKBtuG6i3DigJ0qWf/DpyJq4oG@wrbCtv//MSwgMP8zLCA1) **11** byte program works for `1` being to the right and `0` to the left.
If we can use any character rather than `*`, we can reduce the programs to **[14](https://tio.run/##ATkAxv9qZWxsef//PeKAnXJv4oG54bqhxZLhuIR94oG24bqLcDFZ/8OnImrigb7CtsK2//8icmwi/zMsIDU)** and **[10](https://tio.run/##ATEAzv9qZWxsef//b@G6ocWS4biEfeKBtuG6i3AxWf/DpyJq4oG@wrbCtv//MSwgMP8zLCA1)** bytes
## How it works
```
=”ro⁹ạŒḄ}⁶ẋp”*Y - Main link. Takes C on the left and n on the right
 ”r             - "r"
=               - Is C = "r"?
    ⁹           - Yield n
   o            - If C ≠ "r", yield n else 1
        }       - To n:
      ŒḄ        -   Bounce; Yield [1, 2, ..., n, ..., 2, 1]
     ạ          - Absolute difference
                  If C = "r", this yields [0, 1, ..., n-1, ..., 1, 0]
                  If C ≠ "r", this yields [n-1, n-2, ..., 0, ..., n-2, n-1]
                  Call the result B
         ⁶      - Yield a space
          ẋ     - For each element k in B, repeat a space k times
            ”*  - Yield "*"
           p    - Cartesian product; This appends "*" to each element in B
              Y - Join on newlines
```
[Answer]
# [><>](https://esolangs.org/wiki/Fish), 60 bytes
```
i"1l"i=&-:&*&:?!\:1-:}c0.
~/?:<-$?&::&;!?l<oao"*"
1/  \o" "-
```
2 wasted bytes on the bottom line, how irritating!
Due to how input works in ><>, it's not possible to 'wait' for input - the `i` command checks if an input character is available on STDIN. If there is, it pushes the ASCII value of that character, and pushes -1 if not.
This means that, in order to use this program, the number and direction must already be ready on STDIN, e.g. `3r` for a size 3 arrow pointing to the right. I'm not sure if that disqualifies this entry, let me know your thoughts :o)
I'll also write up a description if anyone wants one.
[Answer]
# PHP, 154 bytes
It looks really repetitive, but it does the desired:
```
$c=$argv[1];$b=l==$argv[2]?1:0;$a=$b?$c:-1;function a($a){echo strrev(str_pad('*',$a))."\n";}while($b?--$a:++$a<$c)a($a+1);while($b?++$a<=$c:1<$a--)a($a);
```
Runs from command line like:
```
php arrow.php 5 l
php arrow.php 5 r
```
[Answer]
# [Japt](https://github.com/ETHproductions/japt) [`-R`](https://codegolf.meta.stackexchange.com/a/14339/), 14 [bytes](https://en.wikipedia.org/wiki/ISO/IEC_8859-1)
Could save at least 3 bytes with looser I/O requirements.
```
õ@'*ùXÃê zVèÊÑ
```
[Try it](https://petershaggynoble.github.io/Japt-Interpreter/?v=1.4.6&flags=LVI&code=9UAnKvlYw%2bogelboytE&input=NQoibCI)
## 11 [bytes](https://en.wikipedia.org/wiki/ISO/IEC_8859-1)
Takes `0/1` as input for `r/l` and uses `1` instead of `*`
```
oç mÄ ê zVÑ
```
[Try it](https://petershaggynoble.github.io/Japt-Interpreter/?v=1.4.6&flags=LVI&code=b%2bcgbcQg6iB6VtE&input=NQox)
```
õ@'*ùXÃê zVèÊÑ     :Implicit input of integer U & string V
õ                  :Range [1,U]
 @                 :Map each X
  '*               :  Literal "*"
    ùX             :  Left pad with spaces to length X
      Ã            :End map
       ê           :Palindromise
         z         :Rotate clockwise 90° this many times ...
          Vè       :  Count the occurrences in U of
            Ê      :    "l"
             Ñ     :  Multiply by 2
                   :Implicit output joined with newlines
```
```
oç mÄ ê zVÑ     :Implicit input of integers U & V
o               :Range [0,U)
 ç              :For each, repeat space that many times
   m            :Map
    Ä           :  Append 1
      ê         :Palindromise
        zVÑ     :Rotate clockwise 90° V*2 times
                :Implicit output joined with newlines
```
]