solution for sequence exercise