What's the simplest way to write a function that outputs the sequence:
1, 0, -1, 0, 1, 0, -1, 0, ...
... without using any trig functions?
I was able to come up with a very complex sequence involving -1 to some complicated formula, but I was hoping there is a more simple solution.
$n$ should start at 0 and go to infinity.
All the solutions you guys provided are great! I wasn't aware there were so many of them. I should have mentioned that I prefer a solution which doesn't use recursion; imaginary numbers; matrices; functions with
if statements; or functions such as
mod. I'm looking for something using basic algebra: addition/subtraction, multiplication/division, exponents, etc. However, I will accept anything since I didn't include this clause originally.
This is what I came up with:
Is there a less complicated way (i.e. fewer terms) to get this same sequence?