| Bytes | Lang | Time | Link |
|---|---|---|---|
| 006 | cQuents | 250921T201832Z | Stephen |
| 029 | Desmos | 250921T042349Z | DesmosEn |
| 016 | APLNARS | 250921T150336Z | Rosario |
| 027 | Haskell | 250328T195945Z | DLosc |
| 027 | AWK | 250328T164909Z | xrs |
| 055 | SAKO | 250327T164303Z | Acrimori |
| 065 | Vyxal | 240213T125627Z | pacman25 |
| 043 | Common Lisp | 171120T151740Z | Renzo |
| 046 | VBA Excel | 171120T073304Z | remoel |
| 050 | Lua | 171119T100134Z | MCAdvent |
| 064 | Python 2 | 171118T215737Z | FlipTack |
| 030 | Cubix | 160602T235725Z | MickyT |
| 012 | Oasis | 160831T134718Z | Leaky Nu |
| 029 | Batch | 160528T182444Z | Neil |
| 019 | Java | 160624T003100Z | Steven H |
| 036 | Java 7 | 160623T173016Z | Steven H |
| 025 | Python 3 | 160623T174828Z | act |
| 012 | APL | 160623T170745Z | lstefano |
| 034 | C# | 160603T203948Z | Andrew |
| 086 | Batch Windows | 160531T022455Z | Drew Chr |
| 028 | R | 160602T210534Z | MickyT |
| 025 | Hexagony | 160602T201314Z | Sok |
| 086 | Desmos | 160602T192053Z | weatherm |
| 040 | Erlang | 160602T143841Z | fxk8y |
| 014 | Labyrinth | 160602T083548Z | Martin E |
| 036 | Java 7 | 160602T091209Z | Kevin Cr |
| nan | ><> | 160602T083754Z | Sok |
| 011 | CJam | 160602T074752Z | Martin E |
| 044 | GeoGebra | 160602T024056Z | juh |
| 014 | APL | 160601T004815Z | marinus |
| 022 | JavaScript | 160531T023657Z | Drew Chr |
| 025 | Bash | 160528T220238Z | rexkogit |
| 027 | GNU Coreutils | 160528T220452Z | rexkogit |
| 010 | dc | 160531T051654Z | Digital |
| 023 | Octave | 160530T194540Z | beaker |
| 081 | MarioLANG | 160529T012904Z | Ether Fr |
| 007 | 05AB1E | 160530T092045Z | Emigna |
| 027 | Haskell | 160530T012756Z | Michael |
| 026 | Mathematica | 160528T225610Z | DavidC |
| 012 | MATL | 160528T172609Z | DJMcMayh |
| 022 | Perl 5 | 160529T065404Z | msh210 |
| 010 | Actually | 160529T072201Z | user4594 |
| 010 | Pyth | 160528T211203Z | John Red |
| 008 | MATL | 160529T044214Z | Luis Men |
| 027 | MATLAB / Octave | 160528T222541Z | Suever |
| 008 | MATL | 160528T183000Z | Suever |
| 007 | Jelly | 160528T165812Z | lynn |
| 027 | J | 160528T182549Z | Conor O& |
| 007 | Pyke | 160528T165735Z | Blue |
| 018 | JavaScript ES6 | 160528T165039Z | Downgoat |
| 015 | J | 160528T180247Z | Leaky Nu |
| 023 | Perl 6 | 160528T175712Z | Brad Gil |
| 045 | Retina | 160528T170938Z | Leaky Nu |
| 024 | Python 2 | 160528T164915Z | Leaky Nu |
cQuents, 6 bytes
k,0,-k
One-indexed.
Explanation
: implicit : mode sequence - given n, output nth term
terms separated by commas, k = 1
k,
0,
-k
increment k and cycle to beginning of list
Desmos, 29 bytes
f(x)=floor(x/3+1)(1-mod(x,3))
This function has two parts, the first part is floor(x/3+1), which produces a series that looks like 1,1,1,2,2,2,3,3,3,4,4,4... etc, increasing by one every three terms. This series is then multiplied by the second part, which cycles between 1,0,-1. This produces the final series of 1,0,-1,2,0,-2,3,0,-3,4,0,-4... etc.
APL(NARS), 16 chars
{(1+⌊⍵÷3)×1-3∣⍵}
test:
{(1+⌊⍵÷3)×1-3∣⍵}¨0..14
1 0 ¯1 2 0 ¯2 3 0 ¯3 4 0 ¯4 5 0 ¯5
Haskell, 27 bytes
(!!)$(*)<$>[1..]<*>[1,0,-1]
Uses a different approach from the previous 27-byte Haskell solution. Attempt This Online!
Explanation
Generates the full sequence as an infinite list, then indexes into it.
(!!)$(*)<$>[1..]<*>[1,0,-1]
<$> <*> -- Take the Cartesian product
(*) -- using multiplication
[1..] -- of the infinite list of positive integers
[1,0,-1] -- and the list of signs
(!!)$ -- Index into the resulting list
AWK, 27 bytes
1,$0=(1+int($1/3))*(1-$1%3)
1, # forces print even if 0
$0= # set output
(1+int($1/3)) # int so we don't get decimals
*(1-$1%3) # rest of algo
SAKO, 55 bytes
PODPROGRAM:F(N)
F():ENT((1+N/3)×(1-MOD(ENT(N),3)))
WROC
Full programme version, 66 bytes
1)CZYTAJ:N
DRUKUJ(0):ENT((1+N/3)×(1-MOD(ENT(N),3)))
STOP1
KONIEC
Vyxal, 52 bitsv2, 6.5 bytes
Þn2ẇ0Zfi
Bitstring:
0010101100100111101111111101010011100010011001000000
Silly vyxal (1 indexed)
VBA Excel , 46 bytes
using immediate window and Range A1 as input
a=[A1]:b=a Mod 3:?IIf(b=0,-a/3,IIf(b=1,a/3,0))
Python 2, 64 bytes
Although Leaky Nun has already posted a much shorter, brilliant Python answer, I decided to see whether this could be done recursively, calculating each new term from the last two. The result was interesting:
f=lambda n,a=1,b=0:(n<1)*`a`or f(n-1,b,[[0,-a][b==0],1-b][a==0])
Cubix, 30 bytes
1..-.w>?^I3%?;,)O@...o-'.<u;;;
Try it here. You will need to replace the current code with the above and enter an input number.
This wraps onto a cube with an edge length of 3. I'm hoping to reduce this a bit more, but at the moment it's not to bad. It would be nice to have some of the planned features for the stack, but oh well.
1 . .
- . w
> ? ^
I 3 % ? ; , ) O @ . . .
o - ' . < u ; ; ; . . .
. . . . . . . . . . . .
. . .
. . .
. . .
Explanation:
I 3 % ?Take a number from input, push a literal 3, mod on TOS and do a check. The?redirects right for negative and left for positive. Pass through for zero- For zero value
; , ) O @Pop, integer divide TOS, increment TOS, output number and terminate - For positive value
1 - > ?Push literal 1, subtract TOS, change direction and check
- For zero value
^ w O @Redirect up, sidestep left (ends up on another face), output number (zero in this case) and terminate - For positive value
; < ' - o ; ; ; u , ) O @pop, redirect, push character -, output character, pop, pop, pop, u-turn to left, integer divide TOS, increment TOS, output number and terminate
- For zero value
Oasis, 12 bytes (non-competing)
n3÷>n3÷y>n-*
Oasis is a language designed by Adnan which is specialized in sequences.
Currently, this language can do recursion and closed form.
This answer can only demonstrate closed form. For recursion, see for example this answer.
We use this formula: a(n) = (n/3+1)*((n/3*3)+1-n) which is modified from the formula used in my Python answer, since there is no modulo at the moment.
n3÷>n3÷y>n-*
n push n (input)
3÷ integer-division by 3
> +1
n push n (input)
3÷ integer-division by 3
y *3
> +1
n push n (input)
- subtract the top of stack from the second top of stack
* multiply the top of stack to the second top of stack
Batch, 30 29 bytes
@cmd/cset/a(1+%1/3)*(1-%1%%3)
The cmd/c makes set/a echo the result of the calculation. Edit: Saved 1 byte by removing the unnecessary space.
Java 7, 38 37 36 bytes
My first golf, be gentle
int a(int i){return(1+i/3)*(1-i%3);}
Try it here! (test cases included)
Edit: I miscounted, and also golfed off one more character by replacing (-i%3+1) with (1-i%3).
Python 3, 30 25 bytes
I tried to replicate the results of Leaky Nun's Python post for 10 minutes before realising it was for Python 2, not 3.
Zero-indexed:
lambda n:(n//3+1)*(1-n%3)
Full program:
a = lambda n:(n//3+1)*(1-n%3)
print(a(0)) # 1
print(a(11)) # -4
print(a(76)) # 0
print(a(134)) # -45
print(a(296)) # -99
APL, 12 chars
-×/1-0 3⊤6+⎕
0 3⊤ is APL's divmod 3.
C#, 34 bytes
n=>n%3==1?0:(n/3+1)*(n%3==0?1:-1);
To assign the lambda to a variable, write:
Func<int,int>f=n=>n%3==1?0:(n/3+1)*(n%3==0?1:-1);
With C# 6, you can also assign the lambda to a method:
int F(int n)=>n%3==1?0:(n/3+1)*(n%3==0?1:-1);
Batch (Windows), 86 bytes
Alternate.bat
SET /A r=%1%%3
SET /A d=(%1-r)/3+1
IF %r%==0 ECHO %d%
IF %r%==1 ECHO 0
IF %r%==2 ECHO -%d%
This program is run as Alternate.bat n where n is the number you wish to call the function on.
R, 28 bytes
-((n=scan())%%3-1)*(n%/%3+1)
Looks like this is a variation of most of the answers here. Zero based.
n=scan() # get input from STDIN
( )%%3-1 # mod by 3 and shift down (0,1,2) -> (-1,0,1)
-( ) # negate result (1,0,-1), this handles the alternating signs
*(n%/%3+1) # integer division of n by 3, add 1, multiply by previous
The nice thing about it is that it handles multiple inputs
> -((n=scan())%%3-1)*(n%/%3+1)
1: 0 3 6 9 1 4 7 10 2 5 8 11
13:
Read 12 items
[1] 1 2 3 4 0 0 0 0 -1 -2 -3 -4
>
Originally I wanted to do the following, but couldn't trim off the extra bytes.
rbind(I<-1:(n=scan()),0,-I)[n]
Uses rbind to add 0's and negatives to a range of 1 to n then return the n'th term (one based).
# for n = 5
rbind( ) # bind rows
n=scan() # get input from STDIN and assign to n
I<-1:( ) # build range 1 to n and assign to I
,0 # add a row of zeros (expanded automatically)
,-I # add a row of negatives
[n] # return the n'th term
Hexagony, 25 bytes
?'+}@/)${':/3$~{3'.%(/'*!
Or, in non-minified format:
? ' + }
@ / ) $ {
' : / 3 $ ~
{ 3 ' . % ( /
' * ! . . .
. . . . .
. . . .
My first foray into Hexagony, so I'm certain I've not done this anywhere near as efficiently as it could be done...
Calculates -(n%3 - 1) on one memory edge, n/3 + 1 on an adjacent one, then multiplies them together.
Desmos, 125 86 bytes
b=\operatorname{ceil}\left(\frac{a}{3}\right)
b\operatorname{mod}\left(-a,3\right)-b
a=1
Simple fix for \operatorname{ceil}\left(\frac{a}{3}\right)
125 bytes:
\operatorname{ceil}\left(\frac{a}{3}\right)\operatorname{mod}\left(-a,3\right)-\operatorname{ceil}\left(\frac{a}{3}\right)
a=1
This is as close as I could get to divmod. Might be able to get rid of subtracting -\operatorname{ceil}\left(\frac{a}{3}\right) to shave some bytes off.
Erlang, 40 bytes
F=fun(N)->trunc((N/3+1)*(1-N rem 3))end.
Sadly Erlang has no '%' modulo operator and 'rem' requires the spaces, even before the 3.
Labyrinth, 17 15 14 bytes
Saved 3 bytes using Sok's idea of using 1-(n%3) instead of ~(n%3-2).
1?:#/)}_3%-{*!
The program terminates with an error (division by zero), but the error message goes to STDERR.
Explanation
The program is completely linear, although some code is executed in reverse at the end.
1 Turn top of stack into 1.
?: Read input as integer and duplicate.
# Push stack depth (3).
/) Divide and increment.
} Move over to auxiliary stack.
_3% Take other copy modulo 3.
- Subtract from 1. This turns 0, 1, 2 into 1, 0, -1, respectively.
{* Move other value back onto main stack and multiply.
! Output as integer.
The instruction pointer now hits a dead end and turns around, so it starts to execute the code from the end:
* Multiply two (implicit) zeros.
{ Pull an (implicit) zero from the auxiliary to the main stack.
- Subtract two (implicit) zeros from one another.
Note that these were all effectively no-ops due to the stacks which are
implicitly filled with zeros.
% Attempt modulo, which terminates the program due to a division-by-zero error.
Java 7, 36 bytes
int c(int n){return(n/3+1)*(1-n%3);}
Ungolfed & test code:
class Main{
static int c(int n){
return (n / 3 + 1) * (1 - n % 3);
}
public static void main(String[] a){
System.out.println(c(0));
System.out.println(c(11));
System.out.println(c(76));
System.out.println(c(134));
System.out.println(c(296));
}
}
Zero-indexed output:
1
-4
0
-45
-99
><>, 16+3 = 19 bytes
:3%:1$-}-3,1+*n;
Needs the input to be present on the stack, so +3 bytes for the -v flag. Try it online!
The program outputs the zero-indexed sequence, using the formula:
f(n) = ((n-(n%3))/3) * (1-(n%3))
CJam, 11 bytes
ri3+3md(W**
0-based input.
Explanation
ri e# Read input and convert to integer N.
3+ e# Add 3.
3md e# Divmod 3, putting N/3+1 and N%3 on the stack.
(W* e# Decrement, multiply by -1, turning 0, 1, 2 into 1, 0, -1, respectively.
* e# Multiply.
GeoGebra, 44 bytes
Element[Flatten[Sequence[{t,0,-t},t,1,n]],n]
where n is one-indexed.
Explanation:
Element[ , n] # Return the nth element of the list .
Flatten[ ] # Strip all the unnecessary braces from the list /|\
Sequence[{t,0,-t}, t, 1, n] # Generate a list of lists of the form {t, 0, -t} |
# This list will start with {1,0,-1} and end with {n,0,-n} |
It is not necessary to generate all triplets through {n, 0, -n}, but it's shorter than writing ceil(n/3) or something to that effect.
Note that n must be defined to create this object (if it isn't defined at the time this is run, GeoGebra will prompt you to create a slider for n).
APL, 14 bytes
{⍵⌷∊{⍵0,-⍵}¨⍳⍵}
This is 1-indexed, i.e.:
{⍵⌷∊{⍵0,-⍵}¨⍳⍵}¨1 2 3 4 5 6 7 8
1 0 ¯1 2 0 ¯2 3 0
Explanation:
{⍵⌷ select the ⍵th element
∊ from all elements in
{⍵0,-⍵} the values ⍵, 0, and -⍵
¨⍳⍵} for each number in 1..⍵
JavaScript, 22 bytes
r=n%3
o=(1-r)/3*(n-r+3)
n is the number you wish to call the function on. o is the output number.
Bash, 28 25 Bytes
echo $[(1+$1/3)*(1-$1%3)]
GNU Coreutils, 27 Bytes
echo "(1+$1/3)*(1-$1%3)"|bc
dc, 10
?2+3~1r-*p
Uses 1-based indexing.
? # Push input to stack
2+ # Add 2
3~ # divmod by 3
1r- # subtract remainder from 1
* # multiply by quotient
p # print
Octave, 23 bytes
With no mod cons...
@(n)(-[-1:1]'*[1:n])(n)
Uses 1-based indexing magic.
Explanation
Creates an anonymous function that will:
(-[-1:1]'*[1:n])(n)
[-1:1] % make a row vector [-1 0 1]
- ' % negate and take its transpose making a column vector
[1:n] % make a row vector [1..n], where n is the input
* % multiply with singleton expansion
(n) % use linear indexing to get the nth value
After the multiplication step we'll have a 3xn matrix like so (for n=12):
1 2 3 4 5 6 7 8 9 10 11 12
0 0 0 0 0 0 0 0 0 0 0 0
-1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -12
Making n columns is overkill, but it's a convenient number that is guaranteed to be large enough. Linear indexing counts down each column from left to right, so the element at linear index 4 would be 2.
All test cases on ideone.
MarioLANG, 93 81 bytes
one-indexed
;(-))+(-
"============<
>:(![<:![<:)![
!=#="!#="!=#=
! < !-< !- <
#==" #=" #=="
Explanation :
we begin by taking the imput
;
wich give us
v
... 0 0 input 0 0 ...
we then decrement the left byte and increment the right byte with
;(-))+(
=======
we end up with
v
... 0 -1 input +1 0 ...
we then set up the loop
;(-))+(-
"============<
> ![< ![< ![
#=" #=" #=
! < !-< !- <
#==" #=" #=="
the loop will go until the memory look like
v
... 0 -X 0 +X 0 ...
we then only need to output the result
;(-))+(-
"============<
>:(![<:![<:)![
!=#="!#="!=#=
! < !-< !- <
#==" #=" #=="
05AB1E, 7 bytes
Code:
(3‰`<*(
Explained:
( # negate input: 12 -> -12
3‰ # divmod by 3: [-4, 0]
` # flatten array: 0, -4
< # decrease the mod-result by 1: -1, -4
* # multiply: 4
( # negate -4
Haskell, 27 bytes
f x=div(x+3)3*(1-mod(x+3)3)
Slightly more interesting 28 byte solution:
(((\i->[i,0,-i])=<<[1..])!!)
(Both are 0-indexed)
Mathematica 26 bytes
With 4 bytes saved thanks to Martin Ender.
⎡#/3⎤(-#~Mod~3-1)&
Uses the same approach as Suever.
MATL, 15 12 bytes
3/XkG3X\2-*_
This uses one based indexing.
Try it online! or verify test cases
Explanation:
G #Input
3X\ #Modulus, except multiples of 3 give 3 instead of 0
2- #Subtract 2, giving -1, 0 or 1
3/Xk #Ceiling of input divided by 3.
* #Multiply
_ #Negate
Perl 5, 22 bytes
21 plus one for -p:
$_=(-$_,$_+2)[$_%3]/3
Uses 1-based indexing.
Explanation:
-p sets the variable $_ equal to the input. The code then sets it equal to the $_%3th element, divided by 3, of the 0-based list (-$_,$_+2) (where % is modulo). Note that if $_%3 is two, then there is no such element, and the subsequent division by 3 numifies the undefined to 0. -p then prints $_.
Actually, 10 bytes
3@│\u)%1-*
Explanation:
3@│\u)%1-*
3@│ push 3, swap, duplicate entire stack ([n 3 n 3])
\u) floor division, increment, move to bottom ([n 3 n//3+1])
%1- mod, subtract from 1 ([1-n%3 n//3+1])
* multiply ([(1-n%3)*(n//3+1)])
Pyth, 10 bytes
*h/Q3-1%Q3
Explanation:
* : Multiply following two arguments
h/Q3 : 1 + Input/3
-1%Q3 : 1 - Input%3
Note: I've assumed the zero-indexed sequence.
MATL, 8 bytes
:t~y_vG)
The result is 1-based.
Explanation
This builds the 2D array
1 2 3 4 5 ...
0 0 0 0 0 ...
-1 -2 -3 -4 -5 ...
and then uses linear indexing to extract the desired term. Linear indexing means index down, then across (so in the above array the first entries in linear order are 1, 0, -1, 2, 0, ...)
: % Vector [1 2 ... N], where N is implicit input
t~ % Duplicate and logical negate: vector of zeros
y_ % Duplicate array below the top and negate: vector [-1 -2 ... -N]
v % Concatenate all stack contents vertically
G) % Index with input. Implicit display
MATLAB / Octave, 27 bytes
@(n)ceil(n/3)*(mod(-n,3)-1)
This creates an anonymous function that can be called using ans(n). This solution uses 1-based indexing.
MATL, 8 bytes
_3&\wq*_
This solution uses 1-based indexing into the sequence.
Modified version showing all test cases
Explanation
% Implicitly grab the input
_ % Negate the input
3&\ % Compute the modulus with 3. The second output is floor(N/3). Because we negated
% the input, this is the equivalent of ceil(input/3)
w % Flip the order of the outputs
q % Subtract 1 from the result of mod to turn [0 1 2] into [-1 0 1]
* % Take the product with ceil(input/3)
_ % Negate the result so that the sequence goes [N 0 -N] instead of [-N 0 N]
% Implicitly display the result
Jelly, 7 bytes
+6d3’PN
Zero-indexed. Test cases here.
Explanation:
+6 Add 6: x+6
d3 Divmod: [(x+6)/3, (x+6)%3]
’ Decrement: [(x+6)/3-1, (x+6)%3-1]
P Product ((x+6)/3-1) * ((x+6)%3-1)
J, 27 bytes
Whilst not the golfiest, I like it better, as it uses an agenda.
>.@(>:%3:)*1:`0:`_1:@.(3|])
Here is the tree decomposition of it:
┌─ >.
┌─ @ ──┤ ┌─ >:
│ └────┼─ %
│ └─ 3:
├─ *
──┤ ┌─ 1:
│ ┌────┼─ 0:
│ │ └─ _1:
└─ @. ─┤
│ ┌─ 3
└────┼─ |
└─ ]
This is very similar to Kenny's J answer, in that it chooses the magnitude and sign, but it's different in that I use an agenda to choose the sign.
Pyke, 8 7 bytes (old version)
3.DeRt*
Try it here! - Note that link probably won't last for long
3.D - a,b = divmod(input, 3)
e - a = ~a -(a+1)
t - b -= 1
* - a = a*b
- implicit output a
Newest version
3.DhRt*_
3.D - a,b = divmod(input, 3)
h - a+=1
t - b-=1
* - a = a*b
_ - a = -a
- implicit output a
JavaScript ES6, 18 bytes
n=>-~(n/3)*(1-n%3)
Turned out very similar to @LeakyNun's answer but I didn't see his until after I posted mine.
Explanation and Ungolfed
-~ is shorthand for Math.ceil, or rounding up:
n => // input in var `n`
Math.ceil(n/3) // Get every 3rd number 1,1,1,2,2,2, etc.
*
(1-n%3) // 1, 0, -1, 1, 0, -1, ...
function f(n){n=i.value;o.value=-~(n/3)*(1-n%3);}
Input: <input id=i oninput="f()"/><br /><br />
Output: <input id=o readable/>
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).
Perl 6, 26 23 bytes
{({|(++$,0,--$)}...*)[$_]}
{($_ div 3+1)*(1-$_%3)}
( The shorter one was translated from other answers )
Explanation (of the first one):
{ # bare block with implicit parameter 「$_」
(
# start of sequence generator
{ # bare block
|( # slip ( so that it flattens into the outer sequence )
++$, # incrementing anon state var => 1, 2, 3, 4, 5, 6
0, # 0 => 0, 0, 0, 0, 0, 0
--$ # decrementing anon state var => -1,-2,-3,-4,-5,-6
)
}
... # repeat
* # indefinitely
# end of sequence generator
)[ $_ ] # get the nth one (zero based)
}
Test:
#! /usr/bin/env perl6
use v6.c;
use Test;
# store it lexically
my &alt-seq-sign = {({|(++$,0,--$)}...*)[$_]}
my &short-one = {($_ div 3+1)*(1-$_%3)}
my @tests = (
0 => 1,
11 => -4,
76 => 0,
134 => -45,
296 => -99,
15..^30 => (6,0,-6,7,0,-7,8,0,-8,9,0,-9,10,0,-10)
);
plan @tests * 2 - 1;
for @tests {
is alt-seq-sign( .key ), .value, 'alt-seq-sign ' ~ .gist;
next if .key ~~ Range; # doesn't support Range as an input
is short-one( .key ), .value, 'short-one ' ~ .gist;
}
1..11
ok 1 - alt-seq-sign 0 => 1
ok 2 - short-one 0 => 1
ok 3 - alt-seq-sign 11 => -4
ok 4 - short-one 11 => -4
ok 5 - alt-seq-sign 76 => 0
ok 6 - short-one 76 => 0
ok 7 - alt-seq-sign 134 => -45
ok 8 - short-one 134 => -45
ok 9 - alt-seq-sign 296 => -99
ok 10 - short-one 296 => -99
ok 11 - alt-seq-sign 15..^30 => (6 0 -6 7 0 -7 8 0 -8 9 0 -9 10 0 -10)
Retina, 45 bytes
.+
11$&$*
(111)+(1)*
$#2$#1
T`d`+0-`^.
^0.+
0
Takes input/output in base-ten. 1-indexed.
Unary input, base-ten output, 1-indexed: 40 bytes
$
11
(111)+(1)*
$#2$#1
T`d`+0-`^.
^0.+
0
Python 2, 24 bytes
lambda n:(n/3+1)*(1-n%3)
Full program:
a=lambda n:(n/3+1)*(1-n%3)
print(a(0)) # 1
print(a(11)) # -4
print(a(76)) # 0
print(a(134)) # -45
print(a(296)) # -99