OFFSET
0,5
COMMENTS
This sequence might be called the "Bad Driver's Sequence" as it fully "accelerates" or "decelerates" when it changes side of its "speed limit".
LINKS
Georg Fischer, Table of n, a(n) for n = 0..1000
FORMULA
a'(n) = A053615(n)*(-1)^ceiling((sqrt(4n+1)-1)/2).
a''(n) = (-1)^ceiling(sqrt(n)).
EXAMPLE
a''(0) = 1, a'(0) = 0, a(0) = 0.
a''(1) = -1, a'(1) = 0 - 1 = -1, a(1) = 0 - 1 = -1.
a(2-2) = a(0) = 0, so a''(2) = -a''(1) = 1, a'(2) = -1 + 1 = 0, a(2) = -1 + 0 = -1.
PROG
(Haskell)
a(0) = 0
a(1) = -1
a(2) = -1
a(n) = if a(n-2) == 0 then a(n-1) + a'(n-1) - a''(n-1) else a(n-1) + a'(n-1) + a''(n-1)
where a'(n) = a(n) - a(n-1)
a''(n) = a'(n) - a'(n-1)
(Perl)
my @a = (0, -1, -1);
for my $n (scalar(@a)..1000) {
if ($a[$n - 2] == 0) {
$a[$n] = $a[$n - 1] + &as($n - 1) - &ass($n - 1);
} else {
$a[$n] = $a[$n - 1] + &as($n - 1) + &ass($n - 1);
}
print "$n $a[$n]\n";
} # for n
sub as { my ($n) = @_; return $a[$n] - $a[$n - 1]; }
sub ass { my ($n) = @_; return &as($n) - &as($n - 1); }
# Georg Fischer, Feb 14 2019
CROSSREFS
KEYWORD
sign,look
AUTHOR
Thomas Anton, Jan 06 2019
EXTENSIONS
a(44) corrected [18, not -18] by Tom Duff, Feb 14 2019
STATUS
approved