Skip to main content
Commonmark migration
Source Link

#J, 19 15 bytes

J, 19 15 bytes

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

Probably need to golf this further...

1-indexed.

###Ungolfed:

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).

#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).

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).

Source Link
Leaky Nun
  • 50.6k
  • 6
  • 115
  • 291

#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).