OFFSET
1,2
COMMENTS
This sequence is generated by taking the sum of each iteration in an alternating rectangular spiral. The rules for generating this spiral are as follows:
1. The first iteration starts with one unit length.
2. Each iteration must alternate the direction the spiral is going (if iteration 1 is counterclockwise, iteration 2 must be clockwise and vice versa). Every time the direction is changed, the next line will be 90 degrees in that direction from the ending of the spiral in that iteration.
3. Each iteration must add one more line that has to be drawn before the iteration is over: 1, 1, 2, 1, 2, 3, 1, 2, 3, 4, etc.
If we add the alternation to it and start by moving right and counterclockwise, we get something like: right, down, left, down, right, up, right, down, left, up.
4. Every line drawn must go at least one unit length farther than the current outer bounds of the spiral.
The sequence comes from the sums of these iterations. The first iteration is only one unit length, so the first term is 1. If the first iteration was counterclockwise and went one unit to the right, the second iteration will be clockwise and start by going one unit down. Because two lines must be drawn for the second iteration, we now have to go left 2 units in order to pass the leftward bound that the starting line created. This gives us a value of 3 for the second iteration because we traveled one unit down and two to the left. We can repeat this process for the third iteration. Now we return to moving counterclockwise and move one unit down. We must move three units to the left in order to pass the rightward bound created by the first iteration. Now we must move three units up in order to pass the upper bound created by the first iteration. When we add 1 + 3 + 3 we get 7 which is the next term in the sequence.
LINKS
FORMULA
Conjectures from Colin Barker, Feb 13 2019: (Start)
G.f.: x*(1 - x + 2*x^2 + x^4) / ((1 - x)^4*(1 + x^2)).
a(n) = (2 - (-i)^n - i^n + 6*n - 2*n^2 + 2*n^3) / 8 where i=sqrt(-1).
(End)
PROG
(Python with Turtle)
import turtle
t = turtle.Turtle()t.hideturtle()t.pensize(1)t.right(90)t.speed(8)t.pendown()j = 1
xMin = 0xMax = 0
yMin = 0yMax = 0
sz = 10
alist = []blist = []
for i in range(15):
while j <= i:
t.color("red")
if i % 2 == 0: t.right(90) else: t.left(90)
if j == 1: if t.heading() == 0: t.forward(sz) xMax += sz alist.append(sz)
if t.heading() == 90: t.forward(sz) yMax += sz alist.append(sz)
if t.heading() == 180: t.forward(sz) xMin -= sz alist.append(sz)
if t.heading() == 270: t.forward(sz) yMin -= sz alist.append(sz)
if j > 1:
t.color("black")
if t.heading() == 0: alist.append(int(t.distance(xMax + sz, t.ycor()))) t.goto(xMax + sz, t.ycor()) xMax = t.xcor()
if t.heading() == 90: alist.append(int(t.distance(t.xcor(), yMax + sz))) t.goto(t.xcor(), yMax + sz) yMax = t.ycor()
if t.heading() == 180: alist.append(int(t.distance(xMin - sz, t.ycor()))) t.goto(xMin - sz, t.ycor()) xMin = t.xcor()
if t.heading() == 270: alist.append(int(t.distance(t.xcor(), yMin - sz))) t.goto(t.xcor(), yMin - sz) yMin = t.ycor()
j += 1
total = sum(alist)/sz blist.append(total) total = 0 del alist[:]
j = 1
print(blist)
CROSSREFS
KEYWORD
nonn
AUTHOR
Drew Edgette, Nov 26 2018
STATUS
approved