text:
Fill the Bucket
Your task is to fill the bucket with numbers upto a given input.
Rules
Numbers occupy the leftmost position then rightmost, then leftmost and so on.
After overflow, the numbers start to gather around the bucket in a similar manner. They occupy position diagonally.
The examples should make it clear what the expected output is (Some rules are mentioned in the examples).
For more then 10, use the rightmost digit
Examples:
The bucket:
|      |  or |      |
|      |     |      |
|      |     |      |
|      |     |      |
|------|     |______|

input:1  (You can start from either 0 or 1)
output:
|      |  (There can be whitespace to the left even if there is no overflow
|      |  but the bucket must not be distorted.)
|      |
|1     |
|------|

input:6
output:
|      |
|      |
|      |
|135642|
|------|

input:8
output:
|      |
|      |
|7    8|
|135642|
|------|

input:23
output:
|913 20|
|357864|
|791208|
|135642|
|------|

input:27
output:
  |913420|
  |357864|
  |791208|
  |135642|
75|------|6

input:30
output:
  |913420|
  |357864|
  |791208|
 9|135642|0
75|------|68

input:40
output:
    |913420|
    |357864|
   5|791208|6
 939|135642|040
7175|------|6828

input:54   (Maximum input for start=1)
    3|913420|4
   13|357864|42
  915|791208|620
 7939|135642|0408
57175|------|68286

This is code-golf so shortest code wins.

What do you exactly mean by "you can start from either 0 or 1"? May the sequence of digits itself be 0-indexed (i.e. |024531| for $n=6$) or only the input?

@Arnauld, yes, the sequence may start from 0

This is one of the better coding challenges for code golf that I have seen here!

JavaScript (Node.js),  145  143 bytes
A hard-coded pattern (see here for more maths).
1-indexed.
n=>`    g|EGIJHF|h
   e]|?ACDB@|^f
  c[U|9;=><:|V\\d
 aYSO|357864|PTZb
_WQMK|------|LNRX\``.replace(/[3-h]/g,c=>(x=Buffer(c)[0])<n+51?x%10:' ')

Try it online!
Saved 2 bytes thanks to @tsh

/[^\s|-]/ -> /[0-z]/

@tsh D'oh! I totally missed this simplification. Thank you!

JavaScript (ES6),  144 ... 139  137 bytes
A mathematical approach (see here for less maths).
0-indexed.
n=>(y=4,g=x=>~y?(X=x>8?17-x:x,k=X<y?g:X<5?24-(z=4+y-X)*~z+y*2:y*6+X*2-18,~X?X^5?k<0?'-':(k+=x>8)<n?k%10:' ':'|':`
`)+g(~X?-~x:!y--):'')()

Try it online!
How?
The output is built character by character, with \$y\$ decreasing from \$4\$ to \$0\$ and \$x\$ increasing from \$0\$ to \$18\$ on each row.
We define:
$$X=\begin{cases}x&\text{if }x\le 8\\17-x&\text{if }x>8\end{cases}$$
By writing the full values rather than just the unit digits, we get the following table:
 x |  0  1  2  3  4  5  6  7  8 |  9 10 11 12 13 14 15 16 17 18
 X |  0  1  2  3  4  5  6  7  8 |  8  7  6  5  4  3  2  1  0 -1
---+----------------------------+-------------------------------
 4 | .. .. .. .. 52 || 18 20 22 | 23 21 19 || 53 .. .. .. .. \n
 3 | .. .. .. 50 42 || 12 14 16 | 17 15 13 || 43 51 .. .. .. \n
 2 | .. .. 48 40 34 || 6  8  10 | 11 9  7  || 35 41 49 .. .. \n
 1 | .. 46 38 32 28 || 0  2  4  | 5  3  1  || 29 33 39 47 .. \n
 0 | 44 36 30 26 24 || -- -- -- | -- -- -- || 25 27 31 37 45 \n

This table is essentially symmetric across the y-axis, except that the values on the left side are even and the values on the right side are their odd counterparts.
We define:
$$k=\begin{cases}24+(4+y-X)(5+y-X)+2y&\text{if }X<5\\6y+2X-18&\text{if }X>5\end{cases}$$
$$k'=\begin{cases}k&\text{if }x\le 8\\k+1&\text{if }x>8\end{cases}$$
And for each cell, we append:

a linefeed if \$X=-1\$
a pipe if \$X=5\$
a hyphen if \$k<0\$
a space if \$X<y\$ or \$k'>n\$ (where \$n\$ is the input)
\$k' \bmod 10\$ otherwise

Commented
n => (                                // main function taking n
  y = 4,                              // start with y = 4
  g = x =>                            // g = recursive function taking x
    ~y ?                              // if y is not equal to -1:
      ( X = x > 8 ? 17 - x : x,       //   compute X
        k = X < y ?                   //   if X is less than y:
          g                           //     set k to a non-numeric value
        :                             //   else:
          X < 5 ?                     //     if X is less than 5:
            24 - (z = 4 + y - X) * ~z //       apply the 'side numbers' formula
             + y * 2                  //
          :                           //     else:
            y * 6 + X * 2 - 18,       //       apply the 'middle numbers' formula
        ~X ?                          //   if X is not equal to -1:
          X ^ 5 ?                     //     if X is not equal to 5:
            k < 0 ?                   //       if k is less than 0:
              '-'                     //         append a hyphen
            :                         //       else:
              (k += x > 8) < n ?      //         update k to k'; if it's less than n:
                k % 10                //           append the unit digit of k'
              :                       //         else:
                ' '                   //           append a space
          :                           //     else (X = 5):
            '|'                       //       append a pipe
        :                             //   else (X = -1):
          `\n`                        //     append a linefeed
      )                               //
      + g(~X ? -~x : !y--)            //   update x and y, and do a recursive call
    :                                 // else (y = -1):
      ''                              //   stop recursion
)()                                   // initial call to g with x undefined

Python 2, 170 bytes
I=input()
s="    u|SUWXVT|v\n   sk|MOQRPN|lt\n  qic|GIKLJH|djr\n oga]|ACEFDB|^bhp\nme_[Y|------|Z\`fn"
i=1
exec"s=s.replace(chr(64+i),[`i%10`,' '][i>I]);i+=1;"*55
print s

Try it online!

Java 10, 168 bytes
n->"    g|EGIJHF|h\n   e]|?ACDB@|^f\n  c[U|9;=><:|V\\d\n aYSO|357864|PTZb\n_WQMK|------|LNRX`".chars().forEach(c->System.out.print(c<46|c==124?(char)c:c<n+51?c%10:" "))

Port of @Arnauld's JavaScript answer (so also 1-indexed, and outputting - as bottom). If you like this answer, make sure to upvote him as well!
Try it online.
Explanation:
n->                      // Method with integer parameter and no return-type
  "    g|EGIJHF|h\n   e]|?ACDB@|^f\n  c[U|9;=><:|V\\d\n aYSO|357864|PTZb\n_WQMK|------|LNRX`"
                         //  String containing the bucket and magic string
   .chars().forEach(c->  //  Loop over the characters (as integers)
     System.out.print(   //   Print:
       c<46|c==124?      //    If the character is "\n", " ", "-", or "|":
        (char)c          //     Output the character as is
       :c<n+51?          //    Else-if the character value is smaller than the input + 51:
        c%10             //     Output a digit: the character value modulo-9
       :                 //    Else:
        " "))            //     Output a space

6502 machine code (C64), 130 bytes
00 C0 20 9B B7 A9 C0 65 65 85 FB A2 00 BD 2B C0 F0 1A 10 12 C5 FB 90 04 A9 20
D0 0A 69 70 C9 3A 90 04 E9 0A B0 F8 20 D2 FF E8 D0 E1 60 20 20 20 20 F5 7D D3
D5 D7 D8 D6 D4 7D F6 0D 20 20 20 F3 EB 7D CD CF D1 D2 D0 CE 7D EC F4 0D 20 20
F1 E9 E3 7D C7 C9 CB CC CA C8 7D E4 EA F2 0D 20 EF E7 E1 DD 7D C1 C3 C5 C6 C4
C2 7D DE E2 E8 F0 0D ED E5 DF DB D9 7D 2D 2D 2D 2D 2D 2D 7D DA DC E0 E6 EE 00

This uses a modified version of the "preformatted" approach of some other answers. It contains a full string of the bucket, but the digits are replaced by values starting from 0xC1, while any characters for direct printing are in the range 0x01-0x7f.
The C64 charset doesn't include a pipe (|) character, it's therefore replaced with the similar-looking PETSCII character 0x7d.
Online demo
Usage: SYS49152,[n] (1-indexed, e.g. SYS49152,54 for the full output)
Commented disassembly:
         00 C0       .WORD $C000        ; load address
.C:c000  20 9B B7    JSR $B79B          ; get unsigned byte from commandline
.C:c003  A9 C0       LDA #$C0           ; add #$C0 (+ carry = #$C1) ...
.C:c005  65 65       ADC $65            ; ... to parameter
.C:c007  85 FB       STA $FB            ; and store in $FB
.C:c009  A2 00       LDX #$00           ; loop index
.C:c00b   .loop:
.C:c00b  BD 2B C0    LDA .bucket,X      ; loop over encoded string
.C:c00e  F0 1A       BEQ .done          ; null-terminator -> done
.C:c010  10 12       BPL .out           ; positive (bit 7 clear) -> output
.C:c012  C5 FB       CMP $FB            ; compare with parameter+#$C1
.C:c014  90 04       BCC .digit         ; smaller -> convert to digit
.C:c016  A9 20       LDA #$20           ; otherwise load space character
.C:c018  D0 0A       BNE .out           ; and output
.C:c01a   .digit:
.C:c01a  69 70       ADC #$70           ; add offset to '0' (#$30)
.C:c01c   .check:
.C:c01c  C9 3A       CMP #$3A           ; greater than '9' (#$39) ?
.C:c01e  90 04       BCC .out           ; no -> to output
.C:c020  E9 0A       SBC #$0A           ; otherwise subtract 10 (#$a)
.C:c022  B0 F8       BCS .check         ; and check again
.C:c024   .out:
.C:c024  20 D2 FF    JSR $FFD2          ; output character
.C:c027  E8          INX                ; next index
.C:c028  D0 E1       BNE .loop          ; and repeat loop
.C:c02a   .done:
.C:c02a  60          RTS                ; exit ....
.C:c02b   .bucket:
.C:c02b  20 20 20    [...]              ; "encoded" string for bucket

