Skip to main content
2 of 2
Commonmark migration

J, 19 15 bytes

>.@(%&3)*1-3|<: 

Probably need to golf this further...

1-indexed.

Ungolfed:

>> choose_sign =: 1-3|<: NB. 1-((n-1)%3) >> choose_magnitude =: >.@(%&3) NB. ceil(n/3) >> f =: choose_sign * choose_magnitude >> f 1 12 77 << 1 _4 0 

Where >> means input (STDIN) and << means output (STDOUT).

Leaky Nun
  • 50.6k
  • 6
  • 115
  • 291