Added a third implementation of the sequence function after taking a look at the answers