[This article was first published on Revolutions, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

I finally got the new version of Twitter yesterday, and it looks great. And that's no accident: according to the designer, the layout of the new Twitter interface is based on the Golden Spiral:

You can describe the Golden Spiral by laying consecutive squares in a spiral fashion, each square being smaller than the last by a factor of the Golden Ratio, (1+sqrt(5))/2 or approximately 1.618. As a ratio of a length to a width, the Golden Ratio has been known by artists for millenia as an aesthetically pleasing aspect ratio for rectangular features in works of art (such as the dimensions of a painting). It's also known to mathematicians and statisticians as the number to which ratios of successive members of the Fibonacci sequence converge.

In a classic case of using a sledgehammer to crack a walnut, I created a custom iterator in R to represent the Fibonacci sequence (code after the fold) and verified the ratio converges to the Golden Ratio at the R command line:

```> fib1 <- iFib(); nextElem(fib1)
[1] 1
> fib2 <- iFib()
> nextElem(fib1)/nextElem(fib2)
[1] 1
> nextElem(fib1)/nextElem(fib2)
[1] 2
> nextElem(fib1)/nextElem(fib2)
[1] 1.5
> nextElem(fib1)/nextElem(fib2)
[1] 1.666667
> nextElem(fib1)/nextElem(fib2)
[1] 1.6
> nextElem(fib1)/nextElem(fib2)
[1] 1.625
> nextElem(fib1)/nextElem(fib2)
[1] 1.615385
> nextElem(fib1)/nextElem(fib2)
[1] 1.619048
> nextElem(fib1)/nextElem(fib2)
[1] 1.617647
> nextElem(fib1)/nextElem(fib2)
[1] 1.618182
> nextElem(fib1)/nextElem(fib2)
[1] 1.617978
> nextElem(fib1)/nextElem(fib2)
[1] 1.618056
> nextElem(fib1)/nextElem(fib2)
[1] 1.618026
```

See? Golden ratio.

Twitter: @stop

```require(iterators)
## Generator for Fibonacci sequence
iFib <- function() {
lastFib <- 0
nextFib <- 1
nextEl <- function() {
newLast <<- nextFib
nextFib <<- lastFib + nextFib
lastFib <<- newLast
lastFib
}
it <- list(nextElem = nextEl)
class(it) <- c('abstractiter','iter')
it
}
```

To leave a comment for the author, please follow the link and comment on their blog: Revolutions.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

# Never miss an update! Subscribe to R-bloggers to receive e-mails with the latest R posts.(You will not see this message again.)

Click here to close (This popup will not appear again)