Charcoal, 64 bytes
Ｎθ³↑⁵‖Ｍ←Ｆ²«‖Ｊ⁻³ι±¹Ｆ⊘⁺θ¬ι«↖Ｉ﹪⁺⊗κ⊕ιχＭ§”)⊟E≡≦⌈▷⊖ü∕”κ§”)⊟＆hXτtD(λＭ”κ

Try it online! Link is to verbose version of code. Explanation:
Ｎθ

Input the number.
³↑⁵‖Ｍ←

Draw half of the bucket and then mirror it to complete the bucket.
Ｆ²«

Loop for each side of the bucket.
‖Ｊ⁻³ι±¹

Reflect the bucket so that we can draw in a consistent direction on both loops, and jump to the position of the first digit on that side of the bucket.
Ｆ⊘⁺θ¬ι«

Loop over the number of digits on that side of the bucket.
↖Ｉ﹪⁺⊗κ⊕ιχ

Print the next digit and move the cursor up and left.
Ｍ§”)⊟E≡≦⌈▷⊖ü∕”κ§”)⊟＆hXτtD(λＭ”κ

Adjust the cursor position by reading the offsets from two compressed strings, 003003003005203004000500 (horizontal offsets) and 11011011011510200300040000 (vertical offsets). These offsets take the above cursor movement into account which conveniently means that they never have to be negative.


text:
Code Golf: Letter-Ception
The Challenge:
For an input of one letter X (upper or lower case from A to Z) and one digit N (0-9) print the corresponding letter X made of N * X.
The letter has to be from this list:
 AAA      BBBB       CCCC     DDDD      EEEEE     FFFFF      GGG      H   H
A   A     B   B     C         D   D     E         F         G         H   H
AAAAA     BBBB      C         D   D     EEEE      FFFF      G  GG     HHHHH
A   A     B   B     C         D   D     E         F         G   G     H   H
A   A     BBBB       CCCC     DDDD      EEEEE     F          GGG      H   H

IIIII         J     K   K     L         M   M     N   N      OOO
  I           J     K  K      L         MM MM     NN  N     O   O
  I           J     KKK       L         M M M     N N N     O   O
  I       J   J     K  K      L         M   M     N  NN     O   O
IIIII      JJJ      K   K     LLLLL     M   M     N   N      OOO

PPPP       QQQ      RRRR       SSSS     TTTTT     U   U     V   V     W   W
P   P     Q   Q     R   R     S           T       U   U     V   V     W   W
PPPP      Q   Q     RRRR       SSS        T       U   U     V   V     W   W
P         Q  QQ     R  R          S       T       U   U      V V      W W W
P          QQQQ     R   R     SSSS        T        UUU        V        W W

X   X     Y   Y     ZZZZZ
 X X       Y Y         Z
  X         Y         Z
 X X        Y        Z
X   X       Y       ZZZZZ

Examples:
input: a 1
output:
 AAA
A   A
AAAAA
A   A
A   A

input: A 0
output: A

input: A 2
output:
      AAA  AAA  AAA
     A   AA   AA   A
     AAAAAAAAAAAAAAA
     A   AA   AA   A
     A   AA   AA   A
 AAA                 AAA
A   A               A   A
AAAAA               AAAAA
A   A               A   A
A   A               A   A
 AAA  AAA  AAA  AAA  AAA
A   AA   AA   AA   AA   A
AAAAAAAAAAAAAAAAAAAAAAAAA
A   AA   AA   AA   AA   A
A   AA   AA   AA   AA   A
 AAA                 AAA
A   A               A   A
AAAAA               AAAAA
A   A               A   A
A   A               A   A
 AAA                 AAA
A   A               A   A
AAAAA               AAAAA
A   A               A   A
A   A               A   A

input: A -1
output: what ever: it doesn't matter

Additional Rules:

The input parameters can be separated by what ever character you
   want.
Each letter must use the capital of itself as the ascii-character to draw it.
Trailing spaces, new lines etc. are allowed
Instead of a program, you may write a function that takes the digit string as an argument. The output should be printed normally.
Stdout / Stderr doesn't matter, just pick one. If stuff gots printed on the other doesn't matter either.
Possible output formats can be printed to STDOUT, returned as a list of strings, returned as a character matrix, etc. as long as the result can simply be printed using the languages default print method.*

*: like the function f(a,1) returns the string and one can simply say print(f(a,1)) dont make the print() call part of the answer. (This was pointed out by Kevin Cruijssen and  Arnauld).
Winning:
This is code-golf, lowest byte-count wins. Have fun!

Edit: this question seems very identical to this however I would say it is not, as it should not only work for H but for each letter from the alphabet.. Guess you decide rather or not it is a duplicate.

Does output have to be printed or can it be a return value like a string array?

@TheLethalCoder does it make sense if I say as long as it is properly formatted its OK ?

Very closely related.

@AdmBorkBork you are right, I didn't see that, should I delete it ?

You'd need to define what properly formatted means, just having all the spaces and new lines in the array, a 2d array with spaces in cells etc. Also your A 2 example has leading spaces, is that intentional?

@TheLethalCoder Just having all the spaces and new lines is enough and the leading spaces are not intentional, I will go fix this.

I don't think they are duplicates -- needing to account for a different letter each run and your letters are different than the H from the linked question -- but they are close enough that I wanted to call it out as it's likely there can be some code or algorithm re-use between the two.

Closely related, related, related, related. PS: @NicolasBrauer related means it can contain tips/similarities on how to do this challenge, it's not necessarily a duplicate. Although the first one is pretty similar for the letter H. Oh, and since no one said it yet: welcome to PPCG!

@KevinCruijssen thank you very much for the explanation and the welcome :D

Also related. Possibly the closest existing question.

Also somewhat related. Welcome to PPCG; nice first challenge. A couple more test cases using different letters wouldn't hurt, though. I'd also suggest against requiring us to handle the special case of N=0 - it doesn't (seem to me) to add anything to the challenge.

@Shaggy thank you :) So you suggest making the output for all N<=0 to what ever: it doesn't matter  ?

Welcome to PPCG. It's always good to see someone actually respond to questions that are asked about their challenge and take hints on board. Respect. You may want to try the sandbox next time (just in case you didn't know about it).

@ElPedro Thank you! I did not know about the sandbox yet, thank you very much I will take a closer look at it!

Nice first challenge! However, your question currently suggests that we may only print the result. The default rule is that functions are allowed to just return it. Generally speaking, I/O formats are very flexible. You may want to have a look at this post in meta which explains why.

@Arnauld as it is about ASCII art I would say to print the result is somewhat crucial to the task, but I guess if your code returns the result and the returned string could simply be printed using the languages default print method (like your function f(a,1) return the string and I can just say print(f(a,1)) the print() call has not to be part of the answer code. If this is somewhat understandable and you agree I may add this to the challenge description.

@NicolasBrauer That's indeed how it's usually done. For this challenge for example, some possible output formats could be indeed printed to STDOUT, returned as a list of strings, returned as a character matrix, etc. In the footer of [Try it online]-links we can add the print, since that part could be pretty verbose and doesn't add much to the challenge itself (which is also why functions are allowed instead of full programs, since in some languages (i.e. Java), a function can be halve the byte-count of a full program, and does exactly the same.

@KevinCruijssen I slightly updated the question, please tell me if its understandable the way I wrote it :)

R, 259 bytes
function(K,N,`!`=utf8ToInt){if(N)for(i in 1:N)T=T%x%(sapply(!"

",intToBits)[1:5,5*(-64+!K)-4:0]>0)
write(c(" ",K)[T+1],1,5^N,,"")}

Try it online!

Disclaimer :
this solution has been obtained by taking @Giuseppe's answer and replacing the matrix compression with another approach very very similar to the one used in @Arnauld's answer, so first of all go upvote them :)

The idea is the following :
Given this 5 x 26*5 matrix of 0/1 :
(1 replaced by '#', 0 replaced by '.' and '|' added for readability)

.####|#####|.###.|#####|#####|#####|.###.|#####|#...#|...#.|#####|#####|#####|
#.#..|#.#.#|#...#|#...#|#.#.#|#.#..|#...#|..#..|#...#|....#|..#..|....#|.#...|
#.#..|#.#.#|#...#|#...#|#.#.#|#.#..|#...#|..#..|#####|....#|..#..|....#|..#..|
#.#..|#.#.#|#...#|#...#|#.#.#|#.#..|#.#.#|..#..|#...#|....#|.#.#.|....#|.#...|
.####|.#.#.|#...#|.###.|#...#|#....|..##.|#####|#...#|####.|#...#|....#|#####| ...
  ^     ^     ^     ^     ^     ^     ^     ^     ^     ^     ^     ^     ^
  |     |     |     |     |     |     |     |     |     |     |     |     |
  A     B     C     D     E     F     G     H     I     J     K     L     M

each column is considered as binary number and converted to an integer. These integer are then converted to unprintable ASCII in the range 1...31 :
e.g. for the columns of "B" the final string will be "\017\021\017\021\017" (unprintable chars written in octal representation):
#####                   ####.     11110          15            '\017'
#.#.#                   #...#     10001          17            '\021'
#.#.#      ------->     ####. --> 11110  ------> 15   ------>  '\017'
#.#.#                   #...#     10001          17            '\021'
.#.#.                   ####.     11110          15            '\017'

          (transposed                  bin to int   int to ASCII
         for reability)

Hence, given the final string of 5*26 = 130 characters, we convert that string back to the matrix of 0/1 using :
sapply(utf8ToInt(STRING),intToBits)

then we simply subsect the matrix selecting only the first 5 rows (intToBits returns 32 bits) and only the columns corresponding to the letter passed as input and finally we apply kronecker as explained in @Giuseppe's answer.

you can also use unprintables to shave off the -48 piece, and use ! in place of U: try it online

@Giuseppe : great ! I made the answer a community wiki since it's the result of a collaboration :) Feel free to edit my poor english :D

I just noticed that this one is the answer with the lowest byte-count, so let me make this the accepted and thus winning answer

JavaScript (ES8), 281 bytes
Takes input as (letter)(N). Returns a string.
c=>n=>(g=y=>y--?''.padEnd(w).replace(/./g,(_,x)=>(h=d=>~~(d/=5)?(P=parseInt)('hhvhefhfhfu111ufhhhfv1f1v11f1vehp1ehhvhhv444vehgggh979hv1111hhlrhhpljhehhhe11fhfuphheh9fhffge1u4444vehhhh4ahhhalhhhha4ah444ahv248v'[y/d%5+5*P(c,36)-50|0],36)>>x/d%5&1?h(d):' ':c)(w))+`
`+g(y):'')(w=5**n)

Try it online!
How?
Font encoding
The letters are \$5\times5\$, which means that each row can be encoded as a 5-digit binary value, i.e. \$0\$ to \$31\$ in decimal. These values can conveniently be stored as a single digit in Base36.
The pattern that is stored is mirrored both horizontally and vertically.
Example for 'F':
#####     ....#     00001      1     '1'
#....     ....#     00001      1     '1'
####. --> .#### --> 01111 --> 15 --> 'f' --> '11f1v'
#....     ....#     00001      1     '1'
#....     #####     11111     31     'v'

The whole font is stored as a single string of \$26\times5 = 130\$ characters.
To test the 'pixel' at \$(x,y)\$ for the \$n^{\text{th}}\$ letter, we do:
parseInt('hhvhefhfh...'[y + 5 * n], 36) >> x & 1

Main algorithm
Given \$n\$, we define \$w=5^n\$, which is the width of the final output.
For \$0\le x<w\$ and \$0\le y<w\$, we want to know if the output pixel at \$(x,y)\$ is set or not. We use the recursive function \$h\$, which tests the letter pixel located at:
$$\left(\left\lfloor\frac{x}{5^k}\right\rfloor\bmod 5,\left\lfloor\frac{y}{5^k}\right\rfloor\bmod 5\right)$$
for all \$k\$ in \$[0 \dots n-1]\$.
The function returns a space as soon as a blank pixel is detected at some depth, or the character corresponding to the input letter if all iterations are successful.

It works really good, congratulations! Can you try to explain the code a bit please ?

Why has the pattern that is stored to be mirrored both horizontally and vertically? would it take more bytes to not mirror it at all for storing ? And tyvm for the explanation *.*

@NicolasBrauer It's mirrored vertically because $y$ is decreasing from $w-1$ to $0$. And it's mirrored horizontally because the leftmost 'pixel' is mapped to the least significant bit (i.e. on the right of the number it's mapped to). The decoding would be a bit longer if it was not mirrored at all.

(Although I think we could drop the vertical mirror at no cost.)

R, 348 bytes
function(K,N){if(N)for(i in 1:N)T=T%x%matrix(c(15269425,32045630,16269839,32032318,33061407,33061392,15224366,18415153,32641183,1082926,18444881,17318431,18732593,18667121,15255086,32045584,15255151,32045649,16267326,32641156,18400814,18400580,18400938,18157905,18157700,32575775)[utf8ToInt(K)-64]%/%2^(24:0)%%2,5,5)
write(c(" ",K)[T+1],1,5^N,,"")}

Try it online!
Uses an encoding nearly identical to Ouros'; however, it does not reverse the bits, instead opting to use them directly.
It then creates a 5x5 matrix of bits and builds the Kronecker Power matrix to generate the necessary pattern, writing the results to stdout.

This is a great use of Kronecker !

272 using another compression method

@digEmAll the heart of this challenge is the compression method (from a code-golf perspective anyway). Why don't you post it as an answer so you can explain it, too?

Clean, 436 372 bytes
Significantly shorter with new IO format.
import StdEnv,StdLib
t=transpose
f=flatten
$0c=[[c]]
$n c=f[t(f[t($(n-1)if(isOdd({#18415150,16301615,31491134,16303663,32554047,1096767,15262766,18415153,32641183,15254032,18128177,32539681,18405233,18667121,15255086,1097263,32294446,18136623,16267326,4329631,15255089,4539953,11191857,18157905,4329809,32575775}.[toInt(max'A'c)-65]>>p))c' ')\\p<-[i..i+4]])\\i<-[0,5..20]]

Try it online!
Compresses the letter patterns into the bits of integer literals to save ~700 bytes. For example, A:

Flatten [[' AAA '],['A   A'],['AAAAA'],['A   A'],['A   A']]
Reverse [' AAA A   AAAAAAA   AA   A']
Turn ['A   AA   AAAAAAA   A AAA '] into binary ('A' = 1, ' ' = 0)
Turn 0b1000110001111111000101110 into decimal
Get 18415150

source: Stack Exchange

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/

sort: votes


text:
Optimal Alphabet Stepping
Given an input string consisting of only letters, return the step-size that results in the minimum amount of steps that are needed to visit all the letters in order over a wrapping alphabet, starting at any letter.
For example, take the word, dog. If we use a step-size of 1, we end up with:
defghijklmnopqrstuvwxyzabcdefg   Alphabet
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
defghijklmnopqrstuvwxyzabcdefg   Visited letters
d          o                 g   Needed letters

For a total of 30 steps.
However, if we use a step-size of 11, we get:
defghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefg
^          ^          ^          ^          ^          ^
d          o          z          k          v          g   Visited letters
d          o                                           g   Needed letters

For a total of 6 steps. This is the minimum amount of steps, so the return result for dog is the step-size; 11.
Test cases:
"dog"      -> 11
"age"      -> 6
"apple"    -> 19
"alphabet" -> 9
"aaaaaaa"  -> 0 for 0 indexed, 26 for 1 indexed
"abcdefga" -> 1 or 9
"aba"      -> Any odd number except for 13
"ppcg"     -> 15
"codegolf" -> 15
"testcase" -> 9
"z"        -> Any number
"joking"   -> 19

Rules

Input will be a non-empty string or array of characters consisting only of the letters a to z (you can choose between uppercase or lowercase)
Output can be 0 indexed (i.e. the range 0-25) or 1 indexed (1-26)
If there's a tie, you can output any step-size or all of them
This is code-golf, so the lowest amount of bytes for each language wins!

Do we need to handle empty input?

@pizzapants184 No. I've updated the question to specify the input will be non-empty

Can we take input as an array of characters?

@Shaggy Sure you can

Is there a reason this uses letters instead of numbers?

Charcoal, 41 bytes
≔ＥＥβＥθ∧μ⌕⭆β§β⁺⌕β§θ⊖μ×κξλ⎇⊕⌊ιΣι⌊ιθＩ⌕θ⌊Φθ⊕ι

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

Loop over the 26 step sizes. (Actually I loop over the lowercase alphabet here and use the index variable.)
Ｅθ∧μ

Loop over each character of the input after the first.
⭆β§β⁺⌕β§θ⊖μ×κξ

Loop 26 times and generate the string of characters resulting by taking 26 steps at the given step size starting (0-indexed) with the previous character of the input.
⌕...λ

Find the position of the current character of the input in that string, or -1 if not found.
Ｅ...⎇⊕⌊ιΣι⌊ι

Take the sum of all the positions, unless one was not found, in which case use -1.
≔...θ

Save the sums.
⌊Φθ⊕ι

Find the minimum non-negative sum.
Ｉ⌕θ...

Find the first step size with that sum and output it.

JavaScript, 143 bytes
w=>(a=[...Array(26).keys(m=1/0)]).map(s=>~[...w].map(c=>(t+=a.find(v=>!p|(u(c,36)+~v*s-u(p,36))%26==0),p=c),p=t=0,u=parseInt)+t<m&&(m=t,n=s))|n

Try it online!
Thanks to Shaggy, using [...Array(26).keys()] saves 9 bytes.

144 bytes

Ruby, 121 114 112 108 102 89 bytes
->s{(r=0..25).min_by{|l|p,=s;s.sum{|c|t=r.find{|i|(p.ord-c.ord+i*l)%26<1}||1/0.0;p=c;t}}}

Try it online!
0-indexed. Takes input as an array of characters.
Thanks to ASCII-only for golfing ideas worth 12 bytes.

:( close (based off python solution)

100, probably can be golfed quite a bit more

91

Great idea, -1 more byte by p,=*s trick, but I'm not so sure about theoretical robustness of a solution with a hardcoded penalty score... So, I changed the constant to infinity (although your value would allow for another 2 bytes off).

Only 2 bytes, not bad

also hmm. that p=c;t is ugly but haven't yet found a shorter alternative

but... yeah, it'd only work for strings up to length 9e9/26 which is within the limits of today's computers (<1 GB). 9e99 should work for a while (4e98 bytes should be well outside the reach of our storage for a long time, but I guess it depends on whether we need theoretical robustness)

oh btw. *s -> s

also 89

JavaScript (Node.js),  123 121 116  114 bytes
s=>(i=26,F=m=>i--?F((g=x=>s[p]?s[k++>>5]?j=1+g(x+i,p+=b[p]==x%26+97):m:0)(b[p=k=0]+7)>m?m:(r=i,j)):r)(b=Buffer(s))

Try it online!
Commented
NB: When trying to match a letter in the alphabet with a given step \$i\$, we need to advance the pointer at most \$25\$ times. After \$26\$ unsuccessful iterations, at least one letter must have been visited twice. So, the sequence is going to repeat forever and the letter we're looking for is not part of it. This is why we do s[k++ >> 5] in the recursive function \$g\$, so that it gives up after \$32 \times L\$ iterations, where \$L\$ is the length of the input string.
s => (                        // main function taking the string s
  i = 26,                     // i = current step, initialized to 26
  F = m =>                    // F = recursive function taking the current minimum m
    i-- ?                     // decrement i; if i was not equal to 0:
      F(                      //   do a recursive call to F:
        (g = x =>             //     g = recursive function taking a character ID x
          s[p] ?              //       if there's still at least one letter to match:
            s[k++ >> 5] ?     //         if we've done less than 32 * s.length iterations:
              j = 1 + g(      //           add 1 to the final result and add the result of
                x + i,        //             a recursive call to g with x = x + i
                p += b[p] ==  //             increment p if
                  x % 26 + 97 //             the current letter is matching
              )               //           end of recursive call to g
            :                 //         else (we've done too many iterations):
              m               //           stop recursion and yield the current minimum
          :                   //       else (all letters have been matched):
            0                 //         stop recursion and yield 0
        )(                    //     initial call to g with p = k = 0
          b[p = k = 0] + 7    //     and x = ID of 1st letter
        ) > m ?               //     if the result is not better than the current minimum:
          m                   //       leave m unchanged
        :                     //     else:
          (r = i, j)          //       update m to j and r to i
      )                       //   end of recursive call to F
    :                         // else (i = 0):
      r                       //   stop recursion and return the final result r
)(b = Buffer(s))              // initial call to F with m = b = list of ASCII codes of s

Shorter to detect 32*L or longer than record?

Jelly, 28 26 23 bytes
S;þḅ26ŒpṢƑƇIŻ€S:g/ƊÞḢg/

Output is 0-indexed. Input is a bytestring and can be in any case, but uppercase is much faster.
Single-letter input has to be special-cased and costs 2 bytes. ._.
Try it online!
Note that this is a brute-force approach; inputs with four or more letters will time out on TIO. The test suite prepends _39  for "efficiency".
How it works
S;þḅ26ŒpṢƑƇIŻ€S:g/ƊÞḢg/  Main link. Argument: b (bytestring)

S                        Take the sum (s) of the code points in b.
 ;þ                      Concatenate table; for each k in [1, ..., s] and each c in
                         b, yield [k, c], grouping by c.
   ḅ26                   Unbase 26; map [k, c] to (26k + c).
      Œp                 Take the Cartesian product.
        ṢƑƇ              Comb by fixed sort; keep only increasing lists.
           I             Increments; take the forward differences of each list.
            Ż€           Prepend a 0 to each list.
                         I returns empty lists for single-letter input, so this is
                         required to keep g/ (reduce by GCD) from crashing.
                   Þ     Sort the lists by the link to the left.
              S:g/Ɗ      Divide the sum by the GCD.
                    Ḣ    Head; extract the first, smallest element.
                     g/  Compute the GCD.

Jelly, 17 bytes
ƓI%
26×þ%iþÇo!SỤḢ

Input is a bytestring on STDIN, output is 1-indexed.
Try it online!
How it works
ƓI%            Helper link. Argument: m (26 when called)

Ɠ              Read a line from STDIN and eval it as Python code.
 I             Increments; take all forward differences.
  %            Take the differences modulo m.

26×þ%iþÇoSSỤḢ  Main link. No arguments.

26             Set the argument and the return value to 26.
  ×þ           Create the multiplication table of [1, ..., 26] by [1, ..., 26].
    %          Take all products modulo 26.
       Ç       Call the helper link with argument 26.
     iþ        Find the index of each integer to the right in each list to the left,
               grouping by the lists.
        o!     Replace zero indices (element not found) with 26!.
               This works for strings up to 25! = 15511210043330985984000000 chars,
               which exceeds Python's 9223372036854775807 character limit on x64.
          S    Take the sum of each column.
           Ụ   Sort the indices by their corresponding values.
            Ḣ  Head; extract the first index, which corresponds to the minimal value.

Python 2, 230 222 216 194 169 bytes
def t(s,l,S=0):
 a=ord(s[0])
 for c in s[1:]:
	while a-ord(c)and S<len(s)*26:S+=1;a=(a-65+l)%26+65
 return S
def f(s):T=[t(s,l)for l in range(26)];return T.index(min(T))

Try it online!
-22 bytes from tsh
-39 bytes from Jo King
Older version with explanation:
A=map(chr,range(65,91)).index
def t(s,l,S=0):
 a=A(s[0])
 for c in s[1:]:
	while a!=A(c)and S<len(s)*26:
	 S+=1;a+=l;a%=26
 return S
def f(s):T=[t(s,l)for l in range(26)];return T.index(min(T))

Try it online!
This would be shorter in a language with a prime number of letters (wouldn't need the float('inf') handling of infinite loops). Actually, this submission would still need that for handling strings like "aaa". This submission now uses 26*len(s) as an upper bound, which stops infinite loops.
This submission is 0-indexed (returns values from 0 to 25 inclusive).
f takes a(n uppercase) string and returns the Optimal Alphabet Stepping
t is a helper function that takes the string and an alphabet stepping and returns the number of hops needed to finish the string (or 26*len(s) if impossible).

Use while a!=A(c)and S<len(s)*26: and you may remove if a==i:return float('inf'), since len(s)*26 is upper bound of any answer.

165

alternative method, 166

155

143

139, same golf can be applied to previous version (removing brackets in min call)

123

as a bonus, can now take input from any range of 26 or less chars

lambda, 114

112

change to 9e9 to 9e99 for more robustness if you want

Red, 197 bytes
func[s][a: collect[repeat n 26[keep #"`"+ n]]m: p: 99 a: append/dup a a m
u: find a s/1 repeat n 26[v: extract u n
d: 0 foreach c s[until[(v/(d: d + 1) = c)or(d > length? v)]]if d < m[m: d p: n]]p]

Try it online!

Python 3, 191 178 162 bytes
Thanks everyone for all your tips! this is looking much more golflike.
*w,=map(ord,input())
a=[]
for i in range(26):
 n=1;p=w[0]
 for c in w:
  while n<len(w)*26and p!=c:
   n+=1;p+=i;
   if p>122:p-=26
 a+=[n]
print(a.index(min(a)))

Try it online!
And my original code if anyone's interested.
Turns the word into a list of ASCII values, then iterates through step sizes 0 to 25, checking how many steps it takes to exhaust the list (there's a ceiling to stop infinite loops).
Number of steps is added to the list a.
After the big for loop, the index of the smallest value in a is printed. This is equal to the value of i (the step size) for that iteration of the loop, QED.

Hi & Welcome to PPCG! For starters, your posted byte count doesn't match that on TIO :) Now, for a couple of quick hints: range(26) is enough - you don't need to specify the start, since 0 is the default; a.append(n) could be a+=[n]; the first line would be shorter as map w=list(map(ord,input())), (actually with your current algorithm, in Py2 you could drop list(...) wrapping as well); avoid extra spacing/line breaks as much as possible (e.g., no need for newlines in oneliners: if p>122:p-=26)

Also, that n>99 look suspicious, is that an arbitrary constant to break out of inifinite loop? Then it probably should be something like 26*len(w), as you never know, how large the input will be.

@KirillL.Yeah that n>99 was a bit shifty so I changed it. Would you believe I spent a good while looking for a way to do if statements in one line like that and came up empty handed? I guess my googling skills aren't great. Thanks for all the advice!

BTW, you can still get rid of that list(...) in Py3 and also of one extra if: 165 bytes. Also, take a look at this tips topic, I'm sure you'll greatly improve your skills using advices from there!

I'm not a python expert, but I think you can do while p!=c and n>len(w)*26: and get rid of that last if statement for -8 bytes.

Although it looks terrible and goes against everything Python is, you can change n+=1 and p+=i on seperate lines to n+=1;p+=i on one.

05AB1E (legacy), 33 27 26 bytes
Ç¥ε₂%U₂L<©ε®*₂%Xk'-žm:]øOWk

Uses the legacy version because there seems to be a bug when you want to modify/use the result after a nested map in the new 05AB1E version..
0-indexed output.
Try it online or verify all test cases.
Explanation:
Ç                        # ASCII values of the (implicit) input
 ¥                       # Deltas (differences between each pair)
  ε                      # Map each delta to:
   ₂%                    #  Take modulo-26 of the delta
     U                   #  Pop and store it in variable `X`
      ₂L<                #  Push a list in the range [0,25]
         ©               #  Store it in the register (without popping)
          ε              #  Map each `y` to:
           ®*            #   Multiply each `y` by the list [0,25] of the register
             ₂%          #   And take modulo-26
                         #   (We now have a list of size 26 in steps of `y` modulo-26)
               Xk        #   Get the index of `X` in this inner list (-1 if not found)
                 '-₄:   '#   Replace the minus sign with "1000"
                         #   (so -1 becomes 10001; others remain unchanged)
]                        # Close both maps
 ø                       # Zip; swapping rows/columns
  O                      # Sum each
   W                     # Get the smallest one (without popping the list)
    k                    # Get the index of this smallest value in the list
                         # (and output the result implicitly)

JavaScript (Node.js), 85 bytes
s=>(b=Buffer(s),g=i=>s[g[j=i%26]=g[j]+!((b[0]-b[g[j]]+~~(i++/26)*j)%26)||1]?g(i):j)``

Try it online!
Branch First Search, needn't handle infinite loop
JavaScript (Node.js), 83 bytes
s=>(b=Buffer(s),g=i=>s[g[j=i%26]=g[j]+!((b[0]-b[g[j]]-~(i++/26)*j)%26)|0]?g(i):j)``

Try it online!
Assumes even is always better than odd if possible, 13 is always better than other if possible, which seems correct
JavaScript (Node.js), 82 bytes
s=>(g=i=>s[g[j=i%26]=g[j]+!((b[0]-b[g[j]]-~(i/26)*j)%26)|0]?g(-~i):j)(b=Buffer(s))

Try it online!
Less confident about correctness

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/


text:
Round the digits last digit, over and over
Challenge:
Given two inputs, x and y, round x to one less significant figure, then repeat until it has y number of unrounded digits left. (the decimal point does not count as a digit)
Input & Output
Input can be a combination of strings and integers, e.g. you can have the input as a string and the output as an int, or vice versa.
The input number will never have 15 digits total, and the y will never be greater  than the input number's length and will always be greater than 0.
Example:
x = 32.64712, y = 3
    32.64712 -> 32.6471 -> 32.647 -> 32.65 -> 32.7  (Three unrounded digits left)

x = 87525, y = 2
    87525 -> 87530 -> 87500 -> 88000 (Two unrounded digits left)

x = 454, y = 3
    454 -> 454 (Three unrounded digits left)

(steps shown just to clarify, you only need to output the last value.)
Rules

Trailing 0's are allowed
5's round up
Standard loopholes apply

This is code-golf, so you should strive for the shortest answer.

I take it numbers ending in 5 round up? If we get a result like 3.100, do we have to output the number with trailing zeroes?

The phrase "round x's second to last digit" seems ambiguous and I'd interpret it differently from what the challenge intends. I'd call it "round away x's last digit" or "round x to one less significant figure". Also, the input refers to integers, but the numbers can be non-whole reals.

@xnor Numbers ending in 5 do round up, trailing zeros are ok

Ugh, JavaScript rounds 32.647 to 32.64999999999999857891 which is still less than 32.65 ;-(

For javascript, you can scale the number up so that there are no digits right of the decimal point, then divide it down after scaling(since integer math is exact)

Python 2, 101 97 92 91 85 bytes
lambda x,y:reduce((lambda n,l:int(n/.1**l+.5)*.1**l),range(15,y+~len(`int(x)`),-1),x)

Try it online!

Alternative :
If Python's round would round "half up" instead of "half to even":
Python 2, 57 bytes
lambda x,y:reduce(round,range(15,y-len(`int(x)`)-1,-1),x)

Try it online!

JavaScript (ES6), 58 bytes

f=
(x,n,y=x.toPrecision(n))=>y>x?y:(x*9/8-y/8).toPrecision(n)

<input id=x><input id=n type=number min=1 max=15 value=3>

Arithmetic solution. The given procedure rounds numbers up if they are greater than 4/9 of the next value, so if rounding doesn't increase the number, try again with a slightly greater value.

Perl 6, 59 bytes
{($^a,{.round(10**($++-15))}...^0|any 10 X**^30-15)[*-$^b]}

Try it online!
Anonymous code block that takes two numbers and returns a number.
Explanation:
{                                                         }  # Anonymous code block
 (                          ...                   )  # Create a sequence
  $^a,   # With the first element as the input
      {                    }  # With each element being
       .round(10**($++-15))   # The previous element rounded by another digit
                                0                   # Until 0
                                 |                  # or
                                  any 10 X**^30-15  # Any available power of 10
                               ^  # Ignoring the last number
                                                   [*-   ]  # Index from the end
                                                      $^b   # The second number

R, 79 bytes
Unfortunately, R uses "round to even" when rounding off a .5

function(x,y){for(i in nchar(gsub('\\.','',x)):y){x=signif((x*100+1)/100,i)};x}

Try it online!

Ruby, 103 bytes
This is ugly and presumably there are better ways (alas sprintf’s %g rounds to even), but it works.
g=->m,n{m.to_s.size>n ?g[(m/10.0).round,n]:m}
->x,n{_,s,_,e=x.to_d.split
"0.#{g[s.to_i,n]}".to_f*10**e}

Attempt This Online!


text:
Seconds to human readable format
Given a positive integer input n seconds, output the time in human readable format.
The time will be considered from 00:00:00, 1st January, 1 A.D.
Leap years must be taken into account.
Assume that the gregorian calendar was followed since the beginning.
(Gregorian Calendar: Every year that is exactly divisible by four is a leap year, except for years that are exactly divisible by 100, but these centurial years are leap years if they are exactly divisible by 400. For example, the years 1700, 1800, and 1900 were not leap years, but the years 1600 and 2000 were)
Output must be a string of the format:
x Millennia/Millennium, x Centuries/Century, x Decades/Decade, x Years/Year, x Months/Month, x Days/Day, x Hours/Hour, x Minutes/Minute and x Seconds/Second

The 0 values must not be shown.
Program must handle at least up to 999 Millennia(inclusive).
Plural/Singular must be kept in mind.
(For millennium, both millennia and millenniums are valid)
,,and and spaces must also be kept in mind.
Case may be anything.
Examples:
1:1 second
2:2 seconds
60:1 minute
62:1 minute and 2 seconds
3600:1 hour
3661:1 hour, 1 minute and 1 second
31536001:1 year and 1 second
317310301:1 decade, 20 days, 13 hours, 45 minutes and 1 second
3499454714:1 century, 1 decade, 10 months, 22 days, 22 hours, 45 minutes and 14 seconds
73019321114:2 millennia, 3 centuries, 1 decade, 3 years, 10 months, 22 days, 45 minutes and 14 seconds

Reference: date-difference to duration converter
This is code-golf so shortest code wins

@JoKing, leap seconds are a bit unpredictable aren't they?. It is added when the difference between atomic and astronomical clocks get greater than 0.9 seconds right? Does this happen after fixed intervals of time? If yes, then you can use them.

Perl 6, 273 245 233 230 bytes
-28 bytes thanks to nwellnhof!
{S/rys/ries/}o{S:th(*)/\,/ and/}o{join ', ',map {$_~'s'x(.[0]>1)},grep *[0],(|[R,](.[0].polymod(10 xx 3)),|.skip Z <millennium century decade year month day hour minute second>)}o{~DateTime.new($_-62135596800)~~m:g/\d+/Z-(^6 X<3)}

Try it online!
I think there might be a trick or two I can use with EVAL to make this shorter. This solution takes into account leap seconds, so the last test case is a bit off. Both no longer applicable.
(Old) Explanation:
{                                      } # First code block
 DateTime.new($_-62135596800)  # Initialise a date time object with input amount of seconds
{  ...  }o    # Pass value to the next code block
 fmt(.year-1: "%04d").comb Z   # Zip each digit of the year with
                             <millennium century decade year>  # The appropriate word
 <month day hour minute second>.map:{  ...  }   # For each of these words
                                ".$^a".EVAL     # EVAL the method on the DateTime
                                           -(2>$++)     # -1 if month or day
                                                   ,$a  # Followed by the word itself
  grep +*[0],  # From these, filter out the ones with value 0
  map {$_~'s'x(.[0]>1)},    # Add plurals if greater than 1
  join ', ',                # Join with commas
 {  ...  }o         # Pass string to next code block
  S:th(*)           # Substitute the last instance of
         /\,/       # A comma
            / and/  # With ' and'
 {  ...  }o         # Pass to next code block
  S/rys/ries/       # Fix plural of century

As of commenting, only this one and the C(gcc) by nwellnhof work for 999 millennium (31525395004800 seconds).

@KGlasier Thanks for pointing that out; apparently JavaScript's date library maxes out at 1e8 days, so I've had to adjust my answer to compensate.

Python 2, 304 297 bytes
lambda s:' and '.join(', '.join([`n`+' '+d+'s'*(n>1)for n,d in zip([int(str(datetime(1,1,1)+timedelta(0,s))[i:i-~(i>4)])-(2<i<9)for i in[0,1,2,3,5,8,11,14,17]],'millennium century decade year month day hour minute second'.split())if n]).replace('rys','ries').rsplit(', ', 1))
from datetime import*

Try it online!
Centuries are annoying...

Wolfram Language 255 251 bytes
If an Oxford comma is acceptable, this works:
Row[#,"  "]&/@(Cases[Partition[StringSplit@ToString@UnitConvert[#~Quantity~"Seconds",MixedUnit@{"Millenium","Century", "Decades","Years","Months","Weeks","Days","Hours","Minutes","Seconds"}],2],Except@{"0",_}]/.{a__,{b__}}:> {a,{"and",b}})&

UnitConvert is used to convert the number of seconds into mixed unit representation.
Cases displays only those measures in which the magnitude is not zero.
The remaining functions, Row, Partition, ToString and StringSplit merely format the output as required.
/.{a__,{b_, c_}}:> {a,{"and",b, c} inserts "and" before the final measure in those answers containing more than one unit of measure.

JavaScript (ES6), 384 bytes

f=
(n,r=[],d=new Date(n%31556952e4*1e3-621355968e5),y=d.getUTCFullYear()+(n/31556952e4|0)*1e4-1,g=(u,n=d[`getUTC${u}s`](),p=`s`,s=``)=>(n|=0)&&r.push(n+` `+u+(n>1?p:s)))=>(g(`Millenni`,y/1000,`a`,`um`),g(`Centur`,y/100%10,`ies`,`y`),g(`Decade`,y/10%10),g(`Year`,y%10),g(`Month`,d.getUTCMonth()),g(`Day`,d.getUTCDate()-1),g`Hour`,g`Minute`,g`Second`,g=r.pop(),r[0]?r.join`, `+` and `+g:g)
<input oninput=o.textContent=f(this.value)><pre id=o>

C (gcc) / glibc / Linux / 64 bits, 337 bytes
int*gmtime();f(long s){s-=62135596800;int*t=gmtime(&s),y=t[5]+1899,i=10,j=0,c=0,v[]={1,*t,t[1],t[2],t[3]-1,t[4],y%i,y/i%i,y/100%i,y/1e3},l[]={0,"second","minute","hour","day","month","year","decade","centur","millenium"};for(;i--;)v[i]&&(j&&printf("%s%d %s%s%s",c++?i?", ":" and ":"",v[j],l[j],j-8?"":v[j]<2?"y":"ie","s"+(v[j]<2)),j=i);}

Try it online!
Explanation
int*gmtime();  // Declare gmtime
f(long s){     // Function taking seconds as long
  s-=62135596800;   // Subtract constant for 0001-01-01
  int
    *t=gmtime(&s),  // Break down time
    y=t[5]+1899,    // Years since 1 AD
    i=10,
    j=0,
    c=0,
    v[]={  // Values
      1,        // Sentinel
      *t,       // Seconds
      t[1],     // Minutes
      t[2],     // Hours
      t[3]-1,   // Month days
      t[4],     // Months
      y%i,      // Years
      y/i%i,    // Decades
      y/100%i,  // Centuries
      y/1e3     // Milleniums
    },
    // Labels
    l[]={0,"second","minute","hour","day","month","year","decade","centur","millenium"};
  for(;i--;)  // Loop from i=9 to 0
    v[i]&&(     // If current value not 0 (or sentinel reached)
      j&&printf("%s%d %s%s%s",  // Print if previous index not 0
                c++?i?", ":" and ":"",  // Separator
                v[j],  // Value
                l[j],  // Label
                j-8?"":v[j]<2?"y":"ie",  // Handle century/centuries
                "s"+(v[j]<2)),  // Plural
      j=i  // Remember index
    );
}

As of commenting, only this one and the perl 6 by Jo King work for 999 millennium (31525395004800 seconds).


text:
find the value at kth position when numbers are sorted lexicographically till n
Ex :-
Input:
n = 12, k = 5
Output:
ans = 2
Sorted list S: ["1", "10", "11", "12", "2", "3", "4", "5", ...., "9"]
ans =  2

Welcome to PPCG! This site is for recreational programming puzzles, not programming help. If you intend this as a proper challenge, you'll have to add a objective winning criteria (e.g. [tag:code-golf]) , remove the [tag:c++] tag and make it sound a lot less like "I want help with my homework"

I think that this could be a good question for code-golf, provided that it isn't a duplicate. There are two remarks however, and both of them are that index-related. Since you say that you use C++ (which is 0-indexed), why are your numbers 1-12 rather than 0-11, and why is the answer a[4] if 5 is the input? Also, ╒░s\(§ and ╒░s§ are solutions in MathGolf for the original problem and a 0-indexed version.

Javascript (ES6), 55 bytes
(n,i)=>+[...Array(n).keys()].map(x=>x+1+"").sort()[i-1]

Try it online!
Unfortunately I can't comment yet, so I'll include it in my answer:
Welcome to PPCG! To make this a challenge you have to clarify some requirements of the challenge. Add a proper description, define the expected output and the winning criteria and also add some example tests.

The default sort in javascript is lexicographic.  So you can write .sort() instead of .sort((a,b)=>a.localeCompare(b))

@Spitemaster well, yea. Not sure why I didn't think of that. Thanks :)

R, 32 bytes
function(n,k)sort(c(1:n,"x"))[k]

Try it online!


text:
Iron particles around a magnet
There are some iron particles on a board. We pass a current carrying wire through that board and the particles form circles. Show these circles if input given is the position of the wire.
Consider the board to be a grid of size 7x7 (fixed)
No extra white spaces are allowed.
Input can be 0-indexed or 1-indexed. (0-indexed in examples)
Examples
input:3,3 # 'X' is wire here but can be shown by anything other than '\/|-'
output:
/-----\
|/---\|
||/-\||
|||X|||
||\-/||
|\---/|
\-----/

input:1,2
output:
|/-\|||
||X||||
|\-/|||
\---/||
-----/|
------/
-------

input:0,0
output:
X||||||
-/|||||
--/||||
---/|||
----/||
-----/|
------/

input:0,3
output:
|||X|||
||\-/||
|\---/|
\-----/
-------
-------
-------

input:3,0
output:
---\|||
--\||||
-\|||||
X||||||
-/|||||
--/||||
---/|||

This is code-golf so shortest code wins.

Can the function output a 7x7 matrix with the characters or we need to print it on the console ?

J, 40 bytes
7 7{.6 6&-|.0":<^:6@8[9!:7@'/_\___\_/|-'

Try it online!

Neat use of box drawing once again! Can you provide an axplanation of the entire solution? Thanks!

R, 136 119 116 bytes
function(i,j,m=diag(7),R=row(m)-i,a=j-col(m)){m[]='-'
m[R==a]='\\'
m[R==-a]='/'
m[R<a&R>-a|R>a&-R>a]='|'
m[i,j]=0
m}

Try it online!

-3 bytes saved thanks to @Giuseppe

Function that takes (row,col) coordinates of the wire (1-indexed) and returns a 7x7 matrix with the characters.

Canvas, 27 23 22 21 bytes
-７×［\＋］↶ω⟳ｎ↔┼⁷⁸╵７７＠↕↔

Try it here!

JavaScript (ES7),  105  103 bytes
Takes input as (y)(x), 0-indexed.
Y=>X=>(g=x=>y<7?`/\\-|X
`[h=(X-x)**2,v=(Y-y)**2,x<7?h<v?2:h>v?3:h?x<X^y<Y:4:5]+g(x<7?x+1:!++y):'')(y=0)

Try it online!

Perl 6, 90 bytes
{<| v - \ X />[1+([-]($_>>.abs).sign||3+[*]($_).sign)for ^7-$^a X ^7-$^b].rotor(7)>>.join}

Try it online!
Anonymous code block that takes two numbers and returns a list of lines.

Python 2, 105 bytes
lambda x,y:[''.join(['/-|'[cmp(abs(i-x),abs(j-y))],'\X'[i==x]][i-x==y-j]for j in R)for i in R]
R=range(7)

Try it online!

Charcoal, 21 bytes
ＧL⁷-↙⁶X‖Ｂ↘¬‖Ｊ±Ｎ±ＮＴ⁷¦⁷

Try it online! Takes 0-indexed column and row as input. Explanation:
ＧL⁷-

Draw a triangle of -s.
↙⁶

Draw a line along the hypotenuse. (This is the wrong way around but we'll fix that later.)
X

Draw the X that shows the position of the wire. (Any other ASCII character could be used here of course.) This completes one eighth of the drawing.
‖Ｂ↘¬

Reflect three times (¬ = left + down) while transforming characters to almost complete the diagram.
‖

Reflect without transforming to switch the /s with the \s so they now point around the X instead of towards it.
Ｊ±Ｎ±Ｎ

Jump to the top left of the desired output.
Ｔ⁷¦⁷

Trim the result to the desired size.


text:
Print coordinates of an NxN grid
Question: Print out all the coordinates of a NxN grid. Preferably in C, however other languages also accepted
Input: N (integer)
Output: for N=3, a 3x3 grid:
0,0
1,0
2,0
0,1
1,1
2,1
0,2
1,2
2,2

Welcome to PPCG! This is the start of a good question. I couldn't find a duplicate from a quick search, though I might be mistaken. One thing I'd suggest is to specify the input and output. I assume that the input is an integer N. Is the output a list of tuples, a list of strings, should it be printed? Does it need to be separated by a comma?

Are we allowed to return a list instead of printing them? Is any order acceptable (i.e. [[0,0],[0,1],[0,2],[1,0],[1,1],[1,2],[2,0],[2,1],[2,2]] instead of what you have above)? Can the output have 1-indexed coordinates instead of 0-indexed?

Also, see https://codegolf.meta.stackexchange.com/a/8066/71420 -- suggest not to ask about doing it in C if any language is acceptable.

Can we start at (1,1) instead of (0,0) ?

@sergiol must be started at 0,0

@KevinCruijssen list is acceptable

Is the input the dimensions of the grid?

Is there a particular order they have to be in or is any order fine?

Can't decide whether this is a dupe of this (just hardcode $n=2$) or this (just duplicate the argument instead of taking two distinct), but probably both.

Nice find on the dupe. Would have taken me forever to track that down.

C (gcc), 83 51 bytes
Saved 32 bytes and fixed output order thanks to Kevin Cruijssen.
i;f(n){for(i=0;i<n*n;)printf("%d,%d\n",i++%n,i/n);}

Try it online!
I'm by no means a C programmer (or C golfer), but I thought I'd give it a try. Should the main be included in the byte count?

51 bytes :) (And no, main method doesn't have to be included. For Java, C, C#, etc. etc. we allows functions instead of full programs, since full programs are quite verbose and doesn't add anything to the actual solution.)

Btw, to have the exact same order for each coordinate as in the input (ordered by y-then-x instead of x-then-y), the i++/n,i%n should be i++%n,i/n. :)

@KevinCruijssen Good point, updated the post!

Japt, 3 bytes
o ï

Try it
o       :Range [0,input)
  ï     :Cartesian product with itself

I had the same solution with  ñÌ at the end to sort it. Hopefully the OP doesn't care about the order.

@Oliver, mw would also work.

R, 33 25 bytes
which(diag(scan())|1,T)-1

Try it online!
Thanks to Kirill L. for suggesting a 2-byte golf, which inspired me to look further :-)

Where do you hear about all of these functions in R? I've never even used arrayInd before, but I feel like it could be useful in a lot of things!

@Sumner18 You can't be as golfy if you don't understand a big chunk of the language, so it pays to read the docs! there are a few workhorse functions like match and which. which in particular has an arr.ind argument, so looking at the documentation for which, we see a note in the Details under .dimnames about passing  to the arrayInd function!

31 bytes. Sadly, requires  !!, as otherwise: argument to 'which' is not logical...

@KirillL. that's neat! It also inspired me to shave off another 2 bytes. EDIT: another 6 bytes!

05AB1E, 8 bytes
L<ãí',ý»

Exactly as the challenge description: prints the 0-indexed coordinates ordered by y-then-x comma- and newline-delimited to STDOUT.
Try it online.
Explanation:
L          # Create a list in the range [1, (implicit) input]
           #  i.e. 3 → [1,2,3]
 <         # Decrease each by 1 to make the range [0, input)
           #  i.e. [1,2,3] → [0,1,2]
  ã        # Create each possible pair with itself
           #  i.e. [0,1,2] → [[0,0],[0,1],[0,2],[1,0],[1,1],[1,2],[2,0],[2,1],[2,2]]
   í       # Reverse each pair so they're sorted by y-then-x instead of x-then-y
           #  i.e. [[0,0],[0,1],[0,2],[1,0],[1,1],[1,2],[2,0],[2,1],[2,2]]
           #   → [[0,0],[1,0],[2,0],[0,1],[1,1],[2,1],[0,2],[1,2],[2,2]]
    ',ý   '# Join each pair with a space delimiter
           #  i.e. [[0,0],[1,0],[2,0],[0,1],[1,1],[2,1],[0,2],[1,2],[2,2]]
           #   → ["0,0","1,0","2,0","0,1","1,1","2,1","0,2","1,2","2,2"]
       »   # And then join everything with a newline delimiter (and output implicitly)
           #  i.e. ["0,0","1,0","2,0","0,1","1,1","2,1","0,2","1,2","2,2"]
           #   → "0,0\n1,0\n2,0\n0,1\n1,1\n2,1\n0,2\n1,2\n2,2"

05AB1E, 2 bytes
Lã

Returns a list of 1-indexed coordinates ordered by x-then-y.
Try it online.
Explanation:
L     # Create a list in the range [1, (implicit) input]
      #  i.e. 3 → [1,2,3]
 ã    # Create each possible pair with itself (and output implicitly)
      #  i.e. [1,2,3] → [[1,1],[1,2],[1,3],[2,1],[2,2],[2,3],[3,1],[3,2],[3,3]]

How comes that your 2-byter is 1-indexed?

@maxb I've added an explanation to my post now. L is a 1-indexed list in the range [1,n] (where n is the implicit input). I've made it 0-indexed in my 8-byte answer with the < (decrease by 1).

PowerShell, 48 42 bytes
param($n)0..--$n|%{$i=$_;0..$n|%{"$i,$_"}}

Try it online!
Boring double-for loop.
Saved 6 bytes thanks to mazzy.

? param($n)0..--$n|%{$i=$_;0..$n|%{"$i,$_"}}

@mazzy Of course, removing the -join. Thanks!

C#, 59, 65
First time posting.  Apologies if I do something wrong!
l=>{for(int j=0;j<l*l;)System.Console.Write($"{j%l},{j++/l}\n");}
Try it online!  -per Kevin Crujissen's TIO Link.

Welcome to the site! Unfortunately, assuming input is in a predefined variable is not a standard form of input. You could add a console.readline() or however that's supposed to work (I'm not too familiar with C#) or submit a function instead.

Hi, welcome to PPCG! We allow either functions or full programs as answers (yours is currently more like a snippet), and all imports add to the byte-count. Which means your current answer should be l=>{for(var j=0;j<l*l;j++)System.Console.Write($"{j%l},{(int)j/l}\n");} instead (71 bytes). However, you can golf 6 bytes by changing (int)j/l to j++/l and remove the j++ like this: l=>{for(int j=0;j<l*l;)System.Console.Write($"{j%l},{j++/l}\n");}. Try it online.

Also, if you haven't seen it yet, tips for golfing in C# and tips for golfing in  might be interesting to read through. Apart from some ruling, your first answer looks fine, so +1 from me. Again welcome, and enjoy your stay! :)

Thanks guys!  Sorry about the function error.  Appreciate the for increment golf!

Can you provide a demo?

@sergiol Kevin provided a TIO link.  I put it on the post.

Tcl, 70 bytes
proc C {n i\ 0} {time {set j 0
time {puts $i,$j
incr j} $n
incr i} $n}

Try it online!

Failed outgolf: https://tio.run/##K0nO@f@/oCg/WcFZoTpPITNGwaBWobokMzdVobqgtKRYITq1oqBIQSVTXyUvVgfGUQVyrDPzkosUMmthKvK0gIK1/3NyEwsU8hSquYy5TLhqoYao5MVUqORxOQMZXGABJaXa/wA

Python 2, 39 bytes
lambda n:[(i%n,i/n)for i in range(n*n)]

Try it online!

I think the question requires variable N...

@FelixPalmen Doh.. Fixed :)

Pyth, 4 bytes
^UQ2

Full program. Outputs list of coordinate pairs.
^UQ2   Implicit: Q=eval(input())
 UQ    [0-Q)
^  2   Take the cartesian product of the previous result with itself

MathGolf, 2 bytes
r■

Try it online!
Explanation
r    Range(0, n)
 ■   Cartesian product with self for lists

For pretty-printing, you could add n to have it print one list item per line.

APL+WIN, 11 bytes
(⍳n)∘.,⍳n←⎕

Index origin = 0. Prompts for input for n and outputs the following for n=4:
0 0  0 1  0 2  0 3
1 0  1 1  1 2  1 3
2 0  2 1  2 2  2 3
3 0  3 1  3 2  3 3

Pepe, 88 bytes
I've never done 2D iterating in Pepe before and it doesn't seem to work pretty well due to labels being dynamic. There's quite a lot of two byte commands to avoid moving the pointer.
REREeErEErerErEReREErEEEErreEEreeeEeEEeerEEeerreEErEEEEEreeEReererEEEEErERRREEEEEeRrEree

Try it online!
Warning: Do not run it with input below 1 - it will kill your browser.

Perl 5 -na, 35 bytes
map{//;say"$',$_"for 0..$F[0]}0..$_

Try it online!

Powershell, 43 bytes
param($n)$i--..--$n*++$n|%{$i+=!$_;"$i,$_"}

Explanation:
One row 0..$n-1 repeated $n times.

Pure Bash (no external utilities), 35
eval echo {0..$[$1-1]},{0..$[$1-1]}

Try it online!

Lua, 63 bytes
s=io.read()-1 for i=0,s do for j=0,s do print(i..','..j)end end

Try it online!

Perl5, 42 38 bytes
for$i(0..--$n){for(0..$n){say"$i,$_"}}

(The inner loop saves a few bytes by using the implicit variable "$_" as an index.)


text:
Hilbertize an image
For a computer vision app I want to do a mapping of an image, in such a way that every pixel fit hilbert curve, instead of conventional layout. So task could be as follows:

Task description
Given square 2D image A with side 2^^N, (N>0), with common Z-order, or row-major representation of pixels in RAM. I need to run a hilbert curve through this image (Like a digital camera, where photodiodes are soldered in a hilbert curve and numbered and accessed in a 1-d ordered manner). Then pixels along this curve just layed down as a regular scanline in image B. So now any consequent samples in output array B now should represent spatially close points in input array A.

Example for N=2

Input: array A (imagination of 2D image)
0 1 E F
3 2 D C
4 7 8 B
5 6 9 A

Input: array A (1D actual layout in memory)
0 1 E F 3 2 D C 4 7 8 B 5 6 9 A

Output: array B (answer)
0 1 2 3 4 5 6 7 8 9 A B C D E F

Note, that values inside arrays are "values". In this example, for array B  accidentally they became same as indices. So basically I want index mapping function B[i]=A[?], e.g B2 = A[E].
Hope code golfing helps.

Example for N=9:
Taken popular 512*512 test image.
Each pixel was threated as 32bit integer, in RGBA format and algorithm proceeded:
Input:

Output:

Reverse question:
Here is reversed-task question on codegolf.
In terms of that question, I want to do opposite transform: "I want to Reravel image A, then Unravel to image B".
In terms of examples of that question: I want to take photo the lion on the camera with hilbert-curved-sensor (look Output array for lion photo) and get that long "scanline of spatially close pixels" (Input for lion photo, in that question)

Reference implementation:
If i take d2xy() function from LGPL sources found here I may write a following program, which works, but maybe not its best way:
#include "hilbert_curve.h"
int main(){
  int *A,*B,i,x,y;
  for(i=0;i<(1<<(N<<1));++i){
    d2xy(N,i,&x,&y);
    B[i]=A[y*(1<<N)+x];
  }
}

Resources:

Spatial indexing with Quadtrees and Hilbert Curves
hilbert function, which returns a rendering of Hilbert Curves

Related.

@Arnauld Yes, i saw it previously. I don't need to copy few identical symbols with rotation, but different bytes or arbitary 2D image, to "hilbertize" it.

And BTW: welcome to PPCG! Although this site is dedicated to recreational programming challenges and not recommended for real world problems, this looks like a perfectly valid challenge nonetheless -- though it might currently be a bit under-specified.

So, what is the input and what is the output? One could e.g. assume an input of N and and a list of carthesian coordinates visited along the curve as ouptut? Also please see https://codegolf.meta.stackexchange.com/a/8078/71420

Also a word of warning, your text reads as if you're looking for an actual solution to use it. Nothing wrong with that, as long as it's a good challenge, but code-golf solutions tend to be more or less useless for realworld coding ;)

Welcome to ppcg and nice first challenge!  Unfortunately it has already been asked here.  Hope you stick around anyway!

@PostLeftGarfHunter Nope, this is NOT an answer, but a reverse task! I I need his OUTPUT, and to produce INPUT!

@PostLeftGarfHunter I probably made an error initially, i corrected it now.

You may want to provide another test case for $N>2$.

I would recommend adding a link to the Hilbert Curve wiki to the question, so that people may more easily read about it.

@xakepp35 Just to clarify my suggestion, the purpose of test cases is to check that a submitted program is working properly, not to help understand the challenge (although they may sometimes do -- but the challenge should not rely on that).

@KamilDrakari just did that, btw, ppl on this site usually have google as their best friend!

Jelly, 38 bytes
U1¦U;$;;UN$
Ll2’ð⁽Æ¬b3’s2Ç⁸¡⁵DW¤;+\Ḋœị

A monadic Link accepting a square matrix of side \$2^n\$, \$n\$ a positive integer which yields an array of the inputs elements in Hilbert curve order.
Try it online!
How?
First we create [row, column] index deltas describing the U shape with an initial right move (i.e into the \$n=1\$ matrix's top-left corner from the left) - that is [[0, 1], [1, 0], [0, 1], [-1, 0]].
Then we repeatedly perform a transform keeping the current list of deltas to describe the bottom-right quarter of the next and adding the other three quarters as copies with reversed deltas (swapping row changes with column ones where necessary and negating directions of the new top-right quarter).
Finally we prepend a starting index of [1,0] (to the left of the top-left of our [1-indexed] matrix), cumulatively reduce by addition to get the indexes, discard the [1, 0] and index into the input.
How?
U1¦U;$;;UN$ - Link 1, transform deltas to next size: list of current deltas
U1¦         - reverse the first delta (makes bottom-left)
   U;$      - reverse each of those and concatenate with that (adds top-left)
      ;     - concatenate with the input (adds bottom-right)
        UN$ - reverse each of the input deltas and negate (makes top-right)
       ;    - concatenate (adds top-right)

Ll2’ð⁽Æ¬b3’s2Ç⁸¡⁵DW¤;+\Ḋœị - Main Link: square matrix (of side 2^n), M
L                          - length of M
 l2                        - log base 2 (=n)
   ’                       - decrement
    ð                      - start a new dyadic chain (i.e. f(n-1, M))
     ⁽Æ¬                   - compressed literal = 4258
        b3                 - to base 3 = [1,2,2,1,1,2,0,1]
          ’                - decrement = [0,1,1,0,0,1,-1,0]
           s2              - split into twos = [[0,1],[1,0],[0,1],[-1,0]]
               ¡           - apply repeatedly...
              ⁸            - ...number of times: chain's left argument, n-1
             Ç             - ...what?: last Link as a monad
                           -           - gets all deltas
                   ¤       - nilad followed by link(s) as a nilad:
                ⁵          -   literal ten
                 D         -   to decimal digits = [1,0]
                  W        -   wrap = [[1,0]]
                    ;      - concatenate with the deltas
                     +\    - cumulative reduce using addition (N.B. Ä wont work here)
                       Ḋ   - dequeue (drop the [1, 0] leading index)
                        œị - multi-dimensional index into M

Whoa! Whole 38 bytes, even for jelly..

There could be a shorter way, and this way might be golfable.

Note also I restrict n as positive (i.e. no 1*1 input). I guess that's fine?

Sure, "1*1 conversion" is a trivia, which does not require even running code (output = input) and is no of interest. You may omit such check, will add this to conditions.

Fastest way of doing it (that I found up to day) is to build index lookup table s2h[2^^(N*2)] for given N, before batch-processing multiple same sized images. Then, just call B[i] = A[s2h[i]], while processing each pixel. For N=9 lookup table will take whole 1MB (5125124), which is not quite friendly for L1/L2 CPU caches. Hopefully it will be at L3.. So (to be honest) I am looking for a indexing function f(i) = s2h[i], which will be faster using math, that using single memory lookup. Memory-heavy algorithms are way slower than SSE/AVX, are ASIC-resistant and not very good even on GPUs!

fast != golfed :p

That implies restrictions: if I want to use it as 1D codec instead of 2D jpeg MDCT transform (MJPEG in most webcams) and embed it to robotics vision camera circuit (for "onboard compression") - I would also have been forced to add a (expensive) memory with indices LUT table to that camera circuit. Even its read-only, and can be pre-flashed once. Best way would be to solder matrix addressing bus in a form of hilbert curve, but that is a challenge about producing very specific CMOS sensor. ;-P

Sorry, I have no idea what most of that means :)

No problem! Thanks for your effort, good solution! Lets wait for what others could offer..


text:
Draw some expanding arrows
This challenge is about printing a series of growing ASCII-art arrows. I'll describe the pattern in words, but it might be easier to look at what the start of this series looks like:
>
<
->
<-
-->
<--
--->
<---
---->
<----
----->
<-----
------>
<------
...

An arrow with length n contains an arrowhead (< or >) and n-1 dashes (-). A right-facing arrow has the dashes first, then a >. A left-facing arrow starts with <, and is followed by the dashes. The series consists of a length n right-facing arrow followed by a length n left-facing arrow, with n from 1 to infinity.
To complete the challenge, write a program or function that takes one input, an integer i >= 1, and outputs the first i arrows. Arrows are individual, not in right-left pairs, so for i=3 you should output:
>
<
->

You can return a list of strings, or print them one after the other. If printing, the arrows must be delimited by some consistent delimiter, which doesn't have to be a newline as in the example.
This is code-golf, so fewest bytes wins.

Related.

Can we have spaces before/after each line?

@OlivierGrégoire Yes, trailing whitespace is ok.

And heading whitespace?

@OlivierGrégoire Yeah, that's fine.

@Pavel what if another delimiter is used? are trailing/leading delimiters fine too, as long as no other non-output characters appear?

@ASCII-only Yes, but only one leading/trailing delimiter. So if it's |, you can't start with ||||||

Canvas, 10 bytes
⇵-×<ｎ¹［↔｝］

Try it here!

I don't know any Canvas, but is that an arrow-drawing builtin I see? ↔ kinda looks like it!

↔ is the "reverse horizontally" built-in (also swapping > & <), sadly no arrow built-ins :p

R, 69 bytes
for(i in 1:scan()-1)cat('<'[i%%2],rep('-',i/2),'>'[!i%%2],'
',sep='')

Try it online!

-5 bytes thanks to @Giuseppe
-3 bytes thanks to @Robert S.

strrep coerces its second argument to integer so you can use / in place of %/%

you can also get rid of a entirely by indexing over 0...(n-1) instead: Try it online!

I'm an idiot... thanks ! :D

@Giuseppe :also I just noticed the deleted question of Robert S. I can use rep instead of strrep and save 3 bytes...(facepalm)

Java (JDK), 81 bytes
n->{for(int i=0;i<n;)System.out.printf(i%2<1?"<%s%n":"%s>%n","-".repeat(i++/2));}

Try it online!
Explanations
n->{                  // int-accepting consumer
 for(int i=0;i<n;)    //  for each i from 0 to n-1 included
  System.out.printf(  //   output on stdout with a pattern
   i%2<1              //    if i is even:
    ?"<%s%n"          //     use the left-arrow pattern
    :"%s>%n",         //    else: use the right-arrow pattern
   "-".repeat(i++/2)  //    fill the "%s" in the pattern with i/2 dashes, and increment i
  );                  //
}                     //

Consider removing static reference to System.out

@candied_orange That's not self-contained.

How about done like this?

@candied_orange It's the same: the imports are required in the count.

Why doesn't import java.util.function.*; count?

Because I use a lambda, and lambda are independant of functions. I merely use a function to be able to call the lambda, but if I wrote a lambda-accepting method that isn't in java.util.function, it'd still be legal. java.util.function != lambda.

Let us continue this discussion in chat.

Haskell, 41 40 bytes
(`take`g">")
g p=p:('<':init p):g('-':p)

Try it online!
Plain old recursion: start with string p = ">", collect p, a < in front of all but the last char of p and a recursive call with one - put in front of p. Take the first n items of this list.
Edit: -1 byte thanks to @xnor.

A weird change to save a byte.

Python 2, 54 bytes
thanks to the and Jo King for fixing a bug.
k=0
exec"print k%2*'<'+k/2*'-'+~k%2*'>';k+=1;"*input()

Try it online!

Your arrows have too many dashes; only every other one should lengthen by a dash.

54 bytes

Commodore BASIC V2 (C64), 94 bytes
0inputn:fOi=1ton:oniaN1gO1:?"<";
1on-(i<3)gO2:fOj=1.5toi/2:?"-";:nE
2on-nOiaN1gO3:?">";
3?:nE

Not entirely sure about the byte count, this is based on the text representation for typing the valid program. It's a bit shorter on disk (91 bytes) because BASIC V2 uses a "tokenized" representation of programs.
Online Demo
Slightly "ungolfed":
0 inputn:fori=1ton:oniand1goto1:print"<";    :rem read n from user, loop to n, if odd skip "<"
1 on-(i<3)goto2:forj=1.5toi/2:print"-";:next :rem skip for i<3, print (i-1)/2 times "-"
2 on-notiand1goto3:print">";                 :rem if even skip ">"
3 print:next                                 :rem newline and next loop iteration

Self-modifying Brainfuck, 55 bytes
Take input as character code.
Only support input up to 255.
Use null character to separate lines.
Coincidentally, all arrow-drawing characters are used as BF commands. Unfortunately, it doesn't save any bytes (currently).
>>,[<<[-<.>>+<]<<.>>.+>>-[<<<<<.>>>>[-<+<.>>].>-<]>]<>-

Try it online!
Explanation
 Code  |              Memory         | Output | Comment
-------+-----------------------------+--------+--------------------------
       | '<' '>' '-' [0]  0   0   0  |        |
>>,    | '<' '>' '-'  0   0  [x]  0  |        |
[      |                             |        |
       | '<' '>' '-'  l   0  [x]  0  |        | l = arrow length
<<[-<  |                             |        | copy l to next cell
.>>+<] |                             |        | and print '-'
       | '<' '>' '-' [0]  l   x   0  | -----  | there are l '-'s
<<.    | '<' [>] '-'  0   l   x   0  | >      |
>>.+   | '<' '>' '-' [1]  l   x   0  | <null> |
>>-    | '<' '>' '-'  1   l  [y]  0  |        | y=x-1
[      |                             |        | execute if y>0
<<<<<. | [<] '>' '-'  1   l   y   0  | <      |
>>>>   | '<' '>' '-'  1  [l]  y   0  |        |
[-<+<. |                             |        |
>>]    | '<' '>' '-'  L  [0]  y   0  | -----  | L=l+1
.      | '<' '>' '-'  L  [0]  y   0  | <null> |
>-<]>] |                             |        | decrement y
<>-    |                             |        | do nothing, used as data

Pyth, 17 bytes
m_W%d2+*\-/d2@"><

Output is a list of strings. Try it online here.
m_W%d2+*\-/d2@"><"dQ   Implicit: Q=eval(input())
                       Trailing "dQ inferred
m                  Q   Map [0-Q), as d, using:
          /d2            Floored division of d by 2
       *\-               Repeat "-" the above number of times
      +                  Append to the above...
             @"><"d      Modular index d into "><" - yields ">" for even d, "<" for odd
                         - examples: d=4 gives "-->", d=7 gives "---<"
 _W                      Reverse the above if...
   %d2                   ... (d % 2) != 0
                       Implicit print result of the map

PowerShell, 62 56 50 bytes
param($n)(0..$n|%{($j='-'*$_)+'>';"<$j"})[0..--$n]

Try it online!
Loops from 0 up to input $n, each iteration creating two arrow strings. Those are then indexed with 0..--$n to pull out the correct number of elements.
Saved 6 bytes thanks to KGlasier.

Messing around with my own solution I found a way to cut a few bytes on yours: Can save 4 bytes by wrapping the loop in brackets and indexing directly. ie param($n)(0..$n|%{($j='-'*$_++)+'>';"<$j"})[0..--$n]. So now you don't have to write $x twice.

Also you can save two more bytes by not using ++ in ($j='-'*$_++) as you don't use $_ anywhere else.

@KGlasier Awesome - thanks for the obvious golfs! :)

Haskell, 51 44 bytes
-7 bytes thanks to xnor (using iterate over list-comprehension)!
(`take`do b<-iterate('-':)"";[b++">",'<':b])

Try it online!
Explanation / Ungolfed
Using do-notation saves us a concat, and using infix-notation allows a pointfree function with take, undoing these would give:
f n = take n $ concat [ [b++">", '<':b] | b <- iterate ('-':) "" ]

Japt -m, 16 15 13 12 bytes
Saved 1 byte thanks to Shaggy
g<i>)iUUz ç-

Test it online
Explanation:
-m            // Map the program through [0...Input); U becomes the iterative number
g<i>)iUUz ç-
 <i>          // ">" prepended with "<", creating "><"
g             //   Get the char at index U, with index-wrapping
    i         // Insert:
     U        //   At index U, with index-wrapping
         ç-   //   "-" repeated:
      Uz      //     U/2 times

12 bytes

@Shaggy Ha! Very clever, thanks!

Python 3, 53 bytes
My first codegolf answer.
lambda x:[i%2*"<"+i//2*"-"+~i%2*">"for i in range(x)]

-10 bytes thanks to Jo King

Jelly, 15 bytes
ị⁾><;’H”-ẋƲṚ⁸¡)

Try it online!

-1 byte using tie: TIO.

Japt -m, 14 bytes
"<>"¬hUUz ç-)q

Try it online!
Updated with a completely new method.
Explanation:
                  #Implicitly map over the range [0..input) as U
"<>"              #The string "<>"
    ¬             #Split into the array ["<",">"]
     hU     )     #Replace the element at index U with wrapping:
           -      # The character '-'
          ç       # Repeated a number of times equal to
       Uz         #  U integer divided by 2
             q    #Join the array to a string

ç auto-casts its first parameter into a string, so you can drop the '.

You don't need the u method thanks to index wrapping so this can be 14 bytes.

MathGolf, 17 15 bytes
Saved 2 bytes thanks to Jo King and Kevin Cruijssen
{ï½'-*'>ï¥╛Å⌡\n

Try it online!
Explanation
The 15-byte approach is different compared to my original solution, I can't take any credit for the implementation.
{                 start block or arbitrary length
 ï                index of current loop, or length of last loop
  ½               pop a : push(a//2 if int else a/2)
   '-             push single character "-"
     *            pop a, b : push(a*b)
      '>           push single character ">"
        ï         index of current loop, or length of last loop
         ¥        modulo 2
          ╛       if without else
           Å      start block of length 2
            ⌡     decrement twice
             \    swap top elements
              n   newline char, or map array with newlines

How does the if/else work in MathGolf? I know how the if-without-else and else-without-if statements work, but how to create an if{ ... } else{ ... } in MathGolf with ¿? (Maybe I should post this in the chat instead of here.. But I might perhaps have a save of 1 byte if I can fix the if-else.)

@KevinCruijssen I think it works with the next two commands/blocks. e.g. ¿12 will push 1 if true, else 2, ¿Å3*Å1+ will add one if true else triple the next element

@KevinCruijssen The if/else pops two operators or blocks from the code. Jo King is correct in his example, but you could also do ¿{"foo"}{"bar"} or ¿1{2}.

@JoKing I'll add a TODO to fix the docs for the slicing operators.

@JoKing Ah ok, thanks for the explanation. Forgot about the code-blocks of length n builtins up to size 8. In that case it's a 17 bytes alternative as well.

I feel like '> should only count as one command, which would save a byte :(

15 bytes using @KevinCruijssen's solution

@JoKing Ah nice. Didn't knew increment/decrement worked on characters as well in MathGolf. That's good to know. :)

C (gcc), 80 77 76 74 71 bytes
g(n,i,j){--n&&g(n);for(j=n%2,i=n/=2;putchar(~n?n---i*j?45:62-j*2:0););}

Try it online!
-3 bytes with idea from ASCII-only.
-1 with \0 instead of \n
-5 rearranging parts

Output includes a trailing \0.
g(n,i,j){
    --n&&g(n);              //draw smaller arrows first (if n>1)
    for(j=n%2,i=n/=2;       //j:!(input parity); i:arrow len-1=ceil(input)/2-1
        putchar(~n          //if n>=0, arrow is not yet completed
                ? n---i*j   //if not first (j==1) or last (j==0) char of arrow:
                  ? 45      // output '-'
                  : 62-j*2  // otherwise, output the appropriate arrow head
                : 0););     //\0 after arrow complete. putchar returns 0; loop terminates
}

this might be clearer? idk

so close :/

@ASCII-only Yeah, that should be clearer, even if it doesn't make a difference for bytecount. As for that second point.. thanks for the idea! Managed to trim down to 78 with that.

sadly, combining ternaries doesn't help

XD you still have !n-- in the first codeblock

ah, thanks for the catch

might help? although probably won't

delimiter doesn't have to be newline. so you can change 10 to 0

as far as I'm aware, none of the ascii characters from 0-9 count as whitespace

Let us continue this discussion in chat.

JavaScript (ES6), 58 bytes
Returns a space-separated string.
n=>(g=p=>n--?k++&1?`<${p} `+g(p+'-'):p+'> '+g(p):'')(k='')

Try it online!

SNOBOL4 (CSNOBOL4), 123 122 118 bytes
	N =INPUT - 1
P	H =X / 2
	Y =DUPL('-',H)
	OUTPUT =EQ(H,X - H) Y '>'	:S(I)
	OUTPUT ='<' Y
I	X =LT(X,N) X + 1	:S(P)
END

Try it online!

V, 22 bytes
i>
<Àñäkjjé-já-ñÀGjdG

Try it online!

This looks like some weird scandinavian language

Charcoal, 16 bytes
ＮθＦθ«⊘ι↓>‖Ｔ»Ｆθ‖Ｔ

Try it online! Link is to verbose version of code. I had three 17-byte solutions before I eventually stumbled over this one. Explanation:
Ｎθ

Input n.
Ｆθ«

Repeat n times, 0-indexed.
⊘ι

Draw a line of -s of length half the index (truncated).
↓>

Draw the arrowhead and move to the next line.
‖Ｔ»

Reflect everything, flipping the arrowheads.
Ｆθ‖Ｔ

The above loop has n reflections, but we need an even number of reflections, so perform another n reflections.

Clean, 76 73 bytes
import StdEnv,StdLib
$n=take n[s\\i<-inits['--'..],s<-[i++['>'],['<':i]]]

Try it online!
Uses the neat fact that ['-','-'..] is the same as ['--'..] to save a bit.

6502 machine code (C64), 49 bytes
00 C0 20 9B B7 A2 00 8A 4A A8 90 05 A9 3C 20 D2 FF A9 2D C0 00 F0 06 20 D2 FF
88 D0 FA 8A 4A B0 05 A9 3E 20 D2 FF A9 0D 20 D2 FF E8 E4 65 D0 D7 60

Still quite a bit shorter than BASIC ;) This one has a number range only up to 255 because the natural integer size of the machine has only 8 bits.
Online demo
Usage: SYS49152,[n] (e.g. SYS49152,3 for the example from the challenge)
Commented disassembly:
         00 C0       .WORD $C000        ; load address
.C:c000  20 9B B7    JSR $B79B          ; get unsigned byte from commandline
.C:c003  A2 00       LDX #$00           ; main loop counter
.C:c005   .loop:
.C:c005  8A          TXA                ; loop counter to accumulator
.C:c006  4A          LSR A              ; divide by 2, shift lowest bit to C
.C:c007  A8          TAY                ; result to Y
.C:c008  90 05       BCC .toright       ; C clear -> counter even, skip '<'
.C:c00a  A9 3C       LDA #$3C           ; load character '<'
.C:c00c  20 D2 FF    JSR $FFD2          ; output character
.C:c00f   .toright:
.C:c00f  A9 2D       LDA #$2D           ; load character '-'
.C:c011  C0 00       CPY #$00           ; counter/2 == 0 ? then no dashes
.C:c013  F0 06       BEQ .skipdashes
.C:c015   .printdashes:
.C:c015  20 D2 FF    JSR $FFD2          ; output character
.C:c018  88          DEY                ; decrement Y
.C:c019  D0 FA       BNE .printdashes   ; not 0 yet -> repeat
.C:c01b   .skipdashes:
.C:c01b  8A          TXA                ; loop counter to accumulator
.C:c01c  4A          LSR A              ; shift lowest bit to C
.C:c01d  B0 05       BCS .toleft        ; C set -> counter odd, skip '>'
.C:c01f  A9 3E       LDA #$3E           ; load character '>'
.C:c021  20 D2 FF    JSR $FFD2          ; output character
.C:c024   .toleft:
.C:c024  A9 0D       LDA #$0D           ; load newline character
.C:c026  20 D2 FF    JSR $FFD2          ; output character
.C:c029  E8          INX                ; next loop iteration
.C:c02a  E4 65       CPX $65            ; compare to command line argument
.C:c02c  D0 D7       BNE .loop          ; not reached yet -> repeat main loop
.C:c02e  60          RTS                ; exit

JavaScript, 49 bytes
f=n=>--n?f(n,l='')+(n%2?`
<`+l:`
${l+='-'}>`):'>'

Try it online!

Wow, pretty cool

...but it throws on 10000, meanwhile my ES6 solution is still works :D Anyway, your solution is very cool)

Powershell, 51 bytes
param($n)0..$n|%{'-'*$_+'>';'<'+'-'*$_}|?{$n---gt0}

05AB1E, 23 20 bytes
FNÉD„><è'-N;∍«s_iR},

Try it online!
First time using 05AB1E or any other golfing language for that matter. Any ideas welcome.
-3 from Kevin Cruijssen

Welcome to the world of 05AB1E, and nice first answer. +1 from me. :) "><" can be „>< to save a byte. There are builtins for 1, 2, and 3 char strings, being ', „, and … respectively. Here is a 18 bytes alternative I came up with, but perhaps it could be golfed a bit more. If you haven't seen it yet, we have a tips for golfing in 05AB1E page, and also feel free to ask anything in the chat.

@KevinCruijssen Thanks so much for your ideas. I don't feel right just using your code, as it feels fairly different from mine, but I did use the idea of modulo 2 as checking for if a number is odd. I also use the two char string idea. I would not mind at all if you posted the 18 byte version on your own.

I've posted my answer in that case. :)

Perl 6, 39 bytes
{map {'<'x$_%2~'-'x$_/2~'>'x$_%%2},^$_}

Try it online!
Anonymous code block that returns a list of lines.

Red, 109 108 bytes
-1 byte thanks to NK1406
func[n][repeat i n[print reduce[pick[pad/with pad/left/with]k: i% 2 + 1
pick copy"<>"k i / 2 + k - 1 #"-"]]]

Try it online!

-1 for removing a space

@NK1406 Thank you! I didn't know this is valid.

K (ngn/k), 31 29 bytes
{"<->"x#2,x{(1=*x)_1,2-|x}\0}

Try it online!
first we generate lists with 0 instead of "<", 1 instead of "-", and 2 instead of ">":
{ } function with argument x
x{...}\0 apply the inner function x times, starting with an initial value of 0 and preserving intermediate results
|x reverse
2- replace 0 with 2 and vice versa, keep the 1s as they are
1, prepend a 1
(1=*x)_ is the first of x equal to 1? if yes, drop one element, otherwise drop 0 elements (do nothing)
2, prepend a 2 for the initial ">" arrow
x# we have a little too many lists, so take only the first x of them
"<->" use the lists' elements (0/1/2) as indices in this string

I would like to ask for an explanation (I haven't started learning K yet, I don't know which version to start with...)

@GalenIvanov i tried to write an explanation, i hope it makes sense. thanks for your interest in my favourite language :) there are multiple implementations with different advantages and disadvantages (kx's original, kona, oK and i'm working on my own). would you like to join the apl chat room so i can give you more details?

Thank you, I'm already there

C (gcc), 127 95 + 26 = 121 bytes
i,j;f(x){for(i=0;i<x;putchar(10),i+=2){for(j=0;E;printf(">\n%c",x-i-1?60:9);for(j=0;x-i-1&&E;}}

Try it online!
Compile with -DE=j<i/2;++j)putchar(45)
-6 bytes from Logern
Yay mismatched parentheses!
Ungolfed:
void f(int x) {
	for (int i = 0; i < x; i += 2) {
		for (int j = 0; j < i/2; ++j) {
			printf("-");
		}
		printf(">\n");
		if (x - i - 1) { // Test for last loop: only print <-- if x is even
			printf("<");
			for (int j = 0; j < i/2; ++j) {
				printf("-");
			}
		}
		else {
			printf("\t"); // This is the 9 in the x-i-1?60:9
		}
		printf("\n");
	}
}

Try it online!

121 bytes with a -D compiler flag instead of #define - Try it online!

Another -3 bytes by taking out the i=0 like this

@NK1406 Functions have to be reusable, that edit would break this rule. Try it online!

@pizzapants184 Sorry, didn't see that!

Suggest x+~i instead of x-i-1 and i+=puts(" ") instead of putchar(10),i+=2

05AB1E, 18 15 bytes
F'-N;∍'>«º2äNè,

Suggested as a golf for @nedla2004's 05AB1E answer, but he said I should post it myself since it's using a slightly different approach.
Try it online.
Explanation:
F                # Loop `N` in the range [0, (implicit) input):
   N;            #  Halve the current index `N`
 '-  ∍          '#  Have that many "-" (the halved index decimal .5 is ignored)
      '>«       '#  And append a ">"
         º       #  Now mirror it: i.e. "--->" becomes "---><---"
          2ä     #  Split it into two equal-sized parts: i.e. ["--->","<---"]
            Nè   #  Index the `N` into this array of two strings (with automatic wraparound)
              ,  #  And output it with a trailing newline

You could probably make something work with NÈ„><è

@MagicOctopusUrn Not sure I could use that, since one had to be prepended, and the other appended (hence the use of an if-else). But, I have been able to golf 3 bytes using a different approach now with a mirror º and splitting into two equal parts 2ä. :)

Your TIO link isn't right now :P

@MagicOctopusUrn Oops.. fixed. Thanks

ES6, 96 82 79 70 bytes
Try it online! (Thanks to @Oliver)
n=>[...Array(n)].map((_,i)=>(i%2?"<":"")+"-".repeat(i/2)+(i%2?"":">"))

Welcome to PPCG! By default, taking input as a variable is disallowed; you have to either make it a function (just stick a i=> in front of your code!) or from a command-line argument or STDIN or something.

@HyperNeutrino okay, edited answer. However, the most voted answer contains only the body of the function, but ok. Anyway I'm outsider)

Can you link it? I don't think any of them are invalid, at least not the top few.

@HyperNeutrino https://codegolf.stackexchange.com/a/177465/84533

@HyperNeutrino well, maybe I'm just not familiar with this language and he has bash input inside the code with some way :)

scan() is input in R :)

@HyperNeutrino already googled and got it, sorry! :)

Welcome to PPCG and nice first answer :) Here are a couple ways you can save some bytes: Try it Online

@Oliver thank you :)

A few more bytes: Try it online

A few more bytes if you re-arrange that last ternary operator and remove the center parenthesis: Try it online

@Oliver Lol, rly!

C# (.NET Core), 90 bytes
a=>{for(int i=0;i<a;i++){var s=new String('-',i/2);Console.WriteLine(i%2<1?s+">":"<"+s);}}

Try it online!
Uses an Action delegate to pull in the input and not require a return.
Ungolfed:
a => {
    for(int i = 0; i < a; i++)          // from [0, a)
    {
        var s = new String('-', i / 2);     // create string of dashes of length (a / 2)
        Console.WriteLine(i % 2 < 1 ?       // write arrow
                                s + ">" :       // if i is even: dashes plus ">"
                                "<" + s);       // if i is odd: "<" plus dashes
    }
}

89 bytes

@EmbodimentofIgnorance Doesn't work, missing the first ">" output string.

How about this instead?

C# (Visual C# Interactive Compiler), 69 bytes
i=>{for(var s="";i>0;s+=--i%2<1?"-":"")WriteLine(i%2<1?"<"+s:s+">");}

Try it online!
Uses a technique from Meerkat's answer, but has a lot of improvements.
Less golfed code:
// anonymous function with
// input i and no return value
i=>{
  for(
    // s is a string of hyphens
    var s="";
    // loop from i down to 0
    i>0;
    // decrement i and conditionally
    // tack on an additional hyphen
    // depending on whether i
    // is even or odd
    s+=--i%2<1?"-":""
  )
    // print the hyphens with an arrow
    // at the start or end, depending
    // on whether i is even or even
    WriteLine(i%2<1?"<"+s:s+">");
}

Perl 5, 36 bytes
say$|--?v17^($@.='-'):"$@>"for 1..<>

Try it online!
Gets < from the bitwise-xor of - and v17 (ASCII 17).

05AB1E, 18 bytes
F…> <N'-×.ø#`})s£»

Try it online!

F            }     # Loop from 0 to input...
 …> <              # Push '> <'...
     N'-×          # Push "-" multiplied by N.
         .ø        # Surround with this.
           #`      # Split on spaces, flatten both directions to stack.
              )    # Group all entries together after loop.
               s£  # Take first N.
                 » # Print with newlines.

Non-iterative, same byte-count:
05AB1E, 18 bytes
'-×©'>«.s®'<ìη.ιs£

Try it online!
Other, other method:
05AB1E, 18 bytes
'-×'>«.sð«.º€#˜s£

Try it online!

Tcl, 99 bytes
proc A i {time {puts [expr [incr j]%2?"":"<"][string repe - [expr ($j-1)/2]][expr $j%2?">":""]} $i}

Try it online!

Java 8, 123 120 119 bytes
n->{String l="",r="";for(int c=0;c<n;c++)System.out.println(c%2<1?r=c<1?">":c<2?"<":"-"+r:(l+=c<1?">":c<2?"<":"-"));}

In r=c<1?">":c==1? -- I think if c<1, equivalent to c==0, is excluded, c==1 is equivalent to c<2.

@JonathanFrech -  true, I updated it. thanx.

Perl 5, 44 bytes
map{$_/=2;say'<'x/\./,'-'x$_,'>'x!$&}0..<>-1

Try it online!

Ruby, 47 bytes
->n{n.times.map{|x|"<#{?-*n}>"[x%2*~x/=2,x+1]}}

Try it online!

PHP, 113 bytes
<?php $x=fgets(STDIN);for($i=0;$i<$x;){echo $i%2<1?str_repeat("-",$i++/2).">\n":"<".str_repeat("-",$i++/2)."\n";}

Try it online!
A pretty straightforward solution.

C#, 99 bytes
n=>new string[n].Select((x,i)=>(i%2>0?"<":"")+new String('-',(int)Math.Floor(i/2d))+(i%2<1?">":""))

Try it online!

PHP, 76 73 72 67 bytes
for(;$x<$i;)echo$x&1?'<':'',str_repeat('-',$x/2),$x++&1?'':'>',"
";

Try it online!
Output:
>
<
->
<-
-->
<--
--->
<---
---->
<----
----->
<-----
------>
<------

Lua, 69 68 bytes
for i=0,...-1 do a=("-"):rep(i//2)print(i%2<1 and a..">"or"<"..a)end

Explanation
for i=0,...-1 do  -- for 'i' going from 0 to the number on the first argument
  dashes = ("-"):rep(i//2)  -- dashes is a dash repeated by the iteration we are divided by 2 and rounded down
  print(i%2<1 and dashes..">" or "<"..dashes)  -- if 'i' is even, then print the dashes and then the right-facing arrow
                                               -- else, print the left-facing arrow and then the dashes
end

Try it online!

Changed my solution! Thanks :)

Rust, 152 142 bytes
|n|{for i in 0..n{println!("");if i%2==1{print!("<");for _ in 1..i{print!("-");}}else{for _ in 1..i{print!("-");}print!(">");}}println!("");};

Down from 152 bytes to 142 bytes thanks to Pavel.

I'm not familiar with Rust, but it looks like you have a lot of extra spaces: Around %, around { and }

PHP, 102 bytes
command line options added -n -d
<?for(;$i++<$argv[1];){$b=str_repeat("-",abs($u=ceil($i/2)*pow(-1,$i+1))-1);echo($u>0)?"<$b
":"$b>
";}

Try it online!
Explanation
It is not a much different solution, but is using one of the ways to get the n-th term of the series A001057 wich is another way to look at the challenge.
According to A001057 the one way to obtain the n-th term is with the formula a($n)=ceil($n/2)*pow(-1,$n+1).
And you can look at the challenge like this.
>     +1
<     -1
->    +2
<-    -2
-->   +3
<--   -3
--->  +4
<---  -4
----> +5
# And so on

CJam, 31 bytes
qi{A2%{'<'-A2/*}{'-A2/*'>}?N}fA

Explanation:
qi{A2%{'<'-A2/*}{'-A2/*'>}?N}fA e# Whole code
qi                              e# Get input as an integer
  {                         }fA e# A for loop, from 0 - (input - 1), stored in var A
   A2%                          e# Is A a multiple of 2?
      {        }{        }?     e# Ternary operator: Left is true, right is false
      {
       '<                       e# Push "<" onto the stack
         '-                     e# Push "-" onto the stack
           A2/                  e# Get A/2
              *                 e# Repeat "-" A/2 times
               }{
                 '-             e# Push "-" onto the stack
                   A2/          e# Get A/2
                      *         e# Repeat "-" A/2 times
                       '>       e# Push ">" onto the stack
                         }
                           N    e# Push a new line after each arrow
                                e# Implicit output

Try it online